大家知道的最多的公共数据库除了TCGA,GEO,还有一个超大的数据库ENA数据库,下面来看看如何使用代码从里面下载数据!

ENA数据库官方网址:https://www./

FASTQ下载

下面以这个数据为例进行下载:E-MTAB-7918,搜索框输入项目编号:

其他信息见页面:https://www./arrayexpress/experiments/E-MTAB-7918,可以知道这个项目是T细胞免疫组库数据,4个样本,物种为小鼠。

选择如下:

可以得到样本的ID编号,保存到ID.txt文件中:

ERR3304809
ERR3304807
ERR3304810
ERR3304808

fq的ftp下载链接如下,多看几个链接得到链接的规律:

ftp://ftp.sra./vol1/fastq/ERR330/007/ERR3304807/ERR3304807_1.fastq.gz
ftp://ftp.sra./vol1/fastq/ERR330/007/ERR3304807/ERR3304807_2.fastq.gz
ftp://ftp.sra./vol1/fastq/ERR330/008/ERR3304808/ERR3304808_1.fastq.gz
ftp://ftp.sra./vol1/fastq/ERR330/008/ERR3304808/ERR3304808_2.fastq.gz
ftp://ftp.sra./vol1/fastq/ERR330/009/ERR3304809/ERR3304809_1.fastq.gz
ftp://ftp.sra./vol1/fastq/ERR330/009/ERR3304809/ERR3304809_2.fastq.gz

ascp的链接特征:

[email protected].:/vol1/fastq/ERR330/007/ERR3304807/ERR3304807_1.fastq.gz
[email protected].:/vol1/fastq/ERR330/007/ERR3304807/ERR3304807_2.fastq.gz

写一个bash代码进行下载:

## ftp下载地址
# ERR3304809
cat ID.txt |while read id
do
 echo "axel -n 100 ftp://ftp.sra./vol1/fastq/${id:0:6}/00${id: -1}/${id}/${id}_1.fastq.gz"
 echo "axel -n 100 ftp://ftp.sra./vol1/fastq/${id:0:6}/00${id: -1}/${id}/${id}_2.fastq.gz"
done >down_ftp.sh

down_ftp.sh 内容如下:

axel -n 100 ftp://ftp.sra./vol1/fastq/ERR330/009/ERR3304809/ERR3304809_1.fastq.gz
axel -n 100 ftp://ftp.sra./vol1/fastq/ERR330/009/ERR3304809/ERR3304809_2.fastq.gz
axel -n 100 ftp://ftp.sra./vol1/fastq/ERR330/007/ERR3304807/ERR3304807_1.fastq.gz
axel -n 100 ftp://ftp.sra./vol1/fastq/ERR330/007/ERR3304807/ERR3304807_2.fastq.gz
axel -n 100 ftp://ftp.sra./vol1/fastq/ERR330/000/ERR3304810/ERR3304810_1.fastq.gz
axel -n 100 ftp://ftp.sra./vol1/fastq/ERR330/000/ERR3304810/ERR3304810_2.fastq.gz
axel -n 100 ftp://ftp.sra./vol1/fastq/ERR330/008/ERR3304808/ERR3304808_1.fastq.gz
axel -n 100 ftp://ftp.sra./vol1/fastq/ERR330/008/ERR3304808/ERR3304808_2.fastq.gz

下载:

nohup bash down_ftp.sh >down_ftp.log &

同理得到ascp下载命令:

## ascp下载
# [email protected].:/vol1/fastq/ERR330/007/ERR3304807/ERR3304807_1.fastq.gz
# key注意换成自己的
key=/nas2/zhangj/biosoft/miniconda3/envs/rna/etc/asperaweb_id_dsa.openssh
# 循环
cat ID.txt |while read id
do
 echo "ascp -v -QT -l 300m -P33001 -k1 -i $key [email protected].:/vol1/fastq/${id:0:6}/00${id: -1}/${id}/${id}_1.fastq.gz ./"
 echo "ascp -v -QT -l 300m -P33001 -k1 -i $key [email protected].:/vol1/fastq/${id:0:6}/00${id: -1}/${id}/${id}_2.fastq.gz ./"
done >down_ascp.sh

down_ascp.sh 内容如下(只放了部分):

ascp -v -QT -l 300m -P33001 -k1 -i /nas2/zhangj/biosoft/miniconda3/envs/rna/etc/asperaweb_id_dsa.openssh [email protected].:/vol1/fastq/ERR330/009/ERR3304809/ERR3304809_1.fastq.gz ./
ascp -v -QT -l 300m -P33001 -k1 -i /nas2/zhangj/biosoft/miniconda3/envs/rna/etc/asperaweb_id_dsa.openssh [email protected].:/vol1/fastq/ERR330/009/ERR3304809/ERR3304809_2.fastq.gz ./
...

下载:

nohup bash down_ascp.sh >down_ascp.log &

表达矩阵下载

由于表达矩阵一般比较小,这里我们换一个思路使用R代码下载!以单细胞表达矩阵 E-MTAB-7919 项目为例。

得到项目页面:https://www./biostudies/arrayexpress/studies/E-MTAB-7919

点开之后:选择目标文件,单击数遍右键复制链接

如何从ENA数据库批量下载fq数据与表达矩阵(代码版)?

得到的链接特征如下:

https://ftp./biostudies/fire/E-MTAB-/919/E-MTAB-7919/Files/matrix.mtx
https://ftp./biostudies/fire/E-MTAB-/919/E-MTAB-7919/Files/genes.tsv
https://ftp./biostudies/fire/E-MTAB-/919/E-MTAB-7919/Files/barcodes.tsv

下面使用R语言下载!

简单的安装一下下面的分析中所需要的包:

## 使用西湖大学的 Bioconductor镜像
options(BioC_mirror="https://mirrors./bioconductor")
options("repos"=c(CRAN="https://mirrors./CRAN/"))

library(remotes)
remotes::install_github("carmonalab/STACAS")
remotes::install_github("carmonalab/ProjecTILs")
devtools::install_github("BorchLab/scRepertoire@v1")

从 Array Express (https://www./arrayexpress/experiments/E-MTAB-7919/) 下载成功后解压会得到三个文件:matrix.mtx, genes.tsv and barcodes.tsv

rm(list=ls())
options(timeout=5000)
options(warn=1)
library(renv)
#renv::restore()
library(Seurat)
library(ggplot2)
library(patchwork)
library(ProjecTILs)
library(scRepertoire)

## 下载
files <- c("matrix.mtx","genes.tsv","barcodes.tsv"# 具体的文件名字
matrix_dir <- "./Xiong_TIL/matrix/"

dir.create(matrix_dir, recursive = T, showWarnings = F)

for (i in 1:length(files)) {
# 根据下载链接得到的通用下载地址
  dataUrl <- sprintf("https://www./biostudies/files/E-MTAB-7919/%s", files[i])
print(dataUrl)
  download.file(dataUrl, paste0(matrix_dir, files[i]))
}

这样数据就下载下来啦:

简单读取进来并创建seurat对象看看:

## 读取数据
projectID <- "Xiong_TIL"
libIDtoSampleID <- c("Mouse 1","Mouse 2","Mouse 3","Mouse 4")
names(libIDtoSampleID) <- 4:7
libIDtoSampleID

exp_mat <- Read10X(matrix_dir)
querydata <- CreateSeuratObject(counts = exp_mat, project = projectID, min.cells = 3, min.features = 50)
querydata

colnames(querydata)
querydata$Sample <- substring(colnames(querydata),18)
table(querydata$Sample)

querydata$SampleLabel <- factor(querydata$Sample, levels = c(4:7), labels=libIDtoSampleID)
table(querydata$SampleLabel)

今天分享到这里~