It's not necessary to get all the keys and values, only those found in the sequence.
• 0 views
•
link
I want to identify the keys from a dictionary (strings) in a DNA sequence(string or fasta).
How can I find the keys in the sequence and get? I've tried something like this:
def identification(ren, S):
patternkeys = []
for key in ren:
if S in key:
patternkeys.append(key)
return patternKeys
patterns = []
patterns = identification(ren, S)
print patterns
#..............
ren is the dictionary and S the sequence
I need to get keys and values FOUND in the sequence.
Thanks
Not really sure what you want to accomplish with this code of yours... An example input would be helpful.
But here's how you can get keys and values separately from a dictionary:
keys, values = dict.keys(), dict.values()
It's not necessary to get all the keys and values, only those found in the sequence.
Not sure if this is what you want, but this should do the trick:
patternkeys = [x for x in ren.keys() if ren[x] in S]
In any case, for this type of programming questions you should better ask in stackoverflow.
Log in to answer this question.
not terribly efficient, but you could modify the line
"if S in key" to use a regular expression that identifies key in S. See e.g. http://stackoverflow.com/questions/7345252/python-regex-match-words-in-string-and-get-count