Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write files without FORMAT and genotypes (#95) #97

Merged
merged 2 commits into from Mar 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion vcf/model.py
Expand Up @@ -133,7 +133,7 @@ def __init__(self, CHROM, POS, ID, REF, ALT, QUAL, FILTER, INFO, FORMAT,
self.alleles = [self.REF]
self.alleles.extend(self.ALT)
#: list of ``_Calls`` for each sample ordered as in source VCF
self.samples = samples
self.samples = samples or []
self._sample_indexes = sample_indexes

def __eq__(self, other):
Expand Down
13 changes: 8 additions & 5 deletions vcf/parser.py
Expand Up @@ -220,6 +220,7 @@ def __init__(self, fsock=None, filename=None, compressed=False, prepend_chr=Fals
self.samples = None
self._sample_indexes = None
self._header_lines = []
self._column_headers = []
self._tabix = None
self._prepend_chr = prepend_chr
self._parse_metainfo()
Expand Down Expand Up @@ -274,7 +275,8 @@ def _parse_metainfo(self):

line = self.reader.next()

fields = re.split('\t| +', line)
fields = re.split('\t| +', line[1:])
self._column_headers = fields[:9]
self.samples = fields[9:]
self._sample_indexes = dict([(x,i) for (i,x) in enumerate(self.samples)])

Expand Down Expand Up @@ -538,8 +540,6 @@ def fetch(self, chrom, start, end=None):
class Writer(object):
""" VCF Writer """

fixed_fields = "#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT".split()

# Reverse keys and values in header field count dictionary
counts = dict((v,k) for k,v in field_counts.iteritems())

Expand Down Expand Up @@ -574,13 +574,16 @@ def __init__(self, stream, template, lineterminator="\r\n"):

def _write_header(self):
# TODO: write INFO, etc
self.writer.writerow(self.fixed_fields + self.template.samples)
self.stream.write('#' + '\t'.join(self.template._column_headers
+ self.template.samples) + '\n')

def write_record(self, record):
""" write a record to the file """
ffs = self._map(str, [record.CHROM, record.POS, record.ID, record.REF]) \
+ [self._format_alt(record.ALT), record.QUAL or '.', self._format_filter(record.FILTER),
self._format_info(record.INFO), record.FORMAT]
self._format_info(record.INFO)]
if record.FORMAT:
ffs.append(record.FORMAT)

samples = [self._format_sample(record.FORMAT, sample)
for sample in record.samples]
Expand Down