--- /dev/null
+package jalview.datamodel;
+
+import java.util.Iterator;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import htsjdk.samtools.SAMRecord;
+import htsjdk.samtools.SAMRecordSetBuilder;
+
+public class CigarParserTest
+{
+ @BeforeClass(alwaysRun = true)
+ public void setup()
+ {
+
+
+
+ }
+
+ @DataProvider(name = "reads")
+ public Object[][] createReadsData()
+ {
+ SortedMap<Integer, Integer> noinsertions = new TreeMap<>();
+
+ SortedMap<Integer, Integer> insertions = new TreeMap<>();
+ insertions.put(8, 3);
+ insertions.put(105, 2);
+
+ SortedMap<Integer, Integer> insertions2 = new TreeMap<>();
+ insertions2.put(11, 2);
+
+ SortedMap<Integer, Integer> insertions3 = new TreeMap<>();
+ insertions3.put(8, 3);
+ insertions3.put(105, 3);
+
+ String read = "CGAAGCTCTTTACCCGGAAACCATTGAAATCGGACGGTTTAGTGAAATGGAGGATCAAGTTGGGTTTGGGTTCCGTCCGAACGACGAGGAGCTCGTTGGTC";
+
+ return new Object[][] { { "1S84M2I14M", read, 21,
+ "----------------------cGAAGCTCTTTACCCGGAAACCATTGAAATCGGACGGTTTAGTGAAATGGAGGATCAAGTTGGGTTTGGGTTCCGTCCGAACGACGAGGAGCTCGTTGGTC",
+ insertions },
+ { "1S84M2I14M", read, 21,
+ "----------------------cGAAGCTCTTTACCCGGAAACCATTGAAATCGGACGGTTTAGTGAAATGGAGGATCAAGTTGGGTTTGGGTTCCGTCCGAACGACGA-GGAGCTCGTTGGTC",
+ insertions3 },
+
+ { "44M1D57M",
+ read,
+ 3,
+ "--CGAAG---CTCTTTACCCGGAAACCATTGAAATCGGACGGTTTAGTG-AAATGGAGGATCAAGTTGGGTTTGGGTTCCGTCCGAACGACGAGGAGCTCGTTGGTC",
+ insertions },
+ { "101M",
+ read, 4,
+ "---CGAA---GCTCTTTACCCGGAAACCATTGAAATCGGACGGTTTAGTGAAATGGAGGATCAAGTTGGGTTTGGGTTCCGTCCGAACGACGAGGAGCTCGTTGGTC",
+ insertions },
+ { "6M2D76M19S",
+ "CGAAGCTTTACCCGGAAACCATTGAAATCGGACGGTTTAGTGAAATGGAGGATCAAGTTGGGTTTGGGTTCCGTCCGAACGACGAGGAGCTCGTTGGTCCC",
+ 4,
+ "---CGAAGC----TTTACCCGGAAACCATTGAAATCGGACGGTTTAGTGAAATGGAGGATCAAGTTGGGTTTGGGTTCCGTCCGAACGAcgaggagctcgttggtccc",
+ insertions2 },
+
+ { "44M1D57M",
+ read,
+ 3,
+ "--CGAAGCTCTTTACCCGGAAACCATTGAAATCGGACGGTTTAGTG-AAATGGAGGATCAAGTTGGGTTTGGGTTCCGTCCGAACGACGAGGAGCTCGTTGGTC",
+ noinsertions },
+ { "101M",
+ read, 4,
+ "---CGAAGCTCTTTACCCGGAAACCATTGAAATCGGACGGTTTAGTGAAATGGAGGATCAAGTTGGGTTTGGGTTCCGTCCGAACGACGAGGAGCTCGTTGGTC",
+ noinsertions },
+ { "5S96M", read, 7,
+ "-cgaagCTCTTTACCCGGAAACCATTGAAATCGGACGGTTTAGTGAAATGGAGGATCAAGTTGGGTTTGGGTTCCGTCCGAACGACGAGGAGCTCGTTGGTC",
+ noinsertions },
+ { "96M5H", read, 7,
+ "------CGAAGCTCTTTACCCGGAAACCATTGAAATCGGACGGTTTAGTGAAATGGAGGATCAAGTTGGGTTTGGGTTCCGTCCGAACGACGAGGAGCTCGT",
+ noinsertions }, };
+ }
+
+ @Test(dataProvider = "reads", groups = { "Functional" })
+ public void testParse(String cigar, String read, int start, String result,
+ SortedMap<Integer, Integer> insertions)
+ {
+ SAMRecord rec = new SAMRecord(null);
+ rec.setCigarString(cigar);
+ rec.setReadString(read);
+ rec.setAlignmentStart(start);
+
+ CigarParser cp = new CigarParser('-');
+ String bfresult = cp.parseCigarToSequence(rec, insertions);
+
+ System.out.println(result);
+ System.out.println(bfresult);
+ Assert.assertEquals(bfresult, result);
+ }
+
+ @Test(groups = { "Functional" })
+ public void testGetInsertions()
+ {
+ final SAMRecordSetBuilder builder = new SAMRecordSetBuilder();
+ builder.addFrag("read_1", 22, 30000, false, false,
+ "101M", "", 0);
+ builder.addFrag("read_2", 22, 28835, false, false,
+ "50M3I48M", "", 0);
+ builder.addFrag("read_3", 22, 28835, false, false, "3M1I75M2I1M", "",
+ 0);
+ builder.addFrag("read_4", 22, 28865, false, false, "48M3I49M", "", 0);
+ builder.addFrag("read_5", 22, 28865, false, false, "49M3I47M2D2M", "",
+ 0);
+ builder.addFrag("read_6", 22, 27000, false, false, "2M4I90M5S", "", 0);
+ builder.addFrag("read_7", 22, 27000, false, false, "2M1I98M", "", 0);
+
+ Iterator<SAMRecord> it = builder.iterator();
+ CigarParser cp = new CigarParser('-');
+ SortedMap<Integer, Integer> insertions = cp.getInsertions(it);
+ Assert.assertEquals(insertions.size(), 5);
+ Assert.assertTrue(insertions.containsKey(28838));
+ Assert.assertEquals((int) insertions.get(28838), 1);
+ Assert.assertTrue(insertions.containsKey(28885));
+ Assert.assertEquals((int) insertions.get(28885), 3);
+ Assert.assertTrue(insertions.containsKey(28913));
+ Assert.assertEquals((int) insertions.get(28913), 3);
+ Assert.assertTrue(insertions.containsKey(28914));
+ Assert.assertEquals((int) insertions.get(28914), 3);
+ Assert.assertTrue(insertions.containsKey(27002));
+ Assert.assertEquals((int) insertions.get(27002), 4);
+ }
+}