Search in sources :

Example 26 with IntervalList

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;
}
Also used : IntervalList(htsjdk.samtools.util.IntervalList) DecimalFormat(java.text.DecimalFormat)

Example 27 with IntervalList

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;
}
Also used : IntervalList(htsjdk.samtools.util.IntervalList) File(java.io.File) Interval(htsjdk.samtools.util.Interval)

Example 28 with IntervalList

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;
}
Also used : LiftOver(htsjdk.samtools.liftover.LiftOver) IntervalList(htsjdk.samtools.util.IntervalList) SAMFileHeader(htsjdk.samtools.SAMFileHeader) Interval(htsjdk.samtools.util.Interval)

Example 29 with IntervalList

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";
}
Also used : Pulldown(org.broadinstitute.hellbender.tools.exome.pulldown.Pulldown) IntervalList(htsjdk.samtools.util.IntervalList) HetPulldownCalculator(org.broadinstitute.hellbender.tools.exome.pulldown.HetPulldownCalculator)

Example 30 with IntervalList

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;
}
Also used : IntervalList(htsjdk.samtools.util.IntervalList) Interval(htsjdk.samtools.util.Interval)

Aggregations

IntervalList (htsjdk.samtools.util.IntervalList)37 Interval (htsjdk.samtools.util.Interval)23 File (java.io.File)18 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)12 UserException (org.broadinstitute.hellbender.exceptions.UserException)7 SAMFileHeader (htsjdk.samtools.SAMFileHeader)6 SamLocusIterator (htsjdk.samtools.util.SamLocusIterator)6 IOException (java.io.IOException)6 List (java.util.List)6 AllelicCount (org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount)6 Nucleotide (org.broadinstitute.hellbender.utils.Nucleotide)6 ParamUtils (org.broadinstitute.hellbender.utils.param.ParamUtils)6 DataProvider (org.testng.annotations.DataProvider)6 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)5 Test (org.testng.annotations.Test)5 htsjdk.samtools (htsjdk.samtools)4 QueryInterval (htsjdk.samtools.QueryInterval)4 DuplicateReadFilter (htsjdk.samtools.filter.DuplicateReadFilter)4 NotPrimaryAlignmentFilter (htsjdk.samtools.filter.NotPrimaryAlignmentFilter)4 SamRecordFilter (htsjdk.samtools.filter.SamRecordFilter)4