Python 3.x 突变DNA生成器中没有打印语句

Python 3.x 突变DNA生成器中没有打印语句,python-3.x,bioinformatics,dna-sequence,Python 3.x,Bioinformatics,Dna Sequence,所以我有一个代码,它是一个突变dna发生器——更具体地说,它产生100条链,任何碱基的点突变频率为0.066%,来源于我在代码中指定的原始链。然而,我的问题是打印语句。我没有得到输出,我也不知道为什么。这是我的密码: import random class DNA_mutant_generator: def __init__ (self, dna): self.dna = dna self.bases = bases def mutate(se

所以我有一个代码,它是一个突变dna发生器——更具体地说,它产生100条链,任何碱基的点突变频率为0.066%,来源于我在代码中指定的原始链。然而,我的问题是打印语句。我没有得到输出,我也不知道为什么。这是我的密码:

import random

class DNA_mutant_generator:
    def __init__ (self, dna):
        self.dna = dna
        self.bases = bases

    def mutate(self, mutation_rate=0.0066): #add a specification of the mutation rate of 0.066%
        result = []
        mutations = []
        for base in self.dna:
            if random.random() < mutation_rate: #random.random() returns the next random floating point number in range [0.0,1.0)
                new_base = bases[bases.index(base) - random.randint(1, 3)] # subtracts the position of a certain base from a random integer within the range of 1 to 3 in the bases list. This creates the newly mutated base.
                result.append(new_base)#append that new base to the result list
                mutations.append((base, new_base))#appends the original base, as well as the new mutated base to a list of tuples
            else:
                result.append(base)# 
        return "".join(result), mutations # returns mutated strands, as well as mutations

       for result_string, mutations in results:
            if mutations: # skip writing out unmutated strings
                print(result_string, mutations)    

bases = "ACTG" #specifies the bases in the DNA strand
orig_dna = "GGCTCTCCAACAGgtaagcactgaagggtagaaggcatcgtctgtctcagacatgtctggcaccatccgctaagacattaccacgtgggtctcgagtatagctaacacccttctgtttggcagCTTACAGGAGCGAACGTTGG"
dna = orig_dna.upper()
dna_mutants = DNA_mutant_generator(dna)
dna_mutants.mutate()

在打印语句之前返回以下行:

return "".join(result), mutations # returns mutated strands, as well as mutations
如果要在此行之后打印信息,请删除
return
语句,将表达式指定给变量,然后在函数末尾返回该变量

    return_value = "".join(result), mutations # returns mutated strands, as well as mutations

   for result_string in result:
        if mutations: # skip writing out unmutated strings
            print(result_string, mutations)  
    return return_value

Edit:你的新问题是因为你创建了一个递归函数,它一次又一次地调用自己。每次函数调用自身时,它都需要堆栈上更多的空间,而且您多次调用它时堆栈“溢出”

谢谢。我做了一些更改,但出现了一个错误。我已经在我的问题中提供了编辑。如果你能在这方面帮助我,我将不胜感激。更新了我的帖子-这是在mutate函数中反复调用mutate()的结果。我认为这不是你想要做的。谢谢你的帮助,尽管我收到了相同的错误消息。如果你不在
mutate
内调用
mutate
,你就不会收到错误消息。我更新了我的编辑,向你展示了我所做的事情-我将函数外的“results”移动到我不在mutate内调用mutate。但是,我收到另一条错误消息。
return "".join(result), mutations # returns mutated strands, as well as mutations
    return_value = "".join(result), mutations # returns mutated strands, as well as mutations

   for result_string in result:
        if mutations: # skip writing out unmutated strings
            print(result_string, mutations)  
    return return_value