-
Notifications
You must be signed in to change notification settings - Fork 31
/
LogRRatioFormat.py
50 lines (41 loc) · 1.38 KB
/
LogRRatioFormat.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
46
47
48
49
50
from vcf.parser import _Format
import numpy as np
class LogRRatioFormat(object):
"""
Generate log R ratio format information for VCF
"""
def __init__(self, logger, log_r_ratio):
self._log_r_ratio = log_r_ratio
self._logger = logger
@staticmethod
def get_id():
return "LRR"
@staticmethod
def get_description():
return "Log R Ratio"
@staticmethod
def get_format_obj():
# arguments should be: ['id', 'num', 'type', 'desc']
return _Format(LogRRatioFormat.get_id(), 1, "Float", LogRRatioFormat.get_description())
def generate_sample_format_info(self, bpm_records, vcf_record, sample_name):
"""
Get the sample log R ratio
Args:
Returns:
float: log R ratio
"""
# if we have more than 1 BPMRecord, need to merge
log_r_ratio_list = []
# if we have more than 1 alt allele, return missing
if len(vcf_record.ALT) > 1:
return "."
for i in range(len(bpm_records)):
idx = bpm_records[i].index_num
log_r_ratio = self._log_r_ratio[idx]
log_r_ratio_list.append(log_r_ratio)
# nanmedian ignores NaN values
final_log_r_ratio = np.nanmedian(log_r_ratio_list)
if np.isnan(final_log_r_ratio):
return "."
else:
return final_log_r_ratio