Skip to content

Commit

Permalink
Fixing parsing of genomelocs that contain colons in the contig names …
Browse files Browse the repository at this point in the history
…(which is allowed by the spec) as reported on the forum. Added unit test for this case.
  • Loading branch information
eitanbanks committed Nov 27, 2012
1 parent ccc96d0 commit 4883454
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Expand Up @@ -374,7 +374,7 @@ public GenomeLoc parseGenomeLoc(final String str) {
int start = 1; int start = 1;
int stop = -1; int stop = -1;


final int colonIndex = str.indexOf(":"); final int colonIndex = str.lastIndexOf(":");
if(colonIndex == -1) { if(colonIndex == -1) {
contig = str.substring(0, str.length()); // chr1 contig = str.substring(0, str.length()); // chr1
stop = Integer.MAX_VALUE; stop = Integer.MAX_VALUE;
Expand Down
Expand Up @@ -2,6 +2,8 @@




import net.sf.samtools.SAMFileHeader; import net.sf.samtools.SAMFileHeader;
import net.sf.samtools.SAMSequenceDictionary;
import net.sf.samtools.SAMSequenceRecord;
import org.broadinstitute.sting.BaseTest; import org.broadinstitute.sting.BaseTest;
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.exceptions.UserException;
Expand Down Expand Up @@ -74,14 +76,31 @@ public void testParseBadString() {
genomeLocParser.parseGenomeLoc("Bad:0-1"); genomeLocParser.parseGenomeLoc("Bad:0-1");
} }


@Test
public void testContigHasColon() {
SAMFileHeader header = new SAMFileHeader();
header.setSortOrder(net.sf.samtools.SAMFileHeader.SortOrder.coordinate);
SAMSequenceDictionary dict = new SAMSequenceDictionary();
SAMSequenceRecord rec = new SAMSequenceRecord("c:h:r1", 10);
rec.setSequenceLength(10);
dict.addSequence(rec);
header.setSequenceDictionary(dict);

final GenomeLocParser myGenomeLocParser = new GenomeLocParser(header.getSequenceDictionary());
GenomeLoc loc = myGenomeLocParser.parseGenomeLoc("c:h:r1:4-5");
assertEquals(0, loc.getContigIndex());
assertEquals(loc.getStart(), 4);
assertEquals(loc.getStop(), 5);
}

@Test @Test
public void testParseGoodString() { public void testParseGoodString() {
GenomeLoc loc = genomeLocParser.parseGenomeLoc("chr1:1-10"); GenomeLoc loc = genomeLocParser.parseGenomeLoc("chr1:1-10");
assertEquals(0, loc.getContigIndex()); assertEquals(0, loc.getContigIndex());
assertEquals(loc.getStop(), 10); assertEquals(loc.getStop(), 10);
assertEquals(loc.getStart(), 1); assertEquals(loc.getStart(), 1);
} }

@Test @Test
public void testCreateGenomeLoc1() { public void testCreateGenomeLoc1() {
GenomeLoc loc = genomeLocParser.createGenomeLoc("chr1", 1, 100); GenomeLoc loc = genomeLocParser.createGenomeLoc("chr1", 1, 100);
Expand Down

0 comments on commit 4883454

Please sign in to comment.