-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1G.py
123 lines (107 loc) · 3.14 KB
/
1G.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
##Frequent Words with Mismatches Problem
#We defined a mismatch in "Approximate Pattern Matching Problem". We now generalize "Frequent Words Problem" to incorporate mismatches as well.
#Frequent Words with Mismatches Problem
#Find the most frequent k-mers with mismatches in a string.
#Given: A string Text as well as integers k and d.
#Return: All most frequent k-mers with up to d mismatches in Text.
#Note: The algorithm for solving the Frequent Words with Mismatches Problem becomes rather slow as k and d increase. In practice, your solution should work for k <= 12 and d <= 3.
#Sample Dataset
'''
ACGTTGCATGTCGCATGATGCATGAGAGCT
4 1
'''
#Sample Output
'''
GATG ATGC ATGT
'''
##########################################################################################
import os, sys, time
# start timing
startTime = time.time()
print 'Start'
path = os.path.join('E:\\','gential','Documents','Archivio_Coursesera','Coursera_BioinformaticsAlgorithms(Part1)','Rosalind','Bioinformatics_TextbookTrack')
In_filename = 'input.txt' #'rosalind_1g_1_dataset.txt'
fText_in = os.path.join(path,In_filename)
In_filetext = open(fText_in,'r')
lines=In_filetext.readlines()
In_filetext.close()
Out_filename = 'output.txt' #'rosalind_1g_1_output.txt'
fText_out = os.path.join(path,Out_filename)
Out_filetext = open(fText_out,'w')
values = []
for line in lines:
values += line.split()
DNA_seq = values[0]
k = int(values[1]) #4#
d = int(values[2]) #1#
#DNA_seq = 'ACGTTGCATGTCGCATGATGCATGAGAGCT'
print DNA_seq
print k
print d
DNA_lenght = len(DNA_seq)
#print DNA_lenght
Pattern_list = []
k_mers = k - 1
iter = -1
ciclo = -1
for N_1 in range(DNA_lenght):
ciclo += 1
iter += 1
k_mers += 1
sequence_k = (DNA_seq)[iter:k_mers]
if len(sequence_k) == k:
a = -1
b = k - 1
N_sequence = 0
for N_2 in range(DNA_lenght):
a += 1
b += 1
sequence = (DNA_seq)[a:b]
Mismatch = 0
number = -1
if len(sequence) == len(sequence_k):
#print sequence_k, ' = ', sequence
#print len(sequence), ' = ', len(sequence_k)
for B in sequence_k:
number += 1
if sequence_k[number] == sequence[number]:
Mismatch += 0
else:
Mismatch += 1
#print sequence[number], sequence_k[number]
#print 'Mismatch: ', Mismatch
if Mismatch <= d:
#print 'Pattern: ', sequence_k
#if sequence_k not in Pattern_list:
Pattern_list += [sequence_k]
for Seq in Pattern_list:
Out_filetext.write(Seq+'\n')
Out_filetext.close()
print '\nThe number of Nucleotides is ', ciclo+1
print 'The DNA_seq is composed by a length of ',len(DNA_seq),' nucleotides'
# show elapsed time
endTime = time.time()
print 'Entire DNA_seq elapsed time: ', endTime - startTime, ' seconds'
print 'End'
'''
NN = 'ACGT'
loop = 0
lista=[]
Sequence = ''
for N1 in NN:
Sequence += N1
#print Sequence
for N2 in NN:
Sequence += N2
#print Sequence
for N3 in NN:
Sequence += N3
for N4 in NN:
name1 = Sequence+'A'
name2 = Sequence+'C'
name3 = Sequence+'G'
name4 = Sequence+'T'
lista = name1 +' '+ name2 +' '+ name3 +' '+ name4
print lista
stop
'''