生信小白__君君

生物信息学分析__学习笔记&日常

Coursera_ Python for Genomic Data 笔记001

range( ):

If you do need to iterate over a sequence of numbers, the built-in function range( ) comes in handy. It generates arithmetic progressions(等差数列)

range(1,5) -> [1,2,3,4]     dosen't including 5

range(1,5,2) -> [1,3]        step by 2

range(5) -> [0,1,2,3,4]      from 0 to 5 and doesn't including 5

array[ ]:

[1,2,3,4,5]

0, 1, 2, 3, 4           "No." start from 0

-5, -4, -3, -2 ,-1    "reverse No." start from 1

array[0:]

array[1:]

array[:-1]

array[3,-3]


x = [:]       make a new arry

array[::2]  step by 2 start from the first element(No.0)

array[2::]  start from the third element(No.2) step by 2


x.reverse( )

array[::-1]  step by 1 start from the last element(No.-1)

array[::-2]  step by 2 start from the last element(No.-1)


来自coursera python 课程里面的def:

def has_stop_codon(dna):

"this function check if given dna seq has in frame stop codons."

    stop_codon_found=False

    stop_codons=['tga','tag','taa']

    for i in range(0,len(dna),3):

     # start from the first element(No.0) to the last element, step by 3

        codon=dna[i:i+3].lower()

        if codon in stop_codons:

            stop_codon_found=True

            break

    return stop_codon_found


评论