Skip to content

Commit

Permalink
JQ-325 (cgates): Ensure format tag names preserve order
Browse files Browse the repository at this point in the history
  • Loading branch information
cgates committed Jul 11, 2019
1 parent 304014b commit b66d216
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions jacquard/utils/vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,9 @@ def get_empty_record(self):
def _format_tag_fields(self):
"""Returns list of format tag names."""
tag_names = []
format_field = "."
if self.sample_tag_values:
first_sample = list(self.sample_tag_values.keys())[0]
tag_names = self.sample_tag_values[first_sample].keys()
if tag_names:
format_field = ":".join(tag_names)
tag_names = list(self.sample_tag_values[first_sample].keys())
return tag_names

def _sample_field(self, tag_names, sample):
Expand Down Expand Up @@ -373,14 +370,14 @@ def text(self):
tag_names = self._format_tag_fields()
format_field = '.' if not tag_names else ':'.join(tag_names)

stringifier = [self.chrom, self.pos, self.vcf_id, self.ref, self.alt,
self.qual, self.filter, self.info,
format_field]
fields = [self.chrom, self.pos, self.vcf_id, self.ref, self.alt,
self.qual, self.filter, self.info,
format_field]

for sample in self.sample_tag_values:
stringifier.append(self._sample_field(tag_names, sample))
fields.append(self._sample_field(tag_names, sample))

return "\t".join(stringifier) + "\n"
return "\t".join(fields) + "\n"

def _samples_match(self, new_sample_values):
return set(new_sample_values.keys()) == \
Expand Down

0 comments on commit b66d216

Please sign in to comment.