use of htsjdk.samtools.util.IntervalList in project gatk by broadinstitute.
the class IntervalListTools method writeScatterIntervals.
/**
* Method to scatter an interval list by locus.
*
* @param list The list of intervals to scatter
* @return The scattered intervals, represented as a {@link List} of {@link IntervalList}
*/
private List<IntervalList> writeScatterIntervals(final IntervalList list) {
final IntervalListScatterer scatterer = new IntervalListScatterer(SUBDIVISION_MODE);
final List<IntervalList> scattered = scatterer.scatter(list, SCATTER_COUNT, UNIQUE);
final DecimalFormat fileNameFormatter = new DecimalFormat("0000");
int fileIndex = 1;
for (final IntervalList intervals : scattered) {
intervals.write(createDirectoryAndGetScatterFile(OUTPUT, scattered.size(), fileNameFormatter.format(fileIndex++)));
}
return scattered;
}
use of htsjdk.samtools.util.IntervalList in project gatk by broadinstitute.
the class IntervalListTools method openIntervalLists.
private List<IntervalList> openIntervalLists(final List<File> files) {
final List<IntervalList> lists = new ArrayList<>();
for (final File f : files) {
final IntervalList list = TYPE.getIntervalList(f, INCLUDE_FILTERED);
if (PADDING != 0) {
final IntervalList out = new IntervalList(list.getHeader());
for (final Interval i : list) {
final int start = i.getStart() - PADDING;
final int end = i.getEnd() + PADDING;
if (start <= end) {
final Interval i2 = new Interval(i.getContig(), start, end, i.isNegativeStrand(), i.getName());
out.add(i2);
}
}
lists.add(out);
} else {
lists.add(list);
}
}
return lists;
}
use of htsjdk.samtools.util.IntervalList in project gatk by broadinstitute.
the class LiftOverIntervalList method doWork.
/**
* Do the work after command line has been parsed. RuntimeException may be
* thrown by this method, and are reported appropriately.
*/
@Override
protected Object doWork() {
assertFileIsReadable(INPUT);
assertFileIsReadable(SEQUENCE_DICTIONARY);
assertFileIsReadable(CHAIN);
assertFileIsWritable(OUTPUT);
final LiftOver liftOver = new LiftOver(CHAIN);
liftOver.setLiftOverMinMatch(MIN_LIFTOVER_PCT);
final IntervalList fromIntervals = fromFile(INPUT);
final SAMFileHeader toHeader = makeDefault().getFileHeader(SEQUENCE_DICTIONARY);
liftOver.validateToSequences(toHeader.getSequenceDictionary());
final IntervalList toIntervals = new IntervalList(toHeader);
boolean anyFailed = false;
for (final Interval fromInterval : fromIntervals) {
final Interval toInterval = liftOver.liftOver(fromInterval);
if (toInterval != null) {
toIntervals.add(toInterval);
} else {
anyFailed = true;
logger.warn("Liftover failed for ", fromInterval, "(len ", fromInterval.length(), ")");
final List<LiftOver.PartialLiftover> partials = liftOver.diagnosticLiftover(fromInterval);
for (final LiftOver.PartialLiftover partial : partials) {
logger.info(partial);
}
}
}
toIntervals.sorted();
toIntervals.write(OUTPUT);
return anyFailed ? 1 : 0;
}
use of htsjdk.samtools.util.IntervalList in project gatk-protected by broadinstitute.
the class GetHetCoverage method doWork.
@Override
protected Object doWork() {
//if tumor arguments are missing, throw exception (and do not even get normal pulldown)
final boolean doTumorPulldown;
if (tumorHetOutputFile != null && tumorBAMFile != null) {
doTumorPulldown = true;
} else if ((tumorHetOutputFile == null) != (tumorBAMFile == null)) {
throw new CommandLineException("Must specify both BAM and output files for tumor pulldown.");
} else {
doTumorPulldown = false;
}
final HetPulldownCalculator hetPulldown = new HetPulldownCalculator(REFERENCE_ARGUMENTS.getReferenceFile(), snpFile, minimumMappingQuality, minimumBaseQuality, VALIDATION_STRINGENCY);
logger.info("Getting normal het pulldown...");
final Pulldown normalHetPulldown = hetPulldown.getNormal(normalBAMFile, pvalThreshold, minimumRawReads);
normalHetPulldown.write(normalHetOutputFile, AllelicCountTableVerbosity.BASIC);
logger.info("Normal het pulldown written to " + normalHetOutputFile.toString());
if (doTumorPulldown) {
final IntervalList normalHetIntervals = normalHetPulldown.getIntervals();
logger.info("Getting tumor het pulldown...");
final Pulldown tumorHetPulldown = hetPulldown.getTumor(tumorBAMFile, normalHetIntervals, minimumRawReads);
tumorHetPulldown.write(tumorHetOutputFile, AllelicCountTableVerbosity.BASIC);
logger.info("Tumor het pulldown written to " + tumorHetOutputFile.toString());
}
return "SUCCESS";
}
use of htsjdk.samtools.util.IntervalList in project gatk-protected by broadinstitute.
the class Pulldown method getIntervals.
/** Returns a new instance of an IntervalList, constructed from the intervals of the internally held
* AllelicCounts. This IntervalList is modifiable and does not change with the state of the Pulldown. */
public IntervalList getIntervals() {
final IntervalList intervals = new IntervalList(header);
intervals.addall(getCounts().stream().map(AllelicCount::getInterval).map(si -> new Interval(si.getContig(), si.getStart(), si.getEnd())).collect(Collectors.toList()));
return intervals;
}
Aggregations