python - User input to check a DNA sequence for restriction sites with BioPython -
i wish write script accepts user inputted restriction enzyme name (therefore string) , parses given dna sequence (also string) instances of restriction enzyme sequence. input access library of restriction enzymes contained in bio.restriction module. simple example:
from bio.restriction import * sequence=('acggctatcgataactg...') enzyme=input('enter name of restriction enzyme: ') enzymesite=bio.restriction.enzyme.site enzymesite in sequence #true or false
the problem, of course, variable enzyme string object, not restrictiontype object required access class.
type(enzyme) <class 'str'> type(bio.restriction.ecori) restrictiontype
i tried using importlib package. enzymes appear classes instead of modules, however, importlib can't help.
i=importlib.import_module('bio.restriction',fromlist=['']) dir(i) #list of bio.restriction contents i=importlib.import_module('bio.restriction.ecori',fromlist=['']) traceback (most recent call last): file "<pyshell#391>", line 1, in <module> i=__import__('bio.restriction.ecori',fromlist=['']) importerror: no module named 'bio.restriction.ecori'
i'm new python, didn't reading restriction source files.
there obvious limitations being forced access restriction enzyme in command line. 1 solution problem have 2 python scripts 1 prompts user enzyme , subsequently replaces code , imports output script. solution create dictionary of possible restriction enzymes , sites. both of these solutions hideous. ideal solution me convert user inputted string proper restrictiontype object used access sites. reading, , appreciate problem.
i've never used biopython before, i'm interested in bioinformatics, looked bit. can't guarantee optimal way this, seeing it's rather strange, seems work.
i made restrictionbatch
, added enzyme batch string, before using batch.get()
retrieve restrictiontype
object, using same string query. i've understood enzyme names case sensitive, used ecori
test. worked example:
from bio.restriction.restriction import restrictionbatch sequence=('acggcgaattctatcgataactg...') # read enzyme name input. enzyme_name = input("enter enzyme name:\n") # e.g ecori print (type(enzyme_name)) # <type 'str'> # restrictiontype name batch = restrictionbatch() batch.add(enzyme_name) enzyme = batch.get(enzyme_name) print (type(enzyme)) # restrictiontype print (enzyme.site in sequence) # true
is along lines of you're looking for?
Comments
Post a Comment