SAMUtils:getOtherCanonicalAlignments extract 'SA' tag and return a list of supplementary alignments #685
Merged
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
Jump to file or symbol
Failed to load files and symbols.
| @@ -26,7 +26,7 @@ | ||
| import org.testng.Assert; | ||
| import org.testng.annotations.Test; | ||
| -import java.util.Arrays; | ||
| +import java.util.List; | ||
| public class SAMUtilsTest { | ||
| @Test | ||
| @@ -173,4 +173,79 @@ public void testClippingOfRecordWithMateAtSamePosition() { | ||
| record.setSecondOfPairFlag(true); | ||
| Assert.assertEquals(SAMUtils.getNumOverlappingAlignedBasesToClip(record), 10); | ||
| } | ||
| + | ||
| + @Test | ||
| + public void testOtherCanonicalAlignments() { | ||
| + // setup the record | ||
| + final SAMFileHeader header = new SAMFileHeader(); | ||
| + header.addSequence(new SAMSequenceRecord("1", 1000)); | ||
| + header.addSequence(new SAMSequenceRecord("2", 1000)); | ||
| + final SAMRecord record = new SAMRecord(header); | ||
| + record.setReadPairedFlag(true); | ||
| + record.setFirstOfPairFlag(true); | ||
| + record.setCigar(TextCigarCodec.decode("10M")); | ||
| + record.setReferenceIndex(0); | ||
| + record.setAlignmentStart(1); | ||
| + record.setMateReferenceIndex(0); | ||
| + record.setMateAlignmentStart(1); | ||
| + record.setReadPairedFlag(true); | ||
| + record.setSupplementaryAlignmentFlag(true);//spec says first 'SA' record will be the primary record | ||
| + | ||
| + record.setMateReferenceIndex(0); | ||
| + record.setMateAlignmentStart(100); | ||
| + record.setInferredInsertSize(99); | ||
| + | ||
| + record.setReadBases("AAAAAAAAAA".getBytes()); | ||
| + record.setBaseQualities("##########".getBytes()); | ||
| + // check no alignments if no SA tag */ | ||
| + Assert.assertEquals(SAMUtils.getOtherCanonicalAlignments(record).size(),0); | ||
| + | ||
| + | ||
| + record.setAttribute(SAMTagUtil.getSingleton().SA, | ||
| + "2,500,+,3S2=1X2=2S,60,1;" + | ||
| + "1,191,-,8M2S,60,0;"); | ||
| + | ||
| + // extract suppl alignments | ||
| + final List<SAMRecord> suppl = SAMUtils.getOtherCanonicalAlignments(record); | ||
| + Assert.assertNotNull(suppl); | ||
| + Assert.assertEquals(suppl.size(), 2); | ||
| + | ||
| + for(final SAMRecord other: suppl) { | ||
| + Assert.assertFalse(other.getReadUnmappedFlag()); | ||
| + Assert.assertTrue(other.getReadPairedFlag()); | ||
| + Assert.assertFalse(other.getMateUnmappedFlag()); | ||
| + Assert.assertEquals(other.getMateAlignmentStart(),record.getMateAlignmentStart()); | ||
| + Assert.assertEquals(other.getMateReferenceName(),record.getMateReferenceName()); | ||
| + | ||
| + Assert.assertEquals(other.getReadName(),record.getReadName()); | ||
| + if( other.getReadNegativeStrandFlag()==record.getReadNegativeStrandFlag()) { | ||
| + Assert.assertEquals(other.getReadString(),record.getReadString()); | ||
| + Assert.assertEquals(other.getBaseQualityString(),record.getBaseQualityString()); | ||
| + } | ||
| + } | ||
| + | ||
| + SAMRecord other = suppl.get(0); | ||
| + Assert.assertFalse(other.getSupplementaryAlignmentFlag());//1st of suppl and 'record' is supplementary | ||
| + Assert.assertEquals(other.getReferenceName(),"2"); | ||
| + Assert.assertEquals(other.getAlignmentStart(),500); | ||
| + Assert.assertFalse(other.getReadNegativeStrandFlag()); | ||
| + Assert.assertEquals(other.getMappingQuality(), 60); | ||
| + Assert.assertEquals(other.getAttribute(SAMTagUtil.getSingleton().NM),1); | ||
| + Assert.assertEquals(other.getCigarString(),"3S2=1X2=2S"); | ||
| + Assert.assertEquals(other.getInferredInsertSize(),0); | ||
| + | ||
| + | ||
| + other = suppl.get(1); | ||
| + Assert.assertTrue(other.getSupplementaryAlignmentFlag()); | ||
| + Assert.assertEquals(other.getReferenceName(),"1"); | ||
| + Assert.assertEquals(other.getAlignmentStart(),191); | ||
| + Assert.assertTrue(other.getReadNegativeStrandFlag()); | ||
| + Assert.assertEquals(other.getMappingQuality(), 60); | ||
| + Assert.assertEquals(other.getAttribute(SAMTagUtil.getSingleton().NM),0); | ||
| + Assert.assertEquals(other.getCigarString(),"8M2S"); | ||
jamesemery
Contributor
|
||
| + Assert.assertEquals(other.getInferredInsertSize(),-91);//100(mate) - 191(other) | ||
| + | ||
| + | ||
| + } | ||
| + | ||
| } | ||
Furthermore, what about the mate information?