forked from Illumina/GTCtoVCF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CallFactory.py
46 lines (36 loc) · 1.53 KB
/
CallFactory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from collections import namedtuple
from vcf.model import _Call
class CallFactory(object):
"""
The CallFactory is reponsible for generating _Calls to add to a VCF record
"""
def __init__(self, formats, sample_name, logger):
"""
Create new call factory
Args:
formats (.): List of Formats (GencallFormat, GenotypeFormat) which produce FORMAT values for a particular sample
sample_name (string) : Name of sample reprsented by format
logger (logging.logger): Logger for error logging
Returns:
CallFactory
"""
self._format_namedtuple = namedtuple("format_tuple", [format_element.get_id() for format_element in formats])
self._formats = formats
self._sample_name = sample_name
self._logger = logger
def create_call(self, locus_entry):
"""
Update the VCF record with the call
data from a new sample
Args:
locus_entry (LocusEntry) : Locus entry that links together BPM records to VCF record
sample_name (string): Name of the sample
Returns:
vcf.model._Call - New call entry for this sample and locus
"""
values = []
for format_element in self._formats:
values.append(format_element.generate_sample_format_info(
locus_entry.bpm_records, locus_entry.vcf_record, self._sample_name))
data = self._format_namedtuple(*values)
return _Call(locus_entry.vcf_record, self._sample_name, data)