【发布时间】:2014-03-23 14:31:45
【问题描述】:
好的,我已经编写这个脚本有一段时间了,但它并没有按照应有的方式工作。 它应该像限制酶一样工作,用户提供一种酶,程序会检查限制位点是否存在于创建的字典中。如果是这样,它应该计算碎片的重量。现在,如果没有限制站点,它会返回一个正确的空列表,但是如果存在限制站点,则程序不起作用。没有错误,但是当我运行脚本时,它什么也没做。有没有人可以帮我解决这个问题??
注意:有些函数是故意留下的,比如权重函数。
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()
【问题讨论】:
-
您可能需要在这里帮助我们。我们不知道您文件的格式。您是否测试过您的 getSequences 函数?您的代码似乎有点奇怪。它会返回您所期望的吗?你能发布一个示例字典吗?将代码分解成小块并系统地跟踪错误通常很有用。
标签: python python-3.x