本文整理汇总了Java中htsjdk.samtools.util.Interval.intersects方法的典型用法代码示例。如果您正苦于以下问题:Java Interval.intersects方法的具体用法?Java Interval.intersects怎么用?Java Interval.intersects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htsjdk.samtools.util.Interval
的用法示例。
在下文中一共展示了Interval.intersects方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findInterval
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
private Interval findInterval(final String chrom,final int start,final int end)
{
final Interval i= new Interval(chrom,start,end);
final List<Interval> L= new ArrayList<>(this.bedIntervals.getOverlapping(i));
if(L.isEmpty()) return null;
if(L.size()==1) return L.get(0);
if(this.chooseLargestOverlap)
{
Interval best = null;
Integer dist = null;
for(final Interval j: L) {
if(!i.intersects(j)) continue;//????
final int commonDist = i.intersect(j).length();
if(dist==null || dist < commonDist) {
best = j;
dist = commonDist;
}
}
return best;
}
else
{
throw new IllegalStateException(
"Option chooseLargestOverlap not used. Overlapping PCR intervals samRecord "+i+": "+L);
}
}
示例2: annotateVariantContext
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
/**
* Annotate and build the variant
*
* @param vc
* {@link VariantContext} to annotate
* @return annotated {@link VariantContext}
*/
public VariantContext annotateVariantContext(VariantContext vc) {
List<String> overlaps = new ArrayList<>();
try {
final Interval vcInterval = new Interval(vc.getContig(), vc.getStart(), vc.getEnd());
for (BEDFeature bedFeature : reader.query(vc.getContig(), vc.getStart() - 1,
vc.getEnd() + 1)) {
final Interval bedItv = new Interval(bedFeature.getContig(), bedFeature.getStart(),
bedFeature.getEnd());
if (vcInterval.intersects(bedItv)) {
if (options.getColNo() == -1) {
overlaps.add("true"); // marker is enough
break;
} else {
overlaps.add(bedFeature.getName());
}
}
}
} catch (IOException e) {
throw new RuntimeException(
"Could not query " + vc.getContig() + ":" + vc.getStart() + "-" + vc.getEnd(),
e);
}
if (overlaps.isEmpty()) {
return vc;
} else {
VariantContextBuilder builder = new VariantContextBuilder(vc);
if (options.getColNo() == -1) {
builder.attribute(options.getInfoField(), true);
} else {
builder.attribute(options.getInfoField(), overlaps);
}
return builder.make();
}
}
示例3: overlap
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
/** returns true two interval overlap with fraction_overlap */
private boolean overlap(final Interval i1,final Interval i2)
{
if(!i1.intersects(i2)) return false;
final int L1 = i1.length();
final int L2 = i2.length();
final int L3 = i1.getIntersectionLength(i2);
if(L3< (int)(this.fraction_overlap*L1)) return false;
if(L3< (int)(this.fraction_overlap*L2)) return false;
return true;
}
示例4: merge
import htsjdk.samtools.util.Interval; //导入方法依赖的package包/类
private Interval merge(Interval i1,Interval i2) {
if(!i1.intersects(i2)) throw new IllegalArgumentException(""+i1+"/"+i2);
return new Interval(i1.getContig(),
Math.min(i1.getStart(), i2.getStart()),
Math.max(i1.getEnd(), i2.getEnd())
);
}
示例5: testIntervals
import htsjdk.samtools.util.Interval; //导入方法依赖的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.");
}