运行此行代码[print(s) for s in lseqs]出现SyntaxError: invalid syntax
def create_matrix_zeros(nrows,ncols):
res = []
for i in range(0,nrows):
res.append([0]*ncols)
return res
def print_matrix(mat):
for i in range(0,len(mat)):
print(mat[i])
class MyMotifs:
def __init__(self,seqs=[],pwm=[],alphabet=None):
if seqs:
self.size = len(seqs[0])
self.seqs = seqs
self.alphabet = seqs[0].alphabet()
self.do_counts()
self.create_pwm()
else:
self.pwm = pwm
self.size = len(pwm[0])
self.alphabet = alphabet
def __len__(self):
return self.size
def do_counts(self):
# noinspection PyAttributeOutsideInit
self.counts = create_matrix_zeros(len(self.alphabet),self.size)
for s in self.seqs:
for i in range(self.size):
lin = self.alphabet.index(s[i])
self.counts[lin][i] += 1
def create_pwm(self):
if self.counts is None:
self.do_counts()
self.pwm = create_matrix_zeros(len(self.alphabet),self.size)
for i in range(len(self.alphabet)):
for j in range(self.size):
# noinspection PyTypeChecker
self.pwm[i][j] = float(self.counts[i][j]) / len(self.seqs)
def consensus(self):
res = ""
for j in range(self.size):
maxcol = self.counts[0][j]
maxcoli = 0
for i in range(1,len(self.alphabet)):
if self.counts[i][j]>maxcol:
maxcol = self.counts[i][j]
maxcoli = i
res += self.alphabet[maxcoli]
return res
def masked_consensus(self):
res = ""
for j in range(self.size):
maxcol = self.counts[0][j]
maxcoli = 0
for i in range(1,len(self.alphabet)):
if self.counts[i][j]>maxcol:
maxcol = self.counts[i][j]
maxcoli = i
if maxcol>len(self.seqs) / 2:
res += self.alphabet[maxcoli]
else:
res += "-"
return res
def probability_sequence(self,seq):
res = 1.0
for i in range(self.size):
lin = self.alphabet.index(seq[i])
res *= self.pwm[lin][i]
return res
def probability_all_positions(self,seq):
res = []
for k in range(len(seq)-self.size+1):
res.append(self.probability_sequence(seq))
return res
def most_probable_sequence(self,seq):
maximum = -1.0
maxind = -1
for k in range(len(seq)-self.size):
p = self.probability_sequence(seq[k:k+self.size])
if p > maximum:
maximum = p
maxind = k
return maxind
def create_motif(self,seqs):
from Bio.Seq import Seq
l = []
for s in seqs:
ind = self.most_probable_sequence(s.seq)
subseq = Seq(s[ind:(ind+self.size)],s.get_seq_biotype() )
l.append(subseq)
return MyMotifs(l)
def test():
from Bio.Seq import Seq
seq1 = Seq("AAAGTT")
seq2 = Seq("CACGTG")
seq3 = Seq("TTGGGT")
seq4 = Seq("GACCGT")
seq5 = Seq("AACCAT")
seq6 = Seq("AACCCT")
seq7 = Seq("AAACCT")
seq8 = Seq("GAACCT")
lseqs = [seq1,seq2,seq3,seq4,seq5,seq6,seq7,seq8]
motifs = MyMotifs(lseqs)
print ("Counts matrix")
print_matrix(motifs.counts)
print ("PWM")
print_matrix(motifs.pwm)
print ("Sequence alphabet")
print(motifs.alphabet)
[print(s) for s in lseqs]
print ("Consensus sequence")
print(motifs.consensus())
print ("Masked Consensus sequence")
print(motifs.masked_consensus())
print(motifs.probability_sequence("AAACCT"))
print(motifs.probability_sequence("ATACAG"))
print(motifs.most_probable_sequence("CTATAAACCTTACATC"))
line 123
[print(s) for s in lseqs]
^
SyntaxError: invalid syntax,请问此行代码该如何修改才能正常运行