Find Repeats In A Sequence
2
3
Entering edit mode
12.8 years ago
Wang ▴ 30

I want to find every repeats codon sequence in DNA sequences using Python so, if i input the sequence, find repeat type and time. absolutely USING PYTHON

Thanx to guys!!!

sequence repeats python homework • 13k views
ADD COMMENT
4
Entering edit mode

This looks like a homework assignment, is it? I think this has something to do with regular expression, and Perl handles it well, too.

ADD REPLY
0
Entering edit mode

You don't need Perl to use regular expressions. They are two very different languages.

ADD REPLY
0
Entering edit mode

Do you mean SSR?

ADD REPLY
9
Entering edit mode
12.8 years ago
Fucitol ▴ 140

It's very easy to do in python using the count function:

from itertools import product    
[sequence.count(''.join(codon)) for codon in product('ATCG', repeat=3)]

Or get the results in a dictionary (you can figure out how to get the max etc yourself):

dict(("".join(codon), sequence.upper().count(''.join(codon))) for codon in product("ATCG", repeat=3))

(edited after brentp's correct comment below)

ADD COMMENT
2
Entering edit mode

+1. Minor nitpick, to get the results in a dictionary, you'd use: dict(("".join(codon), seq.count(''.join(codon))) for codon in itertools.product("ATCG", repeat=3))

otherwise, you get a list of dictionaries of length 1.

ADD REPLY
0
Entering edit mode

Nice solution; with the caveat that it should be 'atcg' to work for the example sequence given in the question.

ADD REPLY
0
Entering edit mode

You are correct Neil, that's the risk of having a Python session already open with some sequence data loaded. For safety, you can also use: sequence.upper().count(...) which works on both lower and uppercase data.

ADD REPLY
3
Entering edit mode
12.8 years ago

Should we really accept doing homework assignments?

A simple invitation to use:

  • help(str)

would have given 'wang' all the basic tools to start this, including:

  • the count() method
  • the join() method
  • the upper() and lower() methods

And he would have learned to use the help() method and the built-in documentation which are fundamental Python tools.

Now he just has a copy-and-paste answer that has taught him nothing...

ADD COMMENT

Login before adding your answer.

Traffic: 2275 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