forked from Shivi91/Rosalind-1
-
Notifications
You must be signed in to change notification settings - Fork 4
/
012_GRPH.py
28 lines (22 loc) · 912 Bytes
/
012_GRPH.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
#!/usr/bin/env python
'''
A solution to a ROSALIND bioinformatics problem.
Problem Title: Overlap Graphs
Rosalind ID: GRPH
Rosalind #: 012
URL: http://rosalind.info/problems/grph/
'''
from scripts import ReadFASTA
# Data is in FASTA form
dna_list = ReadFASTA('data/rosalind_grph.txt')
overlaps = []
for i in range(len(dna_list)):
for j in filter(lambda j: j!=i, range(len(dna_list))):
if dna_list[i][1][-3:] == dna_list[j][1][0:3]:
overlaps.append(dna_list[i][0]+' '+dna_list[j][0])
# Just for fun, the following list comprehension does the same thing in one line!
# overlaps2 = [dna_list[i][0]+' '+dna_list[j][0] for i in range(len(dna_list)) for j in range(len(dna_list)) if i!=j if dna_list[i][1][-3:] == dna_list[j][1][0:3]]
# Print and save the answer.
print '\n'.join(overlaps)
with open('output/012_GRPH.txt', 'w') as output_data:
output_data.write('\n'.join(overlaps))