《python语言程序设计》第8章第12题生物信息:找出基因,生物学家使用字母A C T和G构成字符2串建模一个基因组(下)

这个版本中div_text函数已经可以很好的划分字符串了
但是我发现了一个问题.它间隔字符效果如下


genome_text = 'TTATGTTTTAAGGATGGGGCGTTAGTT'
len_num_out = len(genome_text)


def div_text(start_num, end_num, text_word):
    text_i_save = ""
    for i_t in range(start_num, end_num):
        text_i_save += text_word[i_t]
    return text_i_save

请添加图片描述
之前的间隔的取数.在这里得到了修正.其实就是将for循环的步幅改回到1

len_num = len(genome_text)
for i in range(0, len_num):
    if i + 2 < len_num:
        print(div_text(i, i + 3, genome_text))
        print('i is', i, 'i+3 is', i + 3)

请添加图片描述


genome_text = 'TTATGTTTTAAGGATGGGGCGTTAGTT'
len_num_out = len(genome_text)


def div_text(start_num, end_num, text_word):
    text_i_save = ""
    for i_t in range(start_num, end_num):
        text_i_save += text_word[i_t]
    return text_i_save


def cut_word_start(judge_word, text_word):
    len_num = len(text_word)
    for i in range(0, len_num):
        if i + 2 < len_num:
            if div_text(i, i + 3, text_word) == judge_word:
                return text_word[i + 3:]


def cut_word_end(judge_word, text_word):
    len_num = len(text_word)
    for i in range(0, len_num):
        if i + 2 < len_num:
            if div_text(i, i + 3, text_word) == judge_word:
                print(text_word[:i])
                # print(i)


def main():
    a = cut_word_start("ATG", genome_text)
    cut_word_end("TAA",a)


main()

请添加图片描述

第一条里我已经成功提取了TTT这个序列但是

‘TTATGTTTTAAGGATGGGGCGTTAGTT’
还存在GGGCGT

另外 当我取的了TTT后,如何让计算机继续往后去寻找
规则也写的很明白
ATG之后TAG或TAA或TGA之前,这样一个区间

抱歉各位兄弟我感觉这道题我现在的能力有限,不纠结了跳过去.等第3刷的时候解决吧.


genome_text = 'TTATGTTTTAAGGATGGGGCGTTAGTT'
len_num_out = len(genome_text)


def div_text(start_num, end_num, text_word):
    text_i_save = ""
    for i_t in range(start_num, end_num):
        text_i_save += text_word[i_t]
    return text_i_save


def cut_word_start(judge_word, text_word):
    len_num = len(text_word)
    for i in range(0, len_num):
        if i + 2 < len_num:
            if div_text(i, i + 3, text_word) == judge_word:
                return text_word[i + 3:]


def cut_word_end(judge_word1, judge_word2, judge_word3, text_word):
    len_num = len(text_word)
    for i in range(0, len_num):
        if i + 2 < len_num:
            run_code = div_text(i, i + 3, text_word)
            if run_code == judge_word1 or run_code == judge_word2 or run_code == judge_word3:
                print(text_word[:i])


# 这个从他们之前取值的想法有点烧脑了.先放弃了
def between_code(judge_start, judge_end1, judge_end2, judge_end3, text_int):
    a = cut_word_start(judge_start, text_int)
    cut_word_end(judge_end1, judge_end2, judge_end3, a)
    


def main():
    a = cut_word_start("ATG", genome_text)
    cut_word_end("TAG", "TAA", "TGA", a)

main()



请添加图片描述

可能彼岸就在眼前,但是我累了.等下次吧

  • 7
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

电饭叔

谢谢各位兄弟们的关注,谢谢破费

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值