Skip to content

Commit

Permalink
Merge pull request #2 from amplab/master
Browse files Browse the repository at this point in the history
off by one error in writing normalize variants
  • Loading branch information
kwestbrooks committed May 14, 2014
2 parents e926574 + 3757bd3 commit b414114
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 2 additions & 3 deletions smashbenchmarking/normalize_vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ def genotype(vcfrecord):
return vcfrecord.samples[0].gt_nums
return {0 : "0/0", 1 : "0/1", 2: "1/1", None : "."}[vcfrecord.samples[0].gt_type]

# assume that input position is 0-based, so offset by 1
def write(record, writer):
return writer.write_record(record.CHROM, record.POS + 1, '.',
record.REF, record.ALT, genotype(record)) # TODO: more gtypes.
return writer.write_record(record.CHROM, record.POS, '.',
record.REF, ','.join(map(lambda a: str(a),record.ALT)), genotype(record)) # TODO: more gtypes.


left_slides = []
Expand Down
2 changes: 1 addition & 1 deletion smashbenchmarking/parsers/vcfwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def write_record(self, CHROM, POS, ID, REF, ALT, gtype):
QUAL = 20 # Default 1/100 error probability.
FILTER = 'PASS'
FORMAT = 'GT'
print(CHROM, POS + 1, ID, REF, ALT, QUAL, FILTER, '.', FORMAT, gtype,
print(CHROM, POS, ID, REF, ALT, QUAL, FILTER, '.', FORMAT, gtype,
sep='\t', file=self._output)
return write

Expand Down
14 changes: 13 additions & 1 deletion test/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def getVcf(self,str):
vcf_io = StringIO.StringIO(str)
return vcf.Reader(vcf_io)

def normalizeString(self,vcf_str):
def normalizeStringToWriter(self,vcf_str):
vcf_io = StringIO.StringIO(vcf_str)
test_vcf = vcf.Reader(vcf_io)
output_io = StringIO.StringIO()
Expand Down Expand Up @@ -234,5 +234,17 @@ def testMultipleAltAlleles(self):
self.assertEqual(record.REF,'G')
self.assertEqual(record.ALT[0],'CG')

def testNormalizerWriter(self):
vcf_str = """##fileformat=VCFv4.0
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">\n
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT NA00001\n
chr1 2 . a c 20 PASS . GT 0/1\n
chr1 4 . A G 20 PASS . GT 1/1\n
"""
output_vcf = self.normalizeStringToWriter(vcf_str)
r1 = output_vcf.next()
self.assertEqual(r1.POS,2)


if __name__ == '__main__':
unittest.main()

0 comments on commit b414114

Please sign in to comment.