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

时间:2014-03-23 14:31:46

标签: python python-3.x

好的,我已经在这个剧本上工作了一段时间,但它并没有发挥作用。 它应该像限制酶一样工作,用户提供酶,程序检查创建的字典中是否存在限制性位点。如果是这样,它应该计算碎片的重量。现在的情况是,如果没有限制站点存在,它返回一个正确的空列表,但是如果存在限制站点,则程序不起作用。没有错误但是当我运行脚本时它没有任何错误。有没有人能帮我解决这个问题?

注意:有些功能是有目的的,就像重量功能一样。

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()

1 个答案:

答案 0 :(得分:0)

如果您在此处报告的代码

if name == "main": main()

插入到您尝试运行的脚本中,您应该按照以下步骤进行修改:

if __name__ == '__main__':
    main()