Search in sources :

Example 1 with LocusInfo

use of htsjdk.samtools.util.SamLocusIterator.LocusInfo in project ASCIIGenome by dariober.

the class FilterTest method STUBcanCallBS.

// @Test
public void STUBcanCallBS() {
    System.out.println("\u203E");
    int f_incl = 0;
    int F_excl = 0;
    String chrom = "chrY";
    int from = 1;
    int to = 1;
    SamReaderFactory srf = SamReaderFactory.make();
    SamReader samReader = srf.open(new File("test_data/mjb050_oxBS.bam"));
    SAMFileHeader fh = samReader.getFileHeader();
    IntervalList il = new IntervalList(fh);
    Interval interval = new Interval(chrom, from, to);
    il.add(interval);
    List<SamRecordFilter> filters = FlagToFilter.flagToFilterList(f_incl, F_excl);
    SamLocusIterator samLocIter = new SamLocusIterator(samReader, il, true);
    samLocIter.setSamFilters(filters);
    while (samLocIter.hasNext()) {
        LocusInfo locus = samLocIter.next();
        int M = 0;
        int U = 0;
        int mism = 0;
        for (RecordAndOffset recOff : locus.getRecordAndPositions()) {
            int pos = locus.getPosition();
            // Code to get ref sequence at pos
            // If ref sequence is C, count read bases if:
            char refbase = Character.toUpperCase('\0');
            char rb = Character.toUpperCase((char) recOff.getReadBase());
            boolean isTopStrand = (new ReadFromTopStrandFilter(true)).filterOut(recOff.getRecord());
            if (refbase == 'C') {
                if (isTopStrand) {
                    // -ve 2nd pair
                    if (rb == 'C') {
                        M++;
                    } else if (rb == 'T') {
                        U++;
                    } else {
                        mism++;
                    }
                }
            } else if (refbase == 'G') {
                if (!isTopStrand) {
                    if (rb == 'G') {
                        M++;
                    } else if (rb == 'A') {
                        U++;
                    } else {
                        mism++;
                    }
                // System.out.println(locus.getPosition() + " ");
                }
            } else {
            // Not a C on ref
            }
        }
    // if(locus.getRecordAndPositions().size() > 0){
    // System.out.println(locus.getPosition() + " " + locus.getRecordAndPositions().size() + " " +
    // locus.getRecordAndPositions().get(0).getRecord().getFlags());
    // }
    }
}
Also used : SamReaderFactory(htsjdk.samtools.SamReaderFactory) SamRecordFilter(htsjdk.samtools.filter.SamRecordFilter) SamReader(htsjdk.samtools.SamReader) SamLocusIterator(htsjdk.samtools.util.SamLocusIterator) IntervalList(htsjdk.samtools.util.IntervalList) LocusInfo(htsjdk.samtools.util.SamLocusIterator.LocusInfo) RecordAndOffset(htsjdk.samtools.util.SamLocusIterator.RecordAndOffset) SAMFileHeader(htsjdk.samtools.SAMFileHeader) File(java.io.File) Interval(htsjdk.samtools.util.Interval)

Example 2 with LocusInfo

use of htsjdk.samtools.util.SamLocusIterator.LocusInfo in project ASCIIGenome by dariober.

the class FilterTest method canFilterFromIntFlag.

// @Test
public void canFilterFromIntFlag() {
    int f_incl = 131;
    int F_excl = 72;
    String chrom = "chrY";
    int from = 1;
    int to = 100;
    SamReaderFactory srf = SamReaderFactory.make();
    SamReader samReader = srf.open(new File("test_data/mjb050_oxBS.bam"));
    SAMFileHeader fh = samReader.getFileHeader();
    IntervalList il = new IntervalList(fh);
    Interval interval = new Interval(chrom, from, to);
    il.add(interval);
    List<SamRecordFilter> filters = FlagToFilter.flagToFilterList(f_incl, F_excl);
    SamLocusIterator samLocIter = new SamLocusIterator(samReader, il, true);
    samLocIter.setSamFilters(filters);
    while (samLocIter.hasNext()) {
        LocusInfo locus = samLocIter.next();
        if (locus.getRecordAndPositions().size() > 0) {
        // System.out.println(locus.getPosition() + " " + locus.getRecordAndPositions().size() + " " +
        // locus.getRecordAndPositions().get(0).getRecord().getFlags());
        }
    }
}
Also used : SamReader(htsjdk.samtools.SamReader) SamLocusIterator(htsjdk.samtools.util.SamLocusIterator) SamReaderFactory(htsjdk.samtools.SamReaderFactory) SamRecordFilter(htsjdk.samtools.filter.SamRecordFilter) IntervalList(htsjdk.samtools.util.IntervalList) LocusInfo(htsjdk.samtools.util.SamLocusIterator.LocusInfo) SAMFileHeader(htsjdk.samtools.SAMFileHeader) File(java.io.File) Interval(htsjdk.samtools.util.Interval)

Aggregations

SAMFileHeader (htsjdk.samtools.SAMFileHeader)2 SamReader (htsjdk.samtools.SamReader)2 SamReaderFactory (htsjdk.samtools.SamReaderFactory)2 SamRecordFilter (htsjdk.samtools.filter.SamRecordFilter)2 Interval (htsjdk.samtools.util.Interval)2 IntervalList (htsjdk.samtools.util.IntervalList)2 SamLocusIterator (htsjdk.samtools.util.SamLocusIterator)2 LocusInfo (htsjdk.samtools.util.SamLocusIterator.LocusInfo)2 File (java.io.File)2 RecordAndOffset (htsjdk.samtools.util.SamLocusIterator.RecordAndOffset)1