Java Code Examples for htsjdk.samtools.util.Interval#getContig()
The following examples show how to use
htsjdk.samtools.util.Interval#getContig() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TargetMetricsCollector.java From picard with MIT License | 6 votes |
/** 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(); }
Example 2
Source File: BaitDesigner.java From picard with MIT License | 6 votes |
@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; }
Example 3
Source File: BAMInputFormat.java From Hadoop-BAM with MIT License | 6 votes |
/** * Converts an interval in SimpleInterval format into an htsjdk QueryInterval. * * In doing so, a header lookup is performed to convert from contig name to index * * @param interval interval to convert * @param sequenceDictionary sequence dictionary used to perform the conversion * @return an equivalent interval in QueryInterval format */ private static QueryInterval convertSimpleIntervalToQueryInterval( final Interval interval, final SAMSequenceDictionary sequenceDictionary ) { if (interval == null) { throw new IllegalArgumentException("interval may not be null"); } if (sequenceDictionary == null) { throw new IllegalArgumentException("sequence dictionary may not be null"); } final int contigIndex = sequenceDictionary.getSequenceIndex(interval.getContig()); if ( contigIndex == -1 ) { throw new IllegalArgumentException("Contig " + interval.getContig() + " not present in reads sequence " + "dictionary"); } return new QueryInterval(contigIndex, interval.getStart(), interval.getEnd()); }
Example 4
Source File: MaskReferenceSequence.java From Drop-seq with MIT License | 5 votes |
private Map<String, List<Interval>> getIntervalsForContig (final IntervalList iList) { Map<String,List<Interval>> result = new HashMap<>(); for (Interval i: iList.getIntervals()) { String contig = i.getContig(); List<Interval> r= result.get(contig); if (r==null) { r = new ArrayList<>(); result.put(contig, r); } r.add(i); } return result; }
Example 5
Source File: IntervalListScattererWithSubdivision.java From picard with MIT License | 5 votes |
@Override public List<Interval> takeSome(final Interval interval, final long idealSplitWeight, final long currentSize, final double projectSizeOfRemaining) { final long amount = idealSplitWeight - currentSize; if (amount >= interval.length()) { return CollectionUtil.makeList(interval, null); } if (amount == 0) { return CollectionUtil.makeList(null, interval); } final Interval left = new Interval( interval.getContig(), interval.getStart(), interval.getStart() + (int) amount - 1, interval.isNegativeStrand(), interval.getName() ); final Interval right = new Interval( interval.getContig(), interval.getStart() + (int) amount, interval.getEnd(), interval.isNegativeStrand(), interval.getName() ); return CollectionUtil.makeList(left, right); }
Example 6
Source File: SNPUMICellReadIteratorWrapperTest.java From Drop-seq with MIT License | 4 votes |
@Test(enabled=true) public void testGeneSNPSplitting () { List<String> cellBarcodeList = ParseBarcodeFile.readCellBarcodeFile(cellBCFile); IntervalList loci = IntervalList.fromFile(snpIntervals); // make a new SNP that is 10 bases before the first SNP. Reads in the test data will hit both. Interval i1 = loci.getIntervals().iterator().next(); Interval i2 = new Interval (i1.getContig(), i1.getStart()-10, i1.getStart()-10, true, "testSNP1"); loci.add(i2); //A read that hits only the default SNP: start read at 76227020 SAMRecord r1 = getReadByName("NS500217:67:H14GMBGXX:1:11308:22039:11268", smallBAMFile); Collection<SAMRecord> tempList = processOneRead(r1, loci, cellBarcodeList); Assert.assertTrue(tempList.size()==1); Assert.assertEquals(1, getNumGenes(tempList)); Assert.assertEquals(1, getNumSNPs(tempList)); //A read that hits both the default SNP and the new SNP: start read at 76227000 r1 = getReadByName("NS500217:67:H14GMBGXX:1:13202:10555:15929", smallBAMFile); tempList = processOneRead(r1, loci, cellBarcodeList); Assert.assertTrue(tempList.size()==2); Assert.assertEquals(1, getNumGenes(tempList)); Assert.assertEquals(2, getNumSNPs(tempList)); // A read that hits only the default SNP: start read at 76227020, has 2 genes. r1 = getReadByName("NS500217:67:H14GMBGXX:1:21206:20467:19854", smallBAMFile); tempList = processOneRead(r1, loci, cellBarcodeList); Assert.assertTrue(tempList.size()==2); Assert.assertEquals(2, getNumGenes(tempList)); Assert.assertEquals(1, getNumSNPs(tempList)); //A read that hits both the default SNP and the new SNP: start read at 76227000, has 2 genes. r1 = getReadByName("NS500217:67:H14GMBGXX:1:22302:3826:3320", smallBAMFile); tempList = processOneRead(r1, loci, cellBarcodeList); Assert.assertTrue(tempList.size()==4); Assert.assertEquals(2, getNumGenes(tempList)); Assert.assertEquals(2, getNumSNPs(tempList)); }
Example 7
Source File: IntervalTagComparator.java From Drop-seq with MIT License | 2 votes |
/** * Converts an Interval object into a string representation that can be parsed by fromString. * Not using the Interval.toString method, because it has tabs, which might really screw up something else... * Instead, use ENCODE_DELIMITER as a delimiter for all fields except the range fields start-end. * @param i The interval to parse * @return A string representation of the interval. */ public static String toString (final Interval i) { // chr1:1-10 + foo String result = i.getContig() + ENCODE_DELIMITER + i.getStart() + "-" + i.getEnd() + ENCODE_DELIMITER + (i.isNegativeStrand() ? '-' : '+') + ENCODE_DELIMITER + ((null == i.getName()) ? '.' : i.getName()); return result; }