本文整理汇总了Java中htsjdk.samtools.util.Interval类的典型用法代码示例。如果您正苦于以下问题:Java Interval类的具体用法?Java Interval怎么用?Java Interval使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Interval类属于htsjdk.samtools.util包,在下文中一共展示了Interval类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: groupMrnaStuff
import htsjdk.samtools.util.Interval; //导入依赖的package包/类
protected void groupMrnaStuff(List<Gene> mRnaStuff, IntervalTreeMap<Gene> stuffIntervalMap) {
for (Gene s : mRnaStuff) {
Interval interval = new Interval(s.getFeature(), s.getStartIndex(), s.getEndIndex());
if (stuffIntervalMap.containsKey(interval)) {
Gene merged = s;
List<Interval> toRemove = new ArrayList<>();
for (Gene g : stuffIntervalMap.getOverlapping(interval)) {
merged.setStartIndex(Math.min(merged.getStartIndex(), g.getStartIndex()));
merged.setEndIndex(Math.max(merged.getEndIndex(), g.getEndIndex()));
merged.setGroupId(null);
merged.setAttributes(Collections.emptyMap());
toRemove.add(new Interval(s.getFeature(), g.getStartIndex(), g.getEndIndex()));
}
merged.setFeature(FeatureType.CDS.name());
toRemove.forEach(stuffIntervalMap::remove);
stuffIntervalMap.put(new Interval(s.getFeature(), merged.getStartIndex(), merged.getEndIndex()),
merged);
} else {
s.setFeature(FeatureType.CDS.name());
stuffIntervalMap.put(interval, s);
}
}
}
示例2: getGeneIds
import htsjdk.samtools.util.Interval; //导入依赖的package包/类
private Set<VariationGeneInfo> getGeneIds(NggbIntervalTreeMap<List<Gene>> intervalMap,
Chromosome chromosome, int start, int end) {
Collection<Gene> genes = intervalMap.getOverlapping(new Interval(chromosome.getName(), start, end))
.stream()
.flatMap(l -> l.stream())
.collect(Collectors.toList());
Set<VariationGeneInfo> geneIds = new HashSet<>();
if (genes != null) {
boolean isExon = genes.stream().anyMatch(GeneUtils::isExon);
geneIds = genes.stream()
.filter(GeneUtils::isGene)
.map(g -> new VariationGeneInfo(g.getGroupId(), g.getFeatureName(), isExon))
.collect(Collectors.toSet());
}
return geneIds;
}
示例3: onTraversalStart
import htsjdk.samtools.util.Interval; //导入依赖的package包/类
@Override
public void onTraversalStart() {
ParamUtils.isPositive(scatterCount, "scatter count must be > 0.");
if (!outputDir.exists() && !outputDir.mkdir()) {
throw new RuntimeIOException("Unable to create directory: " + outputDir.getAbsolutePath());
}
// in general dictionary will be from the reference, but using -I reads.bam or -F variants.vcf
// to use the sequence dict from a bam or vcf is also supported
final SAMSequenceDictionary sequenceDictionary = getBestAvailableSequenceDictionary();
final List<SimpleInterval> intervals = hasIntervals() ? intervalArgumentCollection.getIntervals(sequenceDictionary)
: IntervalUtils.getAllIntervalsForReference(sequenceDictionary);
final IntervalList intervalList = new IntervalList(sequenceDictionary);
intervals.stream().map(si -> new Interval(si.getContig(), si.getStart(), si.getEnd())).forEach(intervalList::add);
final IntervalListScatterer scatterer = new IntervalListScatterer(subdivisionMode);
final List<IntervalList> scattered = scatterer.scatter(intervalList, scatterCount, false);
final DecimalFormat formatter = new DecimalFormat("0000");
IntStream.range(0, scattered.size()).forEach(n -> scattered.get(n).write(new File(outputDir, formatter.format(n) + "-scattered.intervals")));
}
示例4: inputGetTumorHetPulldown
import htsjdk.samtools.util.Interval; //导入依赖的package包/类
@DataProvider(name = "inputGetTumorHetPulldown")
public Object[][] inputGetTumorHetPulldown() {
final Pulldown tumorHetPulldown = new Pulldown(normalHeader);
tumorHetPulldown.add(new AllelicCount(new SimpleInterval("1", 11522, 11522), 7, 4));
tumorHetPulldown.add(new AllelicCount(new SimpleInterval("1", 12098, 12098), 8, 6));
tumorHetPulldown.add(new AllelicCount(new SimpleInterval("1", 14630, 14630), 9, 8));
tumorHetPulldown.add(new AllelicCount(new SimpleInterval("2", 14689, 14689), 6, 9));
tumorHetPulldown.add(new AllelicCount(new SimpleInterval("2", 14982, 14982), 6, 5));
final IntervalList normalHetIntervals = new IntervalList(tumorHeader);
normalHetIntervals.add(new Interval("1", 11522, 11522));
normalHetIntervals.add(new Interval("1", 12098, 12098));
normalHetIntervals.add(new Interval("1", 14630, 14630));
normalHetIntervals.add(new Interval("2", 14689, 14689));
normalHetIntervals.add(new Interval("2", 14982, 14982));
return new Object[][]{
{normalHetIntervals, tumorHetPulldown}
};
}
示例5: excludingNonOverlaps
import htsjdk.samtools.util.Interval; //导入依赖的package包/类
/**
* Returns a decorated {@link VcfFileSegmentGenerator} that filters out {@link VcfFileSegment}s that have no overlap with the provided
* {@link OverlapDetector}.
*/
public static <T> VcfFileSegmentGenerator excludingNonOverlaps(final VcfFileSegmentGenerator strategy, final OverlapDetector<T> overlaps) {
return new VcfFileSegmentGenerator() {
@Override
public Iterable<VcfFileSegment> forVcf(final File vcf) {
return FluentIterable.from(strategy.forVcf(vcf)).filter(new Predicate<VcfFileSegment>() {
@Override
public boolean apply(final VcfFileSegment segment) {
final boolean keep = !overlaps.getOverlaps(new Interval(segment.contig(), segment.start(), segment.stop())).isEmpty();
if (!keep) {
LOG.debug(String.format("Ignoring segment because it does not overlap with detector, %s::%s:%s-%s",
segment.vcf().getName(), segment.contig(), segment.start(), segment.stop())
);
}
return keep;
}
});
}
};
}
示例6: apply
import htsjdk.samtools.util.Interval; //导入依赖的package包/类
@Override
public boolean apply(final VariantContext vc) {
if (vc.getStart() == vc.getEnd()) {
// This isn't a multi-allelic segment, so it can only be produced by a single segment.
return true;
}
final Collection<VcfFileSegment> intersectingSegments =
multiSegmentDetectorPerFile.get(sourceSegment.vcf()).getOverlaps(new Interval(vc.getContig(), vc.getStart(), vc.getEnd()));
if (intersectingSegments.size() < 2) {
// There's only one segment that produces this variant
return true;
}
// The convention is: only emit the VC if it is produced from the first segment that can produce it in the list.
final int sourceSegmentIndex = segments.indexOf(sourceSegment);
LOG.debug("Found wide variant spanning multiple source segments: ", vc);
for (final VcfFileSegment intersectingSegment : intersectingSegments) {
if (segments.indexOf(intersectingSegment) < sourceSegmentIndex) {
// There is a segment that produces this variant earlier in the segment list, exclude it.
return false;
}
}
LOG.debug("Emitting wide variant because it belongs to first segment: ", vc);
return true;
}
示例7: setup
import htsjdk.samtools.util.Interval; //导入依赖的package包/类
@Override
protected void setup(final SAMFileHeader header, final File samFile) {
if (CHART_OUTPUT != null) IOUtil.assertFileIsWritable(CHART_OUTPUT);
final OverlapDetector<Gene> geneOverlapDetector = GeneAnnotationReader.loadRefFlat(REF_FLAT, header.getSequenceDictionary());
LOG.info("Loaded " + geneOverlapDetector.getAll().size() + " genes.");
final Long ribosomalBasesInitialValue = RIBOSOMAL_INTERVALS != null ? 0L : null;
final OverlapDetector<Interval> ribosomalSequenceOverlapDetector = RnaSeqMetricsCollector.makeOverlapDetector(samFile, header, RIBOSOMAL_INTERVALS, LOG);
final HashSet<Integer> ignoredSequenceIndices = RnaSeqMetricsCollector.makeIgnoredSequenceIndicesSet(header, IGNORE_SEQUENCE);
collector = new RnaSeqMetricsCollector(METRIC_ACCUMULATION_LEVEL, header.getReadGroups(), ribosomalBasesInitialValue,
geneOverlapDetector, ribosomalSequenceOverlapDetector, ignoredSequenceIndices, MINIMUM_LENGTH, STRAND_SPECIFICITY, RRNA_FRAGMENT_PERCENTAGE,
true);
// If we're working with a single library, assign that library's name as a suffix to the plot title
final List<SAMReadGroupRecord> readGroups = header.getReadGroups();
if (readGroups.size() == 1) {
this.plotSubtitle = readGroups.get(0).getLibrary();
if (null == this.plotSubtitle) this.plotSubtitle = "";
}
}
示例8: makeOverlapDetector
import htsjdk.samtools.util.Interval; //导入依赖的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;
}
示例9: emitPerBaseCoverageIfRequested
import htsjdk.samtools.util.Interval; //导入依赖的package包/类
/** Emits a file with per base coverage if an output file has been set. */
private void emitPerBaseCoverageIfRequested() {
if (this.perBaseOutput == null) return;
final PrintWriter out = new PrintWriter(IOUtil.openFileForBufferedWriting(this.perBaseOutput));
out.println("chrom\tpos\ttarget\tcoverage");
for (final Map.Entry<Interval,Coverage> entry : this.highQualityCoverageByTarget.entrySet()) {
final Interval interval = entry.getKey();
final String chrom = interval.getContig();
final int firstBase = interval.getStart();
final int[] cov = entry.getValue().getDepths();
for (int i = 0; i < cov.length; ++i) {
out.print(chrom);
out.print('\t');
out.print(firstBase + i);
out.print('\t');
out.print(interval.getName());
out.print('\t');
out.print(cov[i]);
out.println();
}
}
out.close();
}
示例10: doWork
import htsjdk.samtools.util.Interval; //导入依赖的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;
}
示例11: design
import htsjdk.samtools.util.Interval; //导入依赖的package包/类
@Override
List<Bait> design(final BaitDesigner designer, final Interval target, final ReferenceSequence reference) {
final List<Bait> baits = new LinkedList<Bait>();
final int baitSize = designer.BAIT_SIZE;
final int baitOffset = designer.BAIT_OFFSET;
final int lastPossibleBaitStart = Math.min(target.getEnd(), reference.length() - baitSize);
final int baitCount = 1 + (int) Math.floor((lastPossibleBaitStart - target.getStart()) / (double) baitOffset);
int i = 0;
for (int start = target.getStart(); start < lastPossibleBaitStart; start += baitOffset) {
final Bait bait = new Bait(target.getContig(),
start,
CoordMath.getEnd(start, baitSize),
target.isNegativeStrand(),
designer.makeBaitName(target.getName(), ++i, baitCount));
bait.addBases(reference, designer.DESIGN_ON_TARGET_STRAND);
baits.add(bait);
}
return baits;
}
示例12: calculateStatistics
import htsjdk.samtools.util.Interval; //导入依赖的package包/类
/** Calculates a few statistics about the bait design that can then be output. */
void calculateStatistics(final IntervalList targets, final IntervalList baits) {
this.TARGET_TERRITORY = (int) targets.getUniqueBaseCount();
this.TARGET_COUNT = targets.size();
this.BAIT_TERRITORY = (int) baits.getUniqueBaseCount();
this.BAIT_COUNT = baits.size();
this.DESIGN_EFFICIENCY = this.TARGET_TERRITORY / (double) this.BAIT_TERRITORY;
// Figure out the intersection between all targets and all baits
final IntervalList tmp = new IntervalList(targets.getHeader());
final OverlapDetector<Interval> detector = new OverlapDetector<Interval>(0, 0);
detector.addAll(baits.getIntervals(), baits.getIntervals());
for (final Interval target : targets) {
final Collection<Interval> overlaps = detector.getOverlaps(target);
if (overlaps.isEmpty()) {
this.ZERO_BAIT_TARGETS++;
} else {
for (final Interval i : overlaps) tmp.add(target.intersect(i));
}
}
tmp.uniqued();
this.BAIT_TARGET_TERRITORY_INTERSECTION = (int) tmp.getBaseCount();
}
示例13: reverseComplement
import htsjdk.samtools.util.Interval; //导入依赖的package包/类
private static Allele reverseComplement(final Allele oldAllele, final Interval target, final ReferenceSequence referenceSequence, final boolean isBiAllelicIndel, final boolean addToStart){
if (oldAllele.isSymbolic() || oldAllele.isNoCall()) {
return oldAllele;
}
else if (isBiAllelicIndel) {
// target.getStart is 1-based, reference bases are 0-based
final StringBuilder alleleBuilder = new StringBuilder(target.getEnd() - target.getStart() + 1);
if (addToStart) {
alleleBuilder.append((char) referenceSequence.getBases()[target.getStart() - 2]);
}
alleleBuilder.append(SequenceUtil.reverseComplement(oldAllele.getBaseString().substring(1, oldAllele.length())));
if (!addToStart) {
alleleBuilder.append((char) referenceSequence.getBases()[target.getEnd() - 1]);
}
return Allele.create(alleleBuilder.toString(), oldAllele.isReference());
} else {
return Allele.create(SequenceUtil.reverseComplement(oldAllele.getBaseString()), oldAllele.isReference());
}
}
示例14: testExcludingFiltered
import htsjdk.samtools.util.Interval; //导入依赖的package包/类
@Test(dataProvider="VcfToIntervalListData")
public void testExcludingFiltered(
final File inputFile,
final boolean includeFiltered,
final int expectedIntervalsSize) throws IOException
{
final File outputFile = File.createTempFile("vcftointervallist_", ".interval_list");
outputFile.deleteOnExit();
final List<String> arguments = new ArrayList<>();
arguments.add("I=" + inputFile.getAbsolutePath());
arguments.add("O=" + outputFile.getAbsolutePath());
if (includeFiltered) {
arguments.add(VcfToIntervalList.INCLUDE_FILTERED_SHORT_NAME + "=true");
}
runPicardCommandLine(arguments);
Assert.assertTrue(outputFile.exists());
final List<Interval> intervals = IntervalList.fromFile(outputFile).getIntervals();
Assert.assertEquals(intervals.size(), expectedIntervalsSize);
}
示例15: prepareQueryIntervals
import htsjdk.samtools.util.Interval; //导入依赖的package包/类
/**
* Converts a List of SimpleIntervals into the format required by the SamReader query API
* @param rawIntervals SimpleIntervals to be converted
* @return A sorted, merged list of QueryIntervals suitable for passing to the SamReader query API
*/
static QueryInterval[] prepareQueryIntervals( final List<Interval>
rawIntervals, final SAMSequenceDictionary sequenceDictionary ) {
if ( rawIntervals == null || rawIntervals.isEmpty() ) {
return null;
}
// Convert each SimpleInterval to a QueryInterval
final QueryInterval[] convertedIntervals =
rawIntervals.stream()
.map(rawInterval -> convertSimpleIntervalToQueryInterval(rawInterval, sequenceDictionary))
.toArray(QueryInterval[]::new);
// Intervals must be optimized (sorted and merged) in order to use the htsjdk query API
return QueryInterval.optimizeIntervals(convertedIntervals);
}