Reading not properly paired reads from a BAM file
1
0
Entering edit mode
4.1 years ago
mhasa006 ▴ 70

I have following BAM file

NB551232:115:H2VJHBGXF:2:22303:20719:3554:CT:GT 97  chr3    17443   54  70M =   17458   72  GTCATATAGATGATGACTGATTTACCCTTTTACTCTGCATGCAGCTTCTCCTGATGGAGTATCGTTTGTG  EEE6/EEAEEAAEEAAEA/E/AEE/<EEEE/EE/EEEAAE/EEEEEE/E<A</EEEAAAEA<<E//EE/<  NM:i:0MD:Z:70   AS:i:70 XS:i:52
NB551232:115:H2VJHBGXF:2:22303:20719:3554:CT:GT 145 chr3    17458   46  57M =   17443   -72 ACTGATTTACCCTTTTACTCTGCATGCAGCTTCTCCTGATGGAGTATCGTTTGTGTG   EEEE6EEE/E/EE/EEEEEEAEEEE//AEEEE/AA/EEE/</EEEEE///EE/E/EA   NM:i:0  MD:Z:57 AS:i:57 XS:i:43

As the flags indicated 97 and 145 these reads are not properly paired reads. How can I read these reads with java hstjdk

Here's what I'm trying

SamReader reader = SamReaderFactory.makeDefault().
               validationStringency(ValidationStringency.LENIENT).
               open(new File(BamPath));
for(SAMRecord record : reader) {
    // do something
}

But this loop doesn't work and does not read the BAM file. Is there some limitations on SAMReader on reading reads with specific flags? How can I read such BAM file with flags like 97, 145, 161 or 81?

BAM java SAMReader • 737 views
ADD COMMENT
1
Entering edit mode
4.1 years ago

Not tested, but the code should look like

(...)
try(CloseableIterator<SAMRecord> iter = reader.iterator()) {
   while(iter.hasNext()) {
   final SAMRecord rec = iter.next();
   if(rec.getReadUnmappedFlag()) continue;
   //etc, etc... see the javadoc for SAMRecord  https://samtools.github.io/htsjdk/javadoc/htsjdk/htsjdk/samtools/SAMRecord.html
   }
}
ADD COMMENT

Login before adding your answer.

Traffic: 2619 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6