-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverlap_graphs.py
More file actions
67 lines (55 loc) · 1.66 KB
/
overlap_graphs.py
File metadata and controls
67 lines (55 loc) · 1.66 KB
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
##############################################
##############################################
# Example data:
# Input: FASTA file
# >Rosalind_0498
# AAATAAA
# >Rosalind_2391
# AAATTTT
# >Rosalind_2323
# TTTTCCC
# >Rosalind_0442
# AAATCCC
# >Rosalind_5013
# GGGTGGG
# Output:
# Rosalind_0498 Rosalind_2391
# Rosalind_0498 Rosalind_0442
# Rosalind_2391 Rosalind_2323
##############################################
##############################################
import sys
from Bio import SeqIO
import os
import linecache
import math
n_seqs = 0
with open(sys.argv[1], 'rU') as file:
for record in SeqIO.parse(file, 'fasta'):
with open('temp_seq', 'a') as file_seq, open('temp_rec', 'a') as file_id:
seq = str(record.seq)
file_seq.write(seq + '\n')
n_seqs = n_seqs + 1
n_seqs2 = n_seqs
rec = str(record.id)
file_id.write(rec + '\n')
n_seqs2_external = n_seqs
loop_counter = 0
line_number_ref = 0
with open(sys.argv[1], 'rU') as file, open('temp_seq', 'r') as file_seq, open('temp_rec', 'r') as file_id:
ids = file_id.readlines()
while n_seqs > 0:
line_number_ref = line_number_ref + 1
ref = linecache.getline('temp_seq', line_number_ref).strip()
length_ref = len(ref)
line_number_qu = 0
n_seqs2_internal = n_seqs2_external
while line_number_qu < n_seqs2_internal:
loop_counter = loop_counter + 1
line_number_qu = line_number_qu + 1
qu = linecache.getline('temp_seq', line_number_qu).strip()
if ref != qu and ref[length_ref-3:length_ref] == qu[0:3]:
print ids[line_number_ref - 1].strip() + ' ' + ids[line_number_qu - 1].strip()
n_seqs = n_seqs - 1
bashCommand = 'rm -f temp_seq && rm -f temp_rec'
os.system(bashCommand)