構(gòu)建ncbi——nr本地庫

網(wǎng)上方案都是用ncbi-blast+程序包的updata_blastdb.pl自動下載天揖,然而我下了兩天夺欲,一直斷···被逼無奈下,我只能用wget命令通過FTP地址去下載了

先附上幾個有用的地址:
ncbi blast database 下載方式介紹
ncbi blast database FTP地址
wget高級用法
現(xiàn)在我們正式開始····


1.庫文件列表< nrftplist >準備

import os
from ftplib import FTP 
import re
workdir='/Users/gushanshan/server/ncbi_db'
os.chdir(workdir)


ftpsite="ftp.ncbi.nlm.nih.gov/blast/db/"
linepo=ftpsite.index("/")
ftp=FTP(ftpsite[0:linepo])
ftp.login()
ftp.cwd(ftpsite[linepo+1:])
dirs=ftp.nlst()
for dir_i in dirs:
    inter_i=re.match("^nr",dir_i)
    if inter_i is not None:
        print(dir_i)
        filepo='ftp://'+ftpsite+dir_i
        os.system('echo \"'+filepo+';type=i\"'+' >> nrftplist')

ftp.close()

type=i指定binary mode:Pre-formatted databases must be downloaded using the update_blastdb.pl script or via FTP in binary mode

2 庫文件下載

如果用wget -i nrftplist下載今膊,程序會按次序一個一個下些阅,太費時間。所以我按照文件大小把nrftplist拆成了6個子文件斑唬,每個子文件總下載量差不多

wget -b -c -I nrftplist_1
wget -b -c -I nrftplist_2
wget -b -c -I nrftplist_3
wget -b -c -I nrftplist_4
wget -b -c -I nrftplist_5
wget -b -c -I nrftplist_6

-c 可持續(xù)斷點下載市埋,中途失敗可續(xù)接;
-i nrftplist對應(yīng)子文件恕刘;
-b 后臺下載缤谎。

速度似乎并沒有上去······,從中午下到了午夜 /("▔□▔)/

可以用下方程序檢查下載到哪里了

tail wget-log
tail wget-log.1
tail wget-log.2
tail wget-log.3
tail wget-log.4
tail wget-log.5

其實我覺得連寫6個wget的方式很笨雪营,但還不知道怎么能更簡潔些···還在學習中


3.文件完整性下載

因為文件太大弓千,下載時間太久,擔心中間出現(xiàn)什么差錯献起,用md5檢查下:

import os
import re
workdir='/Users/gushanshan/server/ncbi_db/nr'
os.chdir(workdir)
files=os.listdir()
for file in files:
    if re.search("gz$",file) is not None:
        print(file)
        os.system('md5sum '+file+' >> md5_file')
    elif re.search("md5$",file) is not None:
        print(file)
        os.system('cat '+file+' >> md5_md5')

太慢了洋访,我好焦灼···


如果md5_file和md5_md5結(jié)果一樣,說明文件很完整谴餐,可以繼續(xù)后續(xù)操作姻政。

4. 庫文件解壓

nohup gzip *.tar.gz -d &
nohup tar -xvf nr....tar &

5.本地庫配置——.ncbirc文件

NCBI官方文檔

  • 以分號開頭的為注釋句;
  • 可以放在當前工作路徑或用戶的home目錄岂嗓,我偏向于后者汁展;
; Start the section for BLAST configuration
[BLAST]
; Specifies the path where BLAST databases are installed
BLASTDB=/picb/evolgen/users/gushanshan/ncbi_db/nr
; Specifies the data sources to use for automatic resolution 
; for sequence identifiers 
DATA_LOADERS=blastdb 
; Specifies the BLAST database to use resolve protein sequences 
BLASTDB_PROT_DATA_LOADER=/picb/evolgen/users/gushanshan/ncbi_db/nr
; Specifies the BLAST database to use resolve nucleotide sequences 
BLASTDB_NUCL_DATA_LOADER=/picb/evolgen/users/gushanshan/ncbi_db/nt

; Windowmasker settings
[WINDOW_MASKER]
WINDOW_MASKER_PATH=/picb/evolgen/users/gushanshan/ncbi_db/windowmasker
; end of file

6.nr子庫構(gòu)建

參考文章:
https://www.bioinfo-scrounger.com/archives/207/
http://www.chenlianfu.com/?p=2691

6.1.軟件安裝及文件下載
6.1.1. TaxonKit

下載地址:https://bioinf.shenwei.me/taxonkit/download/

wget https://github.com/shenwei356/taxonkit/releases/download/v0.6.0/taxonkit_linux_amd64.tar.gz
tar -zxvf taxonkit_linux_amd64.tar.gz 
mkdir -p $HOME/bin/
cp taxonkit $HOME/bin/
6.1.2. csvtk

下載地址:https://bioinf.shenwei.me/csvtk/download/

wget https://github.com/shenwei356/csvtk/releases/download/v0.20.0/csvtk_linux_amd64.tar.gz
tar -zxvf csvtk_linux_amd64.tar.gz
cp csvtk $HOME/bin/
6.1.3. prot.accession2taxid

該文件記錄NCBI的accession與taxid的對應(yīng)關(guān)系

wget ftp://ftp.ncbi.nih.gov/pub/taxonomy/accession2taxid/prot.accession2taxid.gz
gzip -dc prot.accession2taxid.gz > prot.accession2taxid
6.1.4. taxdump

文件包含 taxonomic lineage of taxa, type strains和material的信息,以及host information
下載地址

#1.下載
wget https://ftp.ncbi.nlm.nih.gov/pub/taxonomy/new_taxdump/new_taxdump.tar.gz
wget https://ftp.ncbi.nlm.nih.gov/pub/taxonomy/new_taxdump/new_taxdump.tar.gz.md5

#2.判斷文件完整性:如果兩個結(jié)果一樣食绿,則文件完整
md5sum new_taxdump.tar.gz#7458b27039e743d8bb4fcbf71ccaf4ac  new_taxdump.tar.gz
cat new_taxdump.tar.gz.md5#7458b27039e743d8bb4fcbf71ccaf4ac  new_taxdump.tar.gz

#3.解壓
mkdir ~/.taxonkit
tar zxf new_taxdump.tar.gz -C ~/.taxonkit
#里面包括citations.dmp侈咕,delnodes.dmp,division.dmp器紧,gencode.dmp耀销,typeoftype.dmp,merged.dmp铲汪,names.dmp熊尉,nodes.dmp,host.dmp掌腰,typematerial.dmp狰住,rankedlineage.dmp,fullnamelineage.dmp齿梁,taxidlineage.dmp催植,readme.txt
#詳細文檔:https://ftp.ncbi.nlm.nih.gov/pub/taxonomy/new_taxdump/taxdump_readme.txt

文件轉(zhuǎn)入$HOME/bin能起作用的前提是$HOME/bin在你的環(huán)境變量里

6.2. 子庫構(gòu)建

以Lactobacillus為例

6.2.1 Taxonomy ID
  • NCBI物種數(shù)據(jù)庫里搜Lactobacillus,有對應(yīng)的Taxonomy ID
  • 程序查找
grep -P "\|\s+[lL]actobacillus\w*\s*\|" ~/.taxonkit/names.dmp

Lactobacillus對應(yīng)的Taxonomy ID為1578

6.2.2.提取特定taxons下的所有taxid
taxonkit list --ids 1578 --indent "" > Lactobacillus.taxid.txt
wc -l Lactobacillus.taxid.txt #共2733個taxid

$nrdir是我存放prot.accession2taxid的地方

--ids是指定taxid士飒,--indent ""是將所列出的taxid左邊的空格去除查邢,以左對齊排列

6.2.3. 提取 Lactobacillus.taxid所有的accession

csvtk在prot.accession2taxid文件中提取Lactobacillus.taxid所有的accession,共6694759條entry

cat /picb/evolgen/users/gushanshan/ncbi_db/prot.accession2taxid |csvtk -t grep -f taxid -P Lactobacillus.taxid.txt  |csvtk -t cut -f taxid,accession.version > Lactobacillus.taxid.acc.new.txt
wc -l Lactobacillus.taxid.acc.new.txt

cat /picb/evolgen/users/gushanshan/ncbi_db/prot.accession2taxid |csvtk -t grep -f taxid -P nr_Lactobacillus/Lactobacillus.taxid.txt  |csvtk -t cut -f taxid,accession.version > all_accession_taxid
6.2.4. 建立Lactobacillus子庫
blastdb_aliastool -seqidlist Lactobacillus.taxid.acc.new.txt -db nr -out nr_Lactobacillus -title nr_Lactobacillus

blastdb_aliastool必須是ncbi toolkit里的酵幕,比如ncbi-blast-2.10.1+。conda安裝的不行缓苛。

7.應(yīng)用

blast系列有以下幾種


摘自徐洲更hoptop簡書 o(*^@^*)o

以npsA基因為例芳撒,尋找其在乳酸桿菌中的進化史。npsA protein fasta 序列下載網(wǎng)址

7.1. blast
#!/bin/bash

db_Lactobacillus=/picb/evolgen/users/gushanshan/probiotics/13tree/npsABC/genetree/nr_Lactobacillus

blastp -num_threads 2 -word_size 6 -gapopen 11 -gapextend 1 -threshold 21 -window_size 40 -db $db_Lactobacillus/nr_Lactobacillus -query npsa_wcfs1.fasta -out npsA_blast_result.txt -outfmt 6

得到2,459個hit

按照ncbi blastp的參數(shù)設(shè)置本地參數(shù)

7.2. 取出相似序列
7.2.1. 閾值選擇

根據(jù) An Introduction to Sequence Similarity (“Homology”) Searching的介紹未桥,將閾值選為bit score> 50笔刹。


得到2,458個hit。

500條同屬序列+3條外群序列+npsA=504條

7.2.2. 抽取序列
epost -db protein -input high_similarity_acc.txt | efetch -format fasta > high_similarity.fasta

epost -db protein -input allacc.txt | efetch -format ipg > allan_tax
7.3. 多序列比對
mafft --auto --thread -1 high_similarity.fasta > mafft_npsA.fasta

附錄1. taxId2taxName

為了了解哪些物種中存在npsA的相似蛋白質(zhì)冬耿,我們需要將6.2.2中得到的taxid對應(yīng)到taxName舌菜。

因為1)轉(zhuǎn)換過程很快,2)該過程不需要重復(fù)操作亦镶,所以我認為沒必要專門寫轉(zhuǎn)換程序

轉(zhuǎn)換網(wǎng)址:https://www.ncbi.nlm.nih.gov/Taxonomy/TaxIdentifier/tax_identifier.cgi

示例

附錄2. 蛋白質(zhì)accession對應(yīng)的具體strain

很多蛋白質(zhì)對應(yīng)species日月,但實際只屬于某些特定strain$凸牵可以通過identical protein

#單個id
esearch -db protein -query 'WP_011101060.1' | efetch -format ipg| grep "RefSeq"
#多個id
epost -db protein -input test | efetch -format ipg| grep "RefSeq"
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末爱咬,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子绊起,更是在濱河造成了極大的恐慌精拟,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,682評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異蜂绎,居然都是意外死亡栅表,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,277評論 3 395
  • 文/潘曉璐 我一進店門师枣,熙熙樓的掌柜王于貴愁眉苦臉地迎上來谨读,“玉大人,你說我怎么就攤上這事坛吁±椭常” “怎么了?”我有些...
    開封第一講書人閱讀 165,083評論 0 355
  • 文/不壞的土叔 我叫張陵拨脉,是天一觀的道長哆姻。 經(jīng)常有香客問我,道長玫膀,這世上最難降的妖魔是什么矛缨? 我笑而不...
    開封第一講書人閱讀 58,763評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮帖旨,結(jié)果婚禮上箕昭,老公的妹妹穿的比我還像新娘。我一直安慰自己解阅,他們只是感情好落竹,可當我...
    茶點故事閱讀 67,785評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著货抄,像睡著了一般述召。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上蟹地,一...
    開封第一講書人閱讀 51,624評論 1 305
  • 那天积暖,我揣著相機與錄音,去河邊找鬼怪与。 笑死夺刑,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的分别。 我是一名探鬼主播遍愿,決...
    沈念sama閱讀 40,358評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼茎杂!你這毒婦竟也來了错览?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,261評論 0 276
  • 序言:老撾萬榮一對情侶失蹤煌往,失蹤者是張志新(化名)和其女友劉穎倾哺,沒想到半個月后轧邪,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,722評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡羞海,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年忌愚,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片却邓。...
    茶點故事閱讀 40,030評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡硕糊,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出腊徙,到底是詐尸還是另有隱情简十,我是刑警寧澤,帶...
    沈念sama閱讀 35,737評論 5 346
  • 正文 年R本政府宣布撬腾,位于F島的核電站螟蝙,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏民傻。R本人自食惡果不足惜胰默,卻給世界環(huán)境...
    茶點故事閱讀 41,360評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望漓踢。 院中可真熱鬧牵署,春花似錦、人聲如沸喧半。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,941評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽薯酝。三九已至半沽,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間吴菠,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,057評論 1 270
  • 我被黑心中介騙來泰國打工浩村, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留做葵,地道東北人。 一個月前我還...
    沈念sama閱讀 48,237評論 3 371
  • 正文 我出身青樓心墅,卻偏偏與公主長得像酿矢,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子怎燥,可洞房花燭夜當晚...
    茶點故事閱讀 44,976評論 2 355