-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shared_Ortho.py
81 lines (60 loc) · 2.71 KB
/
Shared_Ortho.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
74
75
76
77
78
79
80
81
#!/usr/local/bin/python
"""
Compare the list of orthologous from one species in different lists.
Ex. genes of sp1 orthologous to sp2 and sp3.
Used (in my case) to get a list of orthologous among the different species (from pair othologou analyses in OMA).
Ref.: Altenhoff A et al., The OMA orthology database in 2015: function predictions, better plant support, synteny view and other improvements, Nucleic Acids Research, 2015, 43 (D1): D240-D249 (doi:10.1093/nar/gku1158).
Usage = Shared_Ortho.py -1 <ortho_sp2> -2 <ortho_sp3> -o <output>
Where:
-1 = list of orthologous genes between the species of interest and sp2
-2 = list of orthologous genes between the species of interest and sp3
-o = name of the output file. List of genes from the species of interest orthologous to the other species
Options: -h for usage help
"""
import sys, getopt
# Check for the arguments, open the inputs and print useful help messages
try:
opts, args = getopt.getopt(sys.argv[1:],"h1:2:o:")
except getopt.GetoptError:
print '\n', '#### Invalid use ####', '\n'
print 'Usage = Shared_Ortho.py -1 <ortho_sp2> -2 <ortho_sp3> -o <output>'
print 'For help use Shared_Ortho.py -h'
sys.exit(99)
for opt, arg in opts:
if len(arg) < 3 and opt == '-h':
print '\n', 'Compare the list of orthologous from one species in different lists. Ex.: genes of sp1 orthologous to sp2 and sp3.', '\n'
print 'Usage = Shared_Ortho.py -1 <ortho_sp2> -2 <ortho_sp3> -o <output>'
print 'Where: -1 = list of orthologous genes between the species of interest and sp2'
print '-2 = list of orthologous genes between the species of interest and sp3'
print '-o = name of the output file. List of genes from the species of interest orthologous to the other species'
sys.exit()
elif len(arg) > 3:
if opt in ("-1"):
list1 = open(arg)
if opt in ("-2"):
list2 = open(arg)
if opt in ("-o", "--output"):
output = open(arg,"w")
elif len(arg) < 3:
print '\n', '### Arguments are missing ###', '\n', '\n' 'Use -h option for help\n'
sys.exit(1)
else:
assert False, "unhandled option"
# Creating useful stuff
gene_list1 = []
gene_list2 = []
# Open the list of genes and save them in another list
for gene in list1:
gene_name = gene.split("\n")
gene_name = str(gene_name[0])
gene_list1.append(gene_name)
for gene in list2:
gene_name = gene.split("\n")
gene_name = str(gene_name[0])
gene_list2.append(gene_name)
# Compare gene lists and save the genes that appear in both
for id in gene_list1:
if id in gene_list2:
output.write(id)
output.write("\n")
output.close()