-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfail_samples.py
44 lines (40 loc) · 1.53 KB
/
fail_samples.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
#!/usr/bin/env python
import sys
def main():
header = None
num_failed = 0
for line in sys.stdin:
if header is None:
header = line.rstrip().split('\t')
sys.stdout.write('\t'.join(header + ['Failure_Reason']))
sys.stdout.write('\n')
else:
fields = dict(zip(header, line.rstrip().split('\t')))
reason = fail_sample(fields)
sys.stdout.write('\t'.join([ fields[x] for x in header]))
if reason is not None:
sys.stdout.write('\t{0}\n'.format(reason))
num_failed = num_failed + 1
else:
sys.stdout.write('\tPass\n')
sys.stderr.write('{0} failed QC\n'.format(num_failed))
def fail_sample(fields):
reason = list()
#if float(fields['New_Haploid_Coverage']) < 19.5:
if float(fields['Haploid_Coverage']) < 19.5:
reason.append('Coverage')
if float(fields['Freemix']) >= 0.05:
reason.append('Freemix')
if ((float(fields['Read1_Picard_Mismatch_Rate']) >= 0.05) or
(float(fields['Read2_Picard_Mismatch_Rate']) >= 0.05)):
reason.append('mismatch_rate')
if (float(fields['Flagstat_Percentage_Interchromosomal_Pair']) >= 0.05):
reason.append('Interchromosomal')
if ((float(fields['Picard_Percent_Reads_Aligned']) * 100) - float(fields['Flagstat_Percentage_Proper_Pair'])) >= 5.0:
reason.append('Discordant')
if reason:
return ','.join(reason)
else:
return None
if __name__ == '__main__':
main()