Skip to content

Commit

Permalink
Per PR comments, change to returning a header line with length set to…
Browse files Browse the repository at this point in the history
… SAMSequenceRecord.UNKNOWN_SEQUENCE_LENGTH
  • Loading branch information
cwhelan committed Oct 1, 2019
1 parent 16f6355 commit 59679d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/main/java/htsjdk/variant/vcf/VCFContigHeaderLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,21 @@ public Integer getContigIndex() {

/**
* Get the SAMSequenceRecord that corresponds to this VCF header line.
* If the VCF header line does not have a length tag, the SAMSequenceRecord returned will be set to have a length of
* SAMSequenceRecord.UNKNOWN_SEQUENCE_LENGTH. Records with unknown length will match any record with the same name
* when evaluated by SAMSequenceRecord.isSameSequence.
* @return The SAMSequenceRecord containing the ID, length, assembly, and index of this contig. Returns null if the
* contig header line does not have a length.
*/
public SAMSequenceRecord getSAMSequenceRecord() {
final String lengthString = this.getGenericFieldValue("length");
if (lengthString == null) return null;
final SAMSequenceRecord record = new SAMSequenceRecord(this.getID(), Integer.parseInt(lengthString));
final int length;
if (lengthString == null) {
length = SAMSequenceRecord.UNKNOWN_SEQUENCE_LENGTH;
} else {
length = Integer.parseInt(lengthString);
}
final SAMSequenceRecord record = new SAMSequenceRecord(this.getID(), length);
record.setAssembly(this.getGenericFieldValue("assembly"));
record.setSequenceIndex(this.contigIndex);
return record;
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/htsjdk/variant/vcf/VCFHeaderUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package htsjdk.variant.vcf;

import htsjdk.samtools.SAMSequenceDictionary;
import htsjdk.samtools.SAMSequenceRecord;
import htsjdk.samtools.util.CloseableIterator;
import htsjdk.samtools.util.FileExtensions;
import htsjdk.samtools.util.IOUtil;
Expand Down Expand Up @@ -247,7 +249,10 @@ public void testVCFHeaderContigLineMissingLength() {
Assert.assertTrue(header.getContigLines().contains(contigLine), "Test contig line not found in contig header lines");
Assert.assertTrue(header.getMetaDataInInputOrder().contains(contigLine), "Test contig line not found in set of all header lines");

Assert.assertNull(header.getSequenceDictionary());
final SAMSequenceDictionary sequenceDictionary = header.getSequenceDictionary();
Assert.assertNotNull(sequenceDictionary);
Assert.assertEquals(sequenceDictionary.getSequence("chr1").getSequenceLength(), SAMSequenceRecord.UNKNOWN_SEQUENCE_LENGTH);

}

@Test
Expand Down

0 comments on commit 59679d8

Please sign in to comment.