This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How can I find the keys from a dictionary in a DNA sequence?

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

2 answers

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.