第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

生信編程實戰(zhàn)第9題(python)

標(biāo)簽:
Python


webp

image.png


这个题目不难,但是我想说明的是
大的数据集和小的数据集的脚本很多时候是不一样的

比如这道题,如果使用的是小的数据集

>chr1
ATCGTCGaaAATGAANccNNttGTA
AGGTCTNAAccAAttGggG
>chr2
ATCGAATGATCGANNNGccTA
AGGTCTNAAAAGG
>chr3
ATCGTCGANNNGTAATggGA
AGGTCTNAAAAGG
>chr4
ATCGTCaaaGANNAATGANGgggTA

我可以用构建字典的方式,将想要查找的染色体和所有该染色体所有碱基的坐标以及对应碱基构建字典

import sys
args=sys.argv
filename=args[1]import collections
chr_num=args[2]
base_num=args[3]
aDict=collections.OrderedDict()
num=0with open(filename) as fh:
  chrome=">"+chr_num  for line in fh:
     line=line.strip()     if line == chrome :
          aDict[chrome]=collections.OrderedDict()
          num=1
          continue


     if num:        if line.startswith(">"):           break
        for i in line:
           aDict[chrome][num]=i
           num+=1for k,v in aDict[chrome].items():    if k == int(base_num):
      print(aDict[chrome][k])

这样,如果想得到chr2的坐标为8,9,10的碱基

python3 chr_base.py test.fa chr2 8Gpython3 chr_base.py test.fa chr2 9Apython3 chr_base.py test.fa chr2 10T

但是,如果对于hg38这种大的数据集,这种方法显然是不合适的
构建字典的过程会消耗大量的内存

所以尽量避免使用字典

import sys
args=sys.argv
filename=args[1]import collections
chr_num=args[2]
base_num=args[3]
up_stream=int(base_num)-1down_stream=int(base_num)+1num=0stop=0with open(filename) as fh:
  chrome=">"+chr_num  for line in fh:
     line=line.strip()     if line == chrome :
          num=1
          continue
     if num:        if line.startswith(">"):           break
        for i in line:           if num == up_stream:
              print(i)
              stop=stop+1
           if num == int(base_num):
              print(i)
              stop=stop+1
           if num == down_stream:
              print(i)
              stop=stop+1
           num+=1
     if stop == 3:         break

这里需要注意的是输入的坐标位置一定要转成int
还有就是,我设置stop这个值是为了提高速度,也就是得到了结果后,后面的就不要遍历了。

time python3 chr_base_bigdata.py hg38.fa chr5 8397384GACreal    0m21.503suser    0m21.008ssys 0m0.488s

如果不加stop

import sys
args=sys.argv
filename=args[1]import collections
chr_num=args[2]
base_num=args[3]
up_stream=int(base_num)-1down_stream=int(base_num)+1num=0#stop=0with open(filename) as fh:
  chrome=">"+chr_num  for line in fh:
     line=line.strip()     if line == chrome :
          num=1
          continue
     if num:        if line.startswith(">"):           break
        for i in line:           if num == up_stream:
              print(i)#              stop=stop+1
           if num == int(base_num):
              print(i)#              stop=stop+1          
           if num == down_stream:
              print(i)#              stop=stop+1  
           num+=1#     if stop == 3:#         break
time python3 chr_base_bigdata.py hg38.fa chr5 8397384GACreal    1m47.082suser    1m46.152ssys 0m0.692s

很明显,一个21s,另外一个1min46s



作者:天秤座的机器狗
链接:https://www.jianshu.com/p/e88190b1e1ed


點擊查看更多內(nèi)容
1人點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學(xué)

大額優(yōu)惠券免費領(lǐng)

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消