NCBI_SRA下载

下载sratools:

img

解压安装:

二进制文件,解压配置环境后就能用。注意:该工具下载后会在家目录下自动建一个ncbi的目录。

#tar -zxvf 文件名
tar -zxvf sratoolkit.2.10.9-centos_linux64.tar.gz

配置环境:

  • 最好先pwd先查看自己的具体路径,避免出错,配置好之后可以 用fastq-dump查看一下是否路径添加成功.


$ cd sratoolkit.2.10.9-centos_linux64 bin
$ pwd
/home/xiaotangyuan/sratoolkit.2.10.9-centos_linux64/bin
   
$ echo 'export export PATH=$PATH:/home/xiaotangyuan/sratoolkit.2.10.9-centos_linux64/bin' >> ~/.bash_profile
$ source ~/.bash_profile
$ cd  sratoolkit.2.10.9-centos_linux64/bin
$vdb-config -i
$ which fastq-dump 
/home/xiaotangyuan/sratoolkit.2.10.9-centos_linux64/bin/fastq-dump

1. prefetch下载数据

  • 单个数据下载
    $ prefetch SRR1234567
    
    ...
    
  • 批量数据下载

    获取Accession List:

    进入NCBI的SRA数据库输入SRP号:

$ prefetch --option-file SraAccList.txt
#下载完成后,文件被存储在默认目录:/home/usr/ncbi/public/sra/

#放在后台
nohup prefetch -O . $(<SRR_Acc_List.txt) &

2. wget 下载

  • 单个数据下载

    获取下载地址:

img
img
$ wget https://sra-download.ncbi.nlm.nih.gov/traces/sra60/SRR/005361/SRR5489805
正在解析主机 sra-download.ncbi.nlm.nih.gov (sra-download.ncbi.nlm.nih.gov)... 130.14.250.24, 130.14.250.25, 130.14.250.28
正在连接 sra-download.ncbi.nlm.nih.gov (sra-download.ncbi.nlm.nih.gov)|130.14.250.24|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:3491558416 (3.3G) [application/octet-stream]
正在保存至: “SRR5489805.1” 0% [ ] 646,937 188KB/s 剩余 5h 1m
  • 批量数据下载

    获取下载地址:在Send to下选择Runinfo而不是Accession List:

获取批量下载的地址

然后把这些下载地址保存在一个新的文件中:

然后利用wget -i 文件 直接下载(放入后台不中断下载:nohup cmd &):

$ nohup wget -i download_path.txt &

[1] 30328

#nohup: 忽略输入并把输出追加到"nohup.out"

3.本人用的方法

我的文件中只有SRA号,如下:

zzzzzz.jpg
setwd("/sibcb1/bioinformatics/wangjiahao/hope/siqi")

source("/sibcb2/bioinformatics2/wangjiahao/code/MyTreasures.R")

Anno  = read.table(file = "SRA.txt", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
SRXID = Anno[, 1]
Ns    = length(SRXID)

targetFolder = "NCBI_SRA"
setwd(targetFolder)
done = list.files()
SRXID %in% done

#打开多个shell界面进行下载
# for(i in 1:15){
# for(i in 16:30){
# for(i in 31:45){
# for(i in 46:60){
# for(i in 61:75){
# for(i in 76:84){
for(i in 74:75){

    SRX = SRXID[i]
    cat("Processing", i, SRX, "\n")

    if(!dir.exists(SRX))
            dir.create(SRX)

    setwd(SRX)
    #因为家目录出现问题导致自己下载的sratools不能使用,也不能添加环境变量,所以使用绝对路径
    runFTP = system(paste("/sibcb2/bioinformatics2/wangjiahao/software/sratoolkit/bin/srapath", SRX), intern = TRUE)
    runID  = sapply(strsplit(runFTP, "/"), function(z) z[length(z) - 1])

    if(length(runFTP) == 0)
            next

    for(j in 1:length(runFTP)){

            sra = paste0(runID[j], ".sra")
            cmd = paste("wget -c", runFTP[j], "-O", sra)
            system(cmd)
    }
    setwd("../")
}

#稍微忽略
prefetch -t ascp -a "/sibcb1/bioinformatics/wangjiahao/.aspera/connect/bin/ascp|/sibcb1/bioinformatics/wangjiahao/.aspera/connect/etc/asperaweb_id_dsa.openssh" --option-file SRR_Acc_List.txt -O NCBI_SRA_raw

下载.sra数据后转化为fastq文件

#fasstq-dump也是sratools的一个工具
for f in *.sra
do
nohup fastq-dump --split-3 $f &
done

本文参考://www.greatytc.com/p/f37a9a87d463
若侵必删,谢谢

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。