comparison call_amr_mutations.py @ 3:30b17a17c1aa draft

Uploaded
author greg
date Tue, 21 Mar 2023 19:26:55 +0000
parents
children bafbed02fdd2
comparison
equal deleted inserted replaced
2:a2fe87395f74 3:30b17a17c1aa
1 #!/usr/bin/env python
2
3 # NOTE: This tool provides the functionality of the PIMA filter_varsacn()
4 # function here https://github.com/appliedbinf/pima_md/blob/main/pima.py#L3012
5
6 import argparse
7 import re
8 import subprocess
9 import sys
10
11
12 def run_command(self, command):
13 try:
14 return re.split('\\n', subprocess.check_output(command, shell=True).decode('utf-8'))
15 except Exception:
16 message = 'Command %s failed: exiting...' % command
17 sys.exit(message)
18
19
20 def filter_varscan(varscan_raw, output):
21 cmd = ' '.join(['cat', varscan_raw,
22 '| awk \'(NR > 1 && $9 == 2 && $5 + $6 >= 15)',
23 '{OFS = "\\t";f = $6 / ($5 + $6); gsub(/.*\\//, "", $4);s = $4;gsub(/[+\\-]/, "", s);$7 = sprintf("%.2f%%", f * 100);'
24 'min = 1 / log(length(s) + 2) / log(10) + 2/10;if(f > min){print}}\'',
25 '1>' + output])
26 output = run_command(cmd)
27
28
29 if __name__ == '__main__':
30 parser = argparse.ArgumentParser()
31
32 parser.add_argument('--varscan_raw', action='store', dest='varscan_raw', help='Raw varscan mpileup VCF file')
33 parser.add_argument('--output', action='store', dest='output', help='Output filtered VCF file')
34
35 args = parser.parse_args()
36
37 filter_varscan(args.varscan_raw, args.output)