-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeData.py
119 lines (97 loc) · 3.17 KB
/
makeData.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
import random
import cPickle as pickle
from numpy import concatenate, ones, array, shape, size, zeros, exp, arange
from numpy import concatenate,ones,array,shape,size,zeros,exp
import numpy as np
import copy
import math
import pdb
dna = ['A', 'C', 'G', 'T']
def simulate_sequence(length):
sequence = ''
for i in range(length):
sequence += random.choice(dna) #zufaellig Element aus dna anhaengen
return sequence
def mutate_motif(motiv,probmut):
dna = ['A', 'C', 'G', 'T']
mutmot = ""
for i in range(len(motiv)):
rnd = random.random()
if (rnd <= probmut):
dnashort =['A', 'C', 'G', 'T']
dnashort.pop(dnashort.index(motiv[i]))
mutmot += random.choice(dnashort)
else:
mutmot +=motiv[i]
return mutmot
def gensequences2(tally,positives,sequenceno,prob,motif,mu):
sequences = []
ml = len(motif)
for i in range(sequenceno):
aa = simulate_sequence(tally)
if i < positives:
mut=mutate_motif(motif,prob)
aa = aa.replace(aa[mu:mu + ml], mut)
sequences.append(aa)
return sequences
def gensequences(tally,positives,sequenceno,prob,motif,mu):
sequences = []
y=np.ones(sequenceno)*(-1)
ml = len(motif)
for i in range(sequenceno):
aa = simulate_sequence(tally)
if i < positives:
y[i]=1
mut=mutate_motif(motif,prob)
aa = aa.replace(aa[mu:mu + ml], mut)
sequences.append(aa)
return sequences,y
def non_polymorphic_loci(x):
counter = np.zeros((4,len(x[0])))
for i in range(len(x)):
for j in range(len(x[0])):
if x[i][j] == 'A':
counter[0,j]=counter[0,j]+1
elif x[i][j] == 'C':
counter[1,j]=counter[1,j]+1
elif x[i][j] == 'G':
counter[2,j]=counter[2,j]+1
else:
counter[3,j]=counter[3,j]+1
counter=counter/len(x)
dna = ['A', 'C', 'G', 'T']
for i in range(len(counter[0])):
for j in range(4):
if counter[j,i] == 1.0:
print "nucleotid " , dna[j]," position", str(i)
return counter
def extractRealData(datapath,savepath,lines):
#path = "/home/mvidovic/POIMall/data/real/"
#filename = "human_acceptor_splice_data.txt"
data =file(datapath).readlines()[:lines]
labels = []
x = []
cn=0
for i in range(len(data)):
labels.append(int(data[i][0:2]))
x.append(data[i][3:-1])
pdb.set_trace()
if int(data[i][0:2])==1:
cn=cn+1
print "numper of positive labels: " , cn
if savepath !="":
fobj = open(savepath,'wb')
pickle.dump([x,labels],fobj)
fobj.close()
return x,labels
#tally = 30 #length of training sequences
#sequenceno = 50 #number of training sequences
#positives = 12 #positives training sequences
#motiv = "CCTATA"
#mu = 10
#poim_degree = 3
#idxprob=np.arange(0.0,1.01,1.1)
#dna = ['A', 'C', 'G', 'T']
def compute_data(seq_length,seq_no,pos_no,motifs,mu):
a=1
#fm_train_dna = gensequences(tally,positives,sequenceno,0,motiv,mu)