-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_Count_HumanPPIExp.py
73 lines (54 loc) · 2.33 KB
/
3_Count_HumanPPIExp.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python
import re
import argparse, sys
###########################################################
# Parses miTAB 2.5 or 2.7 file
# Counts the experiments where both proteins have TaxID = '9606' i.e Human
# Prints the total no. of Human-Human Protein Interaction experiments to STDOUT
def checkHumanPPI(interaction_file):
# User input -> Protein-protein Interaction file
interaction_file = sys.stdin
# Skip header
interaction_file.readline()
# Keeping the count of Human-Human protein interaction experiments
HumanInt_Count = 0
# Compiling regular expression
# TaxID id for protein
re_taxID = re.compile('^taxid:(9606)')
# Parsing the interaction file
for line in interaction_file:
line = line.rstrip('\n')
line_fields = line.split('\t')
# Initializing TaxID accumulator
TaxIDs = ['','']
for taxindex in [0,1]:
if (re_taxID.match(line_fields[taxindex+9])):
ID = re_taxID.match(line_fields[taxindex+9]).group(1)
TaxIDs[taxindex] = ID
continue
if (TaxIDs[0] == '9606') and (TaxIDs[1] == '9606'):
HumanInt_Count += 1
continue
print("\nTotal Number of Human-Human Protein Interaction experiments: ", HumanInt_Count, "\n")
# Closing the file
interaction_file.close()
###########################################################
# Taking and handling command-line arguments
def main():
file_parser = argparse.ArgumentParser(description =
"""
----------------------------------------------------------------------------------------------------------------------
Program: Parses a miTAB 2.5 or 2.7 file and prints the number of Human-Human Protein Interaction experiments to STDOUT
----------------------------------------------------------------------------------------------------------------------
Usage:
% python 3_check_HumanPPIExp.py < Input file
OR
% cat Input file | python 3_check_HumanPPIExp.py
----------------------------------------------------------------------------------------------------------------------
""",
formatter_class = argparse.RawDescriptionHelpFormatter)
file_parser.set_defaults(func=checkHumanPPI)
args = file_parser.parse_args()
args.func(args)
if __name__ == "__main__":
main()