-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath_abundance.py
242 lines (231 loc) · 8.07 KB
/
path_abundance.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
cervical_columns = []
vaginal_columns = []
rectal_columns = []
f = open("/Users/gracie/Downloads/Thesis/Pathway Abundance/pathabundance_relab.tsv", "r")
first_line = f.readline()[:-1]
columns = first_line.split('\t')
for c in range(len(columns)):
if 'C' in columns[c]:
cervical_columns.append(c)
elif 'V' in columns[c]:
vaginal_columns.append(c)
elif 'R' in columns[c]:
rectal_columns.append(c)
def VcomparedtoR():
print("Pathways that have a higher sum of abundances in vaginal samples than rectal samples")
f2 = open("/Users/gracie/Downloads/unique_V_compared_to_R.tsv", "w")
f2.write(first_line + "\tVaginal Sum\tRectal Sum\tDifference\n")
line = f.readline()[:-1]
while line != "":
columns = line.split('\t')
Vsum = 0
for i in vaginal_columns:
Vsum += float(columns[i])
Rsum = 0
for j in rectal_columns:
Rsum += float(columns[j])
if Vsum > Rsum:
print(columns[0])
f2.write(line + "\t" + str(Vsum) + "\t" + str(Rsum) + "\t" + str(Vsum-Rsum) + "\n")
line = f.readline()[:-1]
f2.close()
def pathways_in_all_V():
print("Pathways found in all vaginal samples")
f2 = open("/Users/gracie/Downloads/pathways_in_all_V.tsv", "w")
f2.write(first_line + "\n")
line = f.readline()[:-1]
while line != "":
columns = line.split('\t')
found0 = False
for i in vaginal_columns:
if float(columns[i]) == 0:
found0 = True
if not found0:
print(columns[0])
f2.write(line + "\n")
line = f.readline()[:-1]
f2.close()
"""Searches for pathways that are only found in vaginal samples,
but could be just some of the vaginal samples, not all"""
def pathways_only_in_V():
print("Pathways only found in vaginal samples")
f2 = open("/Users/gracie/Downloads/pathways_only_in_V.tsv", "w")
f2.write(first_line + "\n")
line = f.readline()[:-1]
while line != "":
columns = line.split('\t')
Vall0 = True
for i in vaginal_columns:
if float(columns[i]) != 0:
Vall0 = False
all0 = True
for i in cervical_columns:
if float(columns[i]) != 0:
all0 = False
for i in rectal_columns:
if float(columns[i]) != 0:
all0 = False
if all0 and not Vall0:
print(columns[0])
f2.write(line + "\n")
line = f.readline()[:-1]
f2.close()
"""Searches for pathways that are only found in rectal samples,
but could be just some of the rectal samples, not all"""
def pathways_only_in_R():
print("Pathways only found in rectal samples")
f2 = open("/Users/gracie/Downloads/pathways_only_in_R.tsv", "w")
f2.write(first_line + "\n")
line = f.readline()[:-1]
while line != "":
columns = line.split('\t')
Rall0 = True
for i in rectal_columns:
if float(columns[i]) != 0:
Rall0 = False
all0 = True
for i in cervical_columns:
if float(columns[i]) != 0:
all0 = False
for i in vaginal_columns:
if float(columns[i]) != 0:
all0 = False
if all0 and not Rall0:
print(columns[0])
f2.write(line + "\n")
line = f.readline()[:-1]
f2.close()
"""Searches for pathways that are only found in cervical samples,
but could be just some of the cervical samples, not all"""
def pathways_only_in_C():
print("Pathways only found in cervical samples")
f2 = open("/Users/gracie/Downloads/pathways_only_in_C.tsv", "w")
f2.write(first_line + "\n")
line = f.readline()[:-1]
while line != "":
columns = line.split('\t')
Call0 = True
for i in cervical_columns:
if float(columns[i]) != 0:
Call0 = False
all0 = True
for i in rectal_columns:
if float(columns[i]) != 0:
all0 = False
for i in vaginal_columns:
if float(columns[i]) != 0:
all0 = False
if all0 and not Call0:
print(columns[0])
f2.write(line + "\n")
line = f.readline()[:-1]
f2.close()
"""Searches for pathways that are not found in rectal samples,
but must be present in at least one vaginal and cervical sample"""
def pathways_only_in_VC():
print("Pathways only found in vaginal and cervical samples")
f2 = open("/Users/gracie/Downloads/Thesis/Pathway Abundance/pathways_only_in_VC.tsv", "w")
f2.write(first_line + "\n")
line = f.readline()[:-1]
while line != "":
columns = line.split('\t')
Vall0 = True
for i in vaginal_columns:
if float(columns[i]) != 0:
Vall0 = False
Call0 = True
for i in cervical_columns:
if float(columns[i]) != 0:
Call0 = False
Rall0 = True
for i in rectal_columns:
if float(columns[i]) != 0:
Rall0 = False
if Rall0 and not Vall0 and not Call0:
print(columns[0])
f2.write(line + "\n")
line = f.readline()[:-1]
f2.close()
"""Searches for pathways that are not found in vaginal samples,
but must be present in at least one cervical and rectal sample"""
def pathways_only_in_CR():
print("Pathways only found in cervical and rectal samples")
f2 = open("/Users/gracie/Downloads/Thesis/Pathway Abundance/pathways_only_in_CR.tsv", "w")
f2.write(first_line + "\n")
line = f.readline()[:-1]
while line != "":
columns = line.split('\t')
Call0 = True
for i in cervical_columns:
if float(columns[i]) != 0:
Call0 = False
Rall0 = True
for i in rectal_columns:
if float(columns[i]) != 0:
Rall0 = False
Vall0 = True
for i in vaginal_columns:
if float(columns[i]) != 0:
Vall0 = False
if Vall0 and not Call0 and not Rall0:
print(columns[0])
f2.write(line + "\n")
line = f.readline()[:-1]
f2.close()
"""Searches for pathways that are not found in cervical samples,
but must be present in at least one vaginal and rectal sample"""
def pathways_only_in_VR():
print("Pathways only found in vaginal and rectal samples")
f2 = open("/Users/gracie/Downloads/Thesis/Pathway Abundance/pathways_only_in_VR.tsv", "w")
f2.write(first_line + "\n")
line = f.readline()[:-1]
while line != "":
columns = line.split('\t')
Vall0 = True
for i in vaginal_columns:
if float(columns[i]) != 0:
Vall0 = False
Rall0 = True
for i in rectal_columns:
if float(columns[i]) != 0:
Rall0 = False
Call0 = True
for i in cervical_columns:
if float(columns[i]) != 0:
Call0 = False
if Call0 and not Vall0 and not Rall0:
print(columns[0])
f2.write(line + "\n")
line = f.readline()[:-1]
f2.close()
"""Searches for pathways that are found at least once in each site"""
def pathways_in_all():
print("Pathways found in all sites")
f2 = open("/Users/gracie/Downloads/Thesis/Pathway Abundance/pathways_only_in_CVR.tsv", "w")
f2.write(first_line + "\n")
line = f.readline()[:-1]
while line != "":
columns = line.split('\t')
Call0 = True
for i in cervical_columns:
if float(columns[i]) != 0:
Call0 = False
Vall0 = True
for i in vaginal_columns:
if float(columns[i]) != 0:
Vall0 = False
Rall0 = True
for i in rectal_columns:
if float(columns[i]) != 0:
Rall0 = False
if not Call0 and not Vall0 and not Rall0:
print(columns[0])
f2.write(line + "\n")
line = f.readline()[:-1]
f2.close()
#Call all the functions you want here:
pathways_only_in_VC()
pathways_only_in_CR()
pathways_only_in_VR()
pathways_in_all()
f.close()