-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter-coinfinder-pairs.py
executable file
·34 lines (31 loc) · 1.33 KB
/
filter-coinfinder-pairs.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
#!/usr/bin/env python3
import os
import sys
import argparse
def main(args):
output = []
p_col = 2
alpha = float(args.alpha)
with open(args.input, 'r') as f:
if not args.noheader:
output.append(f.readline())
for line in f:
linelist = line.rstrip().split('\t')
if float(linelist[p_col]) < alpha:
output.append(line)
print("".join(output))
if __name__ == "__main__":
# Handle arguments
desc = "Filters a coinfinder output file by a p-value threshold."
parser = argparse.ArgumentParser(description=desc)
parser.add_argument("alpha", help="The maximum p-value to include in the output.")
parser.add_argument("input", help="The *_pairs.tsv output file from coinfinder.")
parser.add_argument("--noheader", action='store_true', help="Specify that the input has no header row.")
# Maybe change these to accept multiple inputs so we can filter on several criteria at once.
#parser.add_argument("-c", "--column", help="The index of the column to query (starting from 0).")
#parser.add_argument("-q", "--query", help="The text to match in the specified column.")
args = parser.parse_args()
# Validate our input
if not os.path.isfile(args.input):
sys.exit("Provided file does not exist: {}".format(args.input))
main(args)