我正在运行的函数是以下
def ambiguous_to_unambiguous(seq):
ambig = {'R': ['A', 'G'], 'V':['A', 'C', 'G'], 'W':['A', 'T'], 'S':['C', 'G'], 'Y':['C', 'T'], 'K':['G', 'T'], 'V':['A', 'C', 'G'], 'H':['A', 'C', 'T'],
'D':['A', 'G', 'T'], 'B':['C', 'G', 'T'], 'N':['G', 'A', 'T', 'C']} #from IU pack
groups = itertools.groupby(seq, lambda char:char not in ambig)
splits = []
for b,group in groups:
if b:
splits.extend([[g] for g in group])
else:
for nuc in group:
splits.append(ambig[nuc])
possible_seqs = [''.join(p) for p in itertools.product(*splits)]
print(possible_seqs)
我需要这个ambique_to_unambique((函数的输出是可迭代的。这在当前是不可能的,因为输出是NoneType。这是我想在中使用ambique_to_unambique((函数的代码块
def seq_ID_and_weight(file_name):
with open (file_name) as file:
ID_weight = {} #create an empty dictionary
for seq in file:
weight_min = [10000]
weight_max = [0]
if ambiguous_to_unambiguous(seq) != seq:
possible_sequences = ambiguous_to_unambiguous(seq)
for possib in possible_sequences:
if possib.molecular_weight < weight_min: weight_min = possib.molecular_weight
elif possib.molecular_weight > weight_max: weight_max = possib.molecular_weight
ID_weight.append({seq.id: [weight_min, weight_max]})
else:
ID_weight.append({seq.id: seq.molecular_weight})
print(ID_weight)
但这给了我以下错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-19-588e4dcc12bb> in <module>
----> 1 seq_ID_and_weight('short.fasta')
<ipython-input-18-ad41a9ecd674> in seq_ID_and_weight(file_name)
7 if ambiguous_to_unambiguous(seq) != seq:
8 possible_sequences = ambiguous_to_unambiguous(seq)
----> 9 for possib in possible_sequences:
10 if possib.molecular_weight < weight_min: weight_min = possib.molecular_weight
11 elif possib.molecular_weight > weight_max: weight_max = possib.molecular_weight
TypeError: 'NoneType' object is not iterable
我用错这个函数了吗?我尝试过map((函数和使用*运算符打印,但键入的内容保持不变。
当函数没有return
语句时,它"返回";没有一个