File: fix_AF1.py

package info (click to toggle)
metaphlan2 2.6.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 72,684 kB
  • ctags: 351
  • sloc: python: 4,352; sh: 26; makefile: 7
file content (36 lines) | stat: -rwxr-xr-x 840 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python
#Author: Duy Tin Truong (duytin.truong@unitn.it)
#        at CIBIO, University of Trento, Italy


import sys
import argparse

def read_params():
    p = argparse.ArgumentParser()
    p.add_argument('--input_file', required=True, default='-', type=str)

    return vars(p.parse_args())


def fix_AF1(ifn):
    if ifn == '-':
        ifile = sys.stdin
    else:
        ifile = open(ifn, 'r')

    for line in ifile:
        if line[0] != '#':
            if 'AF1=0' in line:
                spline = line.split()
                if spline[3] != spline[4] and spline[4].upper() in ['A', 'T', 'C', 'G']:
                    line = line.replace('AF1=0', 'AF1=1')
        sys.stdout.write(line)

    if ifn != '-':
        ifile.close()


if __name__ == "__main__":
    args = read_params()
    fix_AF1(args['input_file'])