Okay I've been working on this script for a while now but it doesn't work how it should be. It should work like a restriction enzyme, a user gives in an enzyme and the program checks if restriction sites are present in the created dictionary. If so it should calculate the weight of the fragments. Now the case if there's no restriction site present it returns an empty list which is correct, BUT if there are restriction sites presents the program doesn't work. There are no errors but when I run the script it does littary nothing. Does anyone has something for me to fix this ??
note: some functions are left away at purpose, like the weight function.
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()