程序根本不运行,没有错误,

2024-09-28 17:01:09 发布

您现在位置:Python中文网/ 问答频道 /正文

好吧,我写这个剧本已经有一段时间了,但它不起作用。 它应该像限制酶一样工作,用户输入一种酶,程序检查创建的字典中是否存在限制性位点。如果是这样,它应该计算碎片的重量。现在,如果没有限制站点,则返回一个正确的空列表,但是如果存在限制站点,则程序无法运行。没有错误,但当我运行脚本时,它什么也不做。有人能帮我解决这个问题吗??在

注意:有些函数是故意保留的,比如权重函数。在

import sys

enzyme = input ("Give me some enzymes to work with, please ") 

enzymesDict = {"EcorI":("GAATTC",1),"BamHI":("GGATCC",1),"EcoRII":("CCWGG",0),"HindIII":("AAGCTT",1),
            "TaqI":("TCGA",1),"NotI":("GCGGCCGC",2),"HinfI":("GANTCA",1),"Sau3A":("GATC",0),
            "HaeIII":("GGCC",2),"EcoRV":("GATATC",3),"PstI":("CTGCAG",4),"XbaI":("TCTAGA",1),
            "MboI":("GATC",0),"mst2":("CCTNAGG",2)}

def getSequences ():
    '''Gets sequences of command-line with as output a dictionary'''

    sequenceDict = {}

    #opens given file as string and reads it's content
    inputFile = open("sequence.txt")
    outputSequence = inputFile.read()
    outputSequence = outputSequence.split('\n')

    for lines in outputSequence:
        if len(lines) % 2  == 0 :
            header = lines
        else:
            if len(lines) % 2 == 1 :
                outputSequence = lines

        #adds header and outputSequence to the empty dict sequenceDict      
            sequenceDict[header] = [outputSequence]
    inputFile.close()   

    return sequenceDict

def digestFragmentWithOneEnzym (sequenceDict):
    '''Function which will cut fragment of DNA with help of enzymes
     Input: Dictionary with sequence and header. Output:'''

    #using the global dictionary of enzymes to cut a fragment of DNA
    #the output of this function should be a list with cutted fragments of DNA

    fragmentList = []
    outputSequence = getSequences()
    #checks if given enzym is in global enzymesDict if true then it continues

    #~ for sequence in sequenceDict:
        #~ header = sequenceDict[sequence]


    if enzyme in enzymesDict:
        offset = enzymesDict[enzyme][1]
        enzymeSeq = enzymesDict[enzyme][0]      
        item = 0
        outputSequence = sequenceDict['>Sequence number 1'][0]

        while item != -1:
            item = outputSequence.find(enzymeSeq)
            if item == -1:
                continue

            end = item + offset
            fragment = outputSequence[0:end]
            sequence = outputSequence[end: ]


            fragmentList.append(fragment)


    return fragmentList #returns a list of cutted fragments


def main ():
    '''Main function which will process the given data'''

    #def performRestriction(path to sequencefile, enzymelist)

    sequenceDict = getSequences()
    outputSequence = getSequences()
    fragmentList = digestFragmentWithOneEnzym(sequenceDict) 
    fragWeight = getMoleculairWeight(fragmentList)

    #prints input sequence plus cutted fragments and weights in a list
    print (outputSequence)
    print("Cutted fragments are:",fragmentList , "\n \t \t Their weights:" , fragWeight)

if __name__ =="__main__":
    main()

Tags: oftoinifdefwithitemheader