本文整理汇总了Java中htsjdk.samtools.util.IntervalList.fromFile方法的典型用法代码示例。如果您正苦于以下问题:Java IntervalList.fromFile方法的具体用法?Java IntervalList.fromFile怎么用?Java IntervalList.fromFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htsjdk.samtools.util.IntervalList
的用法示例。
在下文中一共展示了IntervalList.fromFile方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runNormalOnly
import htsjdk.samtools.util.IntervalList; //导入方法依赖的package包/类
/**
* The normal-only workflow
*/
private void runNormalOnly() {
final BayesianHetPulldownCalculator normalHetPulldownCalculator;
final Pulldown normalHetPulldown;
normalHetPulldownCalculator = new BayesianHetPulldownCalculator(REFERENCE_ARGUMENTS.getReferenceFile(),
IntervalList.fromFile(snpFile), minimumMappingQuality, minimumBaseQuality, readDepthThreshold,
VALIDATION_STRINGENCY, errorProbabilityAdjustmentFactor,
new BalancedHeterozygousPileupPriorModel());
logger.info("Calculating the Het pulldown from the normal BAM file using the BALANCED prior...");
normalHetPulldown = normalHetPulldownCalculator.getHetPulldown(normalBamFile, hetCallingStringency);
logger.info("Writing Het pulldown from normal reads to " + normalHetOutputFile.toString());
normalHetPulldown.write(normalHetOutputFile, AllelicCountTableColumn.AllelicCountTableVerbosity.FULL);
}
示例2: runTumorOnly
import htsjdk.samtools.util.IntervalList; //导入方法依赖的package包/类
/**
* The tumor-only workflow
*/
private void runTumorOnly() {
final BayesianHetPulldownCalculator tumorHetPulldownCalculator;
final Pulldown tumorHetPulldown;
tumorHetPulldownCalculator = new BayesianHetPulldownCalculator(REFERENCE_ARGUMENTS.getReferenceFile(),
IntervalList.fromFile(snpFile), minimumMappingQuality, minimumBaseQuality, readDepthThreshold,
VALIDATION_STRINGENCY, errorProbabilityAdjustmentFactor,
new HeterogeneousHeterozygousPileupPriorModel(minimumAbnormalFraction, maximumAbnormalFraction,
maximumCopyNumber, quadratureOrder));
logger.info("Calculating the Het pulldown from the tumor BAM file using the HETEROGENEOUS prior...");
tumorHetPulldown = tumorHetPulldownCalculator.getHetPulldown(tumorBamFile, hetCallingStringency);
logger.info("Writing Het pulldown from tumor reads to " + tumorHetOutputFile.toString());
tumorHetPulldown.write(tumorHetOutputFile, AllelicCountTableColumn.AllelicCountTableVerbosity.FULL);
}
示例3: doWork
import htsjdk.samtools.util.IntervalList; //导入方法依赖的package包/类
@Override
protected Object doWork() {
validateArguments();
final File referenceFile = referenceArguments.getReferenceFile();
final IntervalList siteIntervals = IntervalList.fromFile(inputSiteIntervalsFile);
final AllelicCountCollector allelicCountCollector = new AllelicCountCollector(referenceFile, readValidationStringency);
logger.info("Collecting allelic counts...");
final AllelicCountCollection allelicCounts = allelicCountCollector.collect(inputBAMFile, siteIntervals, minimumMappingQuality, minimumBaseQuality);
allelicCounts.write(outputAllelicCountsFile);
logger.info("Allelic counts written to " + outputAllelicCountsFile.toString());
return "SUCCESS";
}
示例4: makeOverlapDetector
import htsjdk.samtools.util.IntervalList; //导入方法依赖的package包/类
public static OverlapDetector<Interval> makeOverlapDetector(final File samFile, final SAMFileHeader header, final File ribosomalIntervalsFile, final Log log) {
final OverlapDetector<Interval> ribosomalSequenceOverlapDetector = new OverlapDetector<Interval>(0, 0);
if (ribosomalIntervalsFile != null) {
final IntervalList ribosomalIntervals = IntervalList.fromFile(ribosomalIntervalsFile);
if (ribosomalIntervals.size() == 0) {
log.warn("The RIBOSOMAL_INTERVALS file, " + ribosomalIntervalsFile.getAbsolutePath() + " does not contain intervals");
}
try {
SequenceUtil.assertSequenceDictionariesEqual(header.getSequenceDictionary(), ribosomalIntervals.getHeader().getSequenceDictionary());
} catch (SequenceUtil.SequenceListsDifferException e) {
throw new PicardException("Sequence dictionaries differ in " + samFile.getAbsolutePath() + " and " + ribosomalIntervalsFile.getAbsolutePath(),
e);
}
final IntervalList uniquedRibosomalIntervals = ribosomalIntervals.uniqued();
final List<Interval> intervals = uniquedRibosomalIntervals.getIntervals();
ribosomalSequenceOverlapDetector.addAll(intervals, intervals);
}
return ribosomalSequenceOverlapDetector;
}
示例5: doWork
import htsjdk.samtools.util.IntervalList; //导入方法依赖的package包/类
@Override
protected int doWork() {
IOUtil.assertFileIsReadable(INPUT);
IOUtil.assertFileIsWritable(OUTPUT);
IntervalList intervals = IntervalList.fromFile(INPUT);
if (SORT) intervals = intervals.sorted();
try {
final BufferedWriter out = IOUtil.openFileForBufferedWriting(OUTPUT);
for (final Interval i : intervals) {
final String strand = i.isNegativeStrand() ? "-" : "+";
final List<?> fields = CollectionUtil.makeList(i.getContig(), i.getStart()-1, i.getEnd(), i.getName(), SCORE, strand);
out.append(fields.stream().map(String::valueOf).collect(Collectors.joining("\t")));
out.newLine();
}
out.close();
}
catch (IOException ioe) {
throw new RuntimeIOException(ioe);
}
return 0;
}
示例6: runMatchedNormalTumor
import htsjdk.samtools.util.IntervalList; //导入方法依赖的package包/类
/**
* The matched norrmal-tumor workflow
*/
private void runMatchedNormalTumor() {
final BayesianHetPulldownCalculator normalHetPulldownCalculator, tumorHetPulldownCalculator;
final Pulldown normalHetPulldown, tumorHetPulldown;
normalHetPulldownCalculator = new BayesianHetPulldownCalculator(REFERENCE_ARGUMENTS.getReferenceFile(),
IntervalList.fromFile(snpFile), minimumMappingQuality, minimumBaseQuality, readDepthThreshold,
VALIDATION_STRINGENCY, errorProbabilityAdjustmentFactor,
new BalancedHeterozygousPileupPriorModel());
logger.info("Calculating the Het pulldown from the normal BAM file using the BALANCED prior...");
normalHetPulldown = normalHetPulldownCalculator.getHetPulldown(normalBamFile, hetCallingStringency);
logger.info("Writing Het pulldown from normal reads to " + normalHetOutputFile.toString());
normalHetPulldown.write(normalHetOutputFile, AllelicCountTableColumn.AllelicCountTableVerbosity.FULL);
tumorHetPulldownCalculator = new BayesianHetPulldownCalculator(REFERENCE_ARGUMENTS.getReferenceFile(),
normalHetPulldown.getIntervals(), minimumMappingQuality, minimumBaseQuality, readDepthThreshold,
VALIDATION_STRINGENCY, errorProbabilityAdjustmentFactor,
new BalancedHeterozygousPileupPriorModel());
logger.info("Calculating the Het pulldown from the tumor BAM file on Hets detected in the normal BAM file...");
tumorHetPulldown = tumorHetPulldownCalculator.getTumorHetPulldownFromNormalPulldown(tumorBamFile,
normalHetPulldown);
logger.info("Writing Het pulldown from tumor reads to " + tumorHetOutputFile.toString());
tumorHetPulldown.write(tumorHetOutputFile, AllelicCountTableColumn.AllelicCountTableVerbosity.INTERMEDIATE);
}
示例7: HetPulldownCalculator
import htsjdk.samtools.util.IntervalList; //导入方法依赖的package包/类
/**
* Constructs a {@link HetPulldownCalculator} object for calculating {@link Pulldown} objects from files
* containing a reference genome and an interval list of common SNP sites. Reads and bases below the specified
* mapping quality and base quality, respectively, are filtered out of the pileup.
* @param refFile file containing the reference
* @param snpFile file containing the interval list of common SNP sites
* @param minMappingQuality minimum mapping quality required for reads to be included in pileup
* @param minBaseQuality minimum base quality required for bases to be included in pileup
* @param validationStringency validation stringency to use for reading BAM files
*/
public HetPulldownCalculator(final File refFile, final File snpFile,
final int minMappingQuality, final int minBaseQuality,
final ValidationStringency validationStringency) {
ParamUtils.isPositiveOrZero(minMappingQuality, "Minimum mapping quality must be nonnegative.");
ParamUtils.isPositiveOrZero(minBaseQuality, "Minimum base quality must be nonnegative.");
this.refFile = refFile;
snpIntervals = IntervalList.fromFile(snpFile);
this.minMappingQuality = minMappingQuality;
this.minBaseQuality = minBaseQuality;
this.validationStringency = validationStringency;
}
示例8: initHetPulldownCalculator
import htsjdk.samtools.util.IntervalList; //导入方法依赖的package包/类
@BeforeClass
public void initHetPulldownCalculator() {
calculator = new BayesianHetPulldownCalculator(REF_FILE, IntervalList.fromFile(SNP_FILE),
MINIMUM_MAPPING_QUALITY, MINIMUM_BASE_QUALITY, READ_DEPTH_THRESHOLD,
ValidationStringency.STRICT, ERROR_PROBABILITY_ADJUSTMENT_FACTOR,
new HeterogeneousHeterozygousPileupPriorModel(MIN_ABNORMAL_FRACTION, MAX_ABNORMAL_FRACTION,
MAX_COPY_NUMBER, QUADRATURE_ORDER));
}
示例9: doWork
import htsjdk.samtools.util.IntervalList; //导入方法依赖的package包/类
@Override
protected int doWork() {
IOUtil.assertFileIsReadable(INTERVAL_LIST);
IOUtil.assertFileIsReadable(REFERENCE_SEQUENCE);
IOUtil.assertFileIsWritable(OUTPUT);
final IntervalList intervals = IntervalList.fromFile(INTERVAL_LIST);
final ReferenceSequenceFile ref = ReferenceSequenceFileFactory.getReferenceSequenceFile(REFERENCE_SEQUENCE);
SequenceUtil.assertSequenceDictionariesEqual(intervals.getHeader().getSequenceDictionary(), ref.getSequenceDictionary());
final BufferedWriter out = IOUtil.openFileForBufferedWriting(OUTPUT);
for (final Interval interval : intervals) {
final ReferenceSequence seq = ref.getSubsequenceAt(interval.getContig(), interval.getStart(), interval.getEnd());
final byte[] bases = seq.getBases();
if (interval.isNegativeStrand()) SequenceUtil.reverseComplement(bases);
try {
out.write(">");
out.write(interval.getName());
out.write("\n");
for (int i=0; i<bases.length; ++i) {
if (i > 0 && i % LINE_LENGTH == 0) out.write("\n");
out.write(bases[i]);
}
out.write("\n");
}
catch (IOException ioe) {
throw new PicardException("Error writing to file " + OUTPUT.getAbsolutePath(), ioe);
}
}
CloserUtil.close(out);
return 0;
}
示例10: testCommandLine
import htsjdk.samtools.util.IntervalList; //导入方法依赖的package包/类
@Test(dataProvider = "intervalInputsFromCommandLine")
public void testCommandLine(final int binLength, final int paddingLength, final List<Interval> inputIntervals, final List<Interval> binsExpected) {
final File outputFile = createTempFile("GATK-preprocess-intervals-test", ".interval_list");
final ArgumentsBuilder argsBuilder = new ArgumentsBuilder()
.addReference(REFERENCE_FILE)
.addArgument(PreprocessIntervals.BIN_LENGTH_LONG_NAME, Integer.toString(binLength))
.addArgument(PreprocessIntervals.PADDING_LONG_NAME, Integer.toString(paddingLength))
.addArgument(IntervalArgumentCollection.INTERVAL_MERGING_RULE_LONG_NAME, IntervalMergingRule.OVERLAPPING_ONLY.toString())
.addOutput(outputFile);
inputIntervals.forEach(i -> argsBuilder.addArgument(StandardArgumentDefinitions.INTERVALS_LONG_NAME, i.getContig() + ":" + i.getStart() + "-" + i.getEnd()));
runCommandLine(argsBuilder);
final IntervalList binsResult = IntervalList.fromFile(outputFile);
Assert.assertEquals(binsResult, binsExpected);
}
示例11: getProbeIntervals
import htsjdk.samtools.util.IntervalList; //导入方法依赖的package包/类
/**
* @return AMPLICON_INTERVALS
*/
@Override
protected IntervalList getProbeIntervals() {
return IntervalList.fromFile(AMPLICON_INTERVALS);
}
示例12: doWork
import htsjdk.samtools.util.IntervalList; //导入方法依赖的package包/类
/**
* Do the work after command line has been parsed. RuntimeException may be
* thrown by this method, and are reported appropriately.
*
* @return program exit status.
*/
@Override
protected int doWork() {
IOUtil.assertFileIsReadable(INPUT);
IOUtil.assertFileIsReadable(SEQUENCE_DICTIONARY);
IOUtil.assertFileIsReadable(CHAIN);
IOUtil.assertFileIsWritable(OUTPUT);
if (REJECT != null) IOUtil.assertFileIsWritable(REJECT);
final LiftOver liftOver = new LiftOver(CHAIN);
liftOver.setLiftOverMinMatch(MIN_LIFTOVER_PCT);
final IntervalList intervalList = IntervalList.fromFile(INPUT);
final IntervalList rejects = new IntervalList(intervalList.getHeader());
final long baseCount = intervalList.getBaseCount();
LOG.info("Lifting over " + intervalList.getIntervals().size() + " intervals, encompassing " +
baseCount + " bases.");
final SAMFileHeader toHeader = SamReaderFactory.makeDefault().getFileHeader(SEQUENCE_DICTIONARY);
liftOver.validateToSequences(toHeader.getSequenceDictionary());
final IntervalList toIntervals = new IntervalList(toHeader);
for (final Interval fromInterval : intervalList) {
final Interval toInterval = liftOver.liftOver(fromInterval);
if (toInterval != null) {
toIntervals.add(toInterval);
} else {
rejects.add(fromInterval);
LOG.warn("Liftover failed for ", fromInterval, " (len ", fromInterval.length(), ")");
final List<LiftOver.PartialLiftover> partials = liftOver.diagnosticLiftover(fromInterval);
for (final LiftOver.PartialLiftover partial : partials) {
LOG.info(partial);
}
}
}
toIntervals.sorted().write(OUTPUT);
if (REJECT != null) {
rejects.write(REJECT);
}
final long rejectBaseCount = rejects.getBaseCount();
LOG.info(String.format("Liftover Complete. \n" +
"%d of %d intervals failed (%g%%) to liftover, encompassing %d of %d bases (%g%%).",
rejects.getIntervals().size(), intervalList.getIntervals().size(),
100 * rejects.getIntervals().size() / (double) intervalList.getIntervals().size(),
rejectBaseCount, baseCount,
100 * rejectBaseCount / (double) baseCount
));
return rejects.getIntervals().isEmpty() ? 0 : 1;
}
示例13: doWork
import htsjdk.samtools.util.IntervalList; //导入方法依赖的package包/类
@Override
protected int doWork() {
IOUtil.assertFileIsReadable(INPUT);
IOUtil.assertFileIsWritable(OUTPUT);
// set up the reference and a mask so that we only count the positions requested by the user
final ReferenceSequenceFile ref = ReferenceSequenceFileFactory.getReferenceSequenceFile(INPUT);
final ReferenceSequenceMask referenceSequenceMask;
if (INTERVALS != null) {
IOUtil.assertFileIsReadable(INTERVALS);
final IntervalList intervalList = IntervalList.fromFile(INTERVALS);
referenceSequenceMask = new IntervalListReferenceSequenceMask(intervalList);
} else {
final SAMFileHeader header = new SAMFileHeader();
header.setSequenceDictionary(ref.getSequenceDictionary());
referenceSequenceMask = new WholeGenomeReferenceSequenceMask(header);
}
long nonNbases = 0L;
for (final SAMSequenceRecord rec : ref.getSequenceDictionary().getSequences()) {
// pull out the contig and set up the bases
final ReferenceSequence sequence = ref.getSequence(rec.getSequenceName());
final byte[] bases = sequence.getBases();
StringUtil.toUpperCase(bases);
for (int i = 0; i < bases.length; i++) {
// only investigate this position if it's within our mask
if (referenceSequenceMask.get(sequence.getContigIndex(), i+1)) {
nonNbases += bases[i] == SequenceUtil.N ? 0 : 1;
}
}
}
try {
final BufferedWriter out = IOUtil.openFileForBufferedWriting(OUTPUT);
out.write(nonNbases + "\n");
out.close();
}
catch (IOException ioe) {
throw new PicardException("Error writing to file " + OUTPUT.getAbsolutePath(), ioe);
}
return 0;
}
示例14: testIntervals
import htsjdk.samtools.util.IntervalList; //导入方法依赖的package包/类
/**
* Confirm that ViewSam only outputs records that overlap intervals in a provided interval file.
*/
@Test
public void testIntervals() throws Exception {
// a SAM file designed to test intervals against
final File inputSam = new File("testdata/picard/sam/viewsam_intervals_test.sam");
// an interval file containing the intervals to run against the SAM
final File inputIntervalsFile = new File("testdata/picard/sam/viewsam_intervals_test.interval_list");
// create temp output file that ViewSam call get written to
final File viewSamOutputFile = File.createTempFile("ViewSamTest.output.", ".sam");
viewSamOutputFile.deleteOnExit();
final ViewSam viewSam = new ViewSam();
viewSam.INPUT = inputSam.getAbsolutePath();
viewSam.INTERVAL_LIST = inputIntervalsFile;
// create a print stream to this file
final PrintStream viewSamPrintStream = new PrintStream(viewSamOutputFile);
// make sure the command line call exited successfully
Assert.assertEquals(viewSam.writeSamText(viewSamPrintStream), 0);
viewSamPrintStream.close();
// load the interval file
final IntervalList inputIntervalsList = IntervalList.fromFile(inputIntervalsFile);
// ViewSam internally utilizes uniqued intervals, so we will compare to the same
final List<Interval> intervals = inputIntervalsList.uniqued().getIntervals();
// make a reader that is not using intervals to load the output file we wrote that
// was written by the call to ViewSam with the given interval file. This will give us
// the "filtered" file that we can compare to the intervals and ensure that only
// overlapped records were written
final SamReader samReader = SamReaderFactory.makeDefault().open(viewSamOutputFile);
// make sure the intervals file caused at least one match to be found
boolean foundMatches = false;
for (final SAMRecord samRecord : samReader) {
// make an interval representing this SAM record
final Interval samRecordInterval = new Interval(samRecord.getContig(), samRecord.getStart(), samRecord.getEnd());
// go through and look to see whether this SAM interval overlaps a filtering interval
boolean samRecordIntervalOverlaps = false;
for (final Interval interval : intervals) {
if (interval.intersects(samRecordInterval)) {
samRecordIntervalOverlaps = true;
// mark that we have found at least one SAM record that overlaps an interval
foundMatches = true;
break;
}
}
// if this SAM record does not overlap an interval, it should not have been written
Assert.assertTrue(samRecordIntervalOverlaps, "SAM record written out was not overlapped by an interval.");
}
// we should have at least one SAM record written to ensure interval filtering worked correctly
Assert.assertTrue(foundMatches, "No SAM records overlapped the given intervals.");
}