How can I find the keys from a dictionary in a DNA sequence?
2
0
Entering edit mode
10.3 years ago

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

DNA python biopython dictionary • 3.4k views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode
10.3 years ago
Cytosine ▴ 460

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()
ADD COMMENT
0
Entering edit mode

It's not necessary to get all the keys and values, only those found in the sequence.

ADD REPLY
0
Entering edit mode
10.3 years ago

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.

ADD COMMENT

Login before adding your answer.

Traffic: 2602 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6