【Python】使用正则表达式搜索

使用re模块 在Python中使用正则表达式时,re模块内部会干两件事情: 编译正则表达式,如果正则表达式的字符串本身不合法,会报错; 用编译后的

Python练习-3

斐波那契数列 http://rosalind.info/problems/fib/ 数列的循环数为n(≤40),扩大级数为k(≤5) F~1~ = F~2~ = 1 Fn=Fn−1+Fn−2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 def fib(i,k): i = int(i) if i in

Python练习-2

查找核酸序列的子集 http://rosalind.info/problems/subs/ 1 2 3 4 5 6 7 8 9 10 11 12 with open('rosalind_subs.txt') as lines: string_1 = lines.readline().strip() string_2 = lines.readline().strip() note = [] length_2 = len(string_2) for i in range(0, len(string_1)+1): if string_1[i:i+length_2] == string_2: note.append(str(i+1)) notes = ' '.join(note) print(notes) 计算两条序列间的汉明距离 http://rosalind.info/problems/hamm/ 1 2 3 4

Python练习-1

获得一条序列的反义链 http://rosalind.info/problems/revc/ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 with open('rosalind_revc.txt') as string_dna: string_dna = string_dna.readline().strip() new_sting = [] for i in string_dna: if i == 'A': new_sting.append('T') elif i == 'C': new_sting.append('G') elif i == 'T': new_sting.append('A') elif i == 'G': new_sting.append('C') #将列表倒序