转录本


简单的转录组
只需要两个文件

SRR_Acc_List.txt

里面的内容:
SRR9115998
SRR9115999
SRR9116000
SRR9116001
SRR9116002
SRR9116003
SRR9116004
SRR9116005
SRR9116006
SRR9116007
SRR9116008
SRR9116009


RNA3_ensemble.py

代码在下方,只需要改路径

最后就能得到FPKM表

RNA3_ensemble1.py

import os
import subprocess

文件路径和目录设置

id_txt = “/home/data1/Ghl/test_RNA7/SRR_Acc_List.txt”
base_dir = “/home/data1/Ghl/test_RNA7”
directories = [
“all_sra”,
“fastq1_2”,
“fastqc”,
“fastp”,
“sam”,
“bam”,
“short_bam”,
“gtf”,
“htseq”,
“_e_gtf”
]

确保所有目录存在

for directory in directories:
dir_path = os.path.join(base_dir, directory)
os.makedirs(dir_path, exist_ok=True)
print(“All directories are ensured to exist.”)

读取SRR序列ID

srr_ids = []
try:
with open(id_txt, ‘r’) as file:
for line in file:
srr_id = line.strip() # 去除行尾的换行符和空格
if srr_id: # 确保不是空行
srr_ids.append(srr_id)
print(“SRR IDs read successfully:”, srr_ids)
except FileNotFoundError:
print(“File not found.”)
except Exception as e:
print(“An error occurred:”, e)

base_dir = “/home/data1/Ghl/test_RNA7” #设置基本工作路径,一般是sra文件的上一级文件夹
sra_dir = f”{base_dir}/all_sra”
fastq_dir = f”{base_dir}/fastq1_2”
fastqc_dir = f”{base_dir}/fastqc”
fastp_dir = f”{base_dir}/fastp”
sam_dir = f”{base_dir}/sam”
bam_dir = f”{base_dir}/bam”
short_bam_dir = f”{base_dir}/short_bam”
gtf_dir = f”{base_dir}/gtf”
htseq_dir = f”{base_dir}/htseq”
e_gtf_dir = f”{base_dir}/_e_gtf”

hisat2_index = “/home/data1/renminpeng/wangjingfeng/gene_reference_index” #设置hisat2_index索引,这个暂时不要改变路径
reference_gtf = “/home/data1/renminpeng/wangjingfeng/modified_genomic.gff” #设置参考基因的gtf文件,可以用此路径执行,未来也可以在ensembl中下载鸡的gtf文件
output_path = “/home/data1/EN_ref/mergelist.txt” #设置输出mergelist.txt的输出路径,此时会创建一个mergelist.txt的文件,让输出的内容进入到这个txt文件夹里
stringtie_merge_path = “/home/data1/renminpeng/wangjingfeng/modified_genomic.gff” #设置参考基因的gtf文件,用于不同路径参数设置
###注意:在最下方处也有要修改路径,在运行这个脚本前,应当新建一个_e_gtf文件夹,然后将_e_gtf文件夹的绝对路径输入至target_dir处

Ensure all directories exist

for d in [sra_dir, fastq_dir, fastqc_dir, fastp_dir, sam_dir, bam_dir, short_bam_dir, gtf_dir, htseq_dir, e_gtf_dir]:
os.makedirs(d, exist_ok=True)

for srr_id in srr_ids:
print(f”Quantifying gene expression for {srr_id}…”)
bam_file = os.path.join(short_bam_dir, f”{srr_id}.sorted.bam”)
output_file = os.path.join(htseq_dir, f”{srr_id}.counts.txt”)
with open(output_file, ‘w’) as out:
subprocess.run([
“htseq-count”, “-s”, “no”, “-f”, “bam”, bam_file, reference_gtf
], stdout=out, check=True)

Estimating transcript abundances with StringTie using merged GTF

for srr_id in srr_ids:
out_dir = os.path.join(e_gtf_dir, srr_id)
os.makedirs(out_dir, exist_ok=True)
print(f”Estimating transcript abundances for {srr_id}…”)
subprocess.run([
“stringtie”, “-e”, “-B”, “-p”, “8”, “-G”, reference_gtf,
“-o”, os.path.join(out_dir, f”{srr_id}.gtf”),
os.path.join(short_bam_dir, f”{srr_id}.sorted.bam”)
], check=True)

遍历 _e_gtf 文件夹中的所有子文件夹(以 SRR 开头的)

sample_dirs = [d for d in os.listdir(e_gtf_dir) if os.path.isdir(os.path.join(e_gtf_dir, d)) and d.startswith(“SRR”)]

创建一个列表,用于存储每个子文件夹的名称和对应的路径

sample_paths = []

遍历每个子文件夹,获取其名称并构建其对应的完整路径,同时将名称和路径存储到 sample_paths 列表中

for sample_dir in sample_dirs:
sample_id = sample_dir
gtf_path = os.path.join(e_gtf_dir, sample_dir, f”{sample_dir}.gtf”)
if os.path.exists(gtf_path): # 检查 gtf 文件是否存在
sample_paths.append((sample_id, gtf_path))

创建 mergelist.txt 文件并写入每个子文件夹的名称和路径

with open(output_path, “w”) as file:
for sample_id, gtf_path in sample_paths:
file.write(f”{sample_id} {gtf_path}\n”)

只有当有 .gtf 文件时,才尝试执行后续的命令

if sample_paths: # 检查列表是否为空
gtf_files = [path for _, path in sample_paths] # 从路径列表中获取所有 gtf 文件
gtf_list = “ “.join(gtf_files)
# 你可以在这里继续你的处理,例如使用 stringtie –merge
# 例如:subprocess.run([“stringtie”, “–merge”, “-o”, “merged.gtf”] + gtf_files)
else:
print(“没有找到任何 .gtf 文件,请检查你的 e_gtf_dir 目录”)

执行stringtie –merge命令

import glob

使用 glob 寻找当前目录及其子目录下的所有 .gtf 文件

如果你只需要在当前目录下查找,去掉 ‘**/‘ 即可

gtf_files = glob.glob(‘**/*.gtf’, recursive=True)

列表推导用于移除空字符串已经不再需要,因为 glob 不会返回空字符串

将找到的文件路径列表转换为字符串,文件路径之间用空格分隔

gtf_list = “ “.join(gtf_files)

print(gtf_list)

执行stringtie命令处理每个bam文件

执行 ls 命令查找 *.sorted.bam 文件

bam_files = glob.glob(“**/*.sorted.bam”)

移除空字符串和空格

bam_files = [file.strip() for file in bam_files if file.strip()]

打印查找到的文件列表

print(“Found BAM files:”, bam_files)

for bam_file in bam_files:
sample_id = os.path.splitext(bam_file)[0]
output_dir = f”ballgown/{sample_id.split(‘_’)[0]}”
os.makedirs(output_dir, exist_ok=True)
subprocess.run([“stringtie”, bam_file, “-G”, stringtie_merge_path, “-o”, f”{output_dir}/{sample_id}.gtf”, “-A”, f”{sample_id}.tab”, “-B”, “-e”, “-p”, “16”])

import subprocess
import os

current_dir = os.getcwd()

指定目标路径

target_dir = “/home/data1/Ghl/test_RNA7/_e_gtf”

try:
# 切换到目标路径
os.chdir(target_dir)

# 定义 gene_count_matrix.csv 和 transcript_count_matrix.csv 的路径
gene_count_matrix = "gene_count_matrix.csv"
transcript_count_matrix = "transcript_count_matrix.csv"

# 调用 prepDE.py 脚本并传递参数
subprocess.run(["python3", "/home/data1/RNA_get/prepDE.py3", "-g", gene_count_matrix, "-t", transcript_count_matrix])

# 假设 getTPM.py 和 getFPKM.py 脚本需要 GTF 文件和输出文件路径

tpm_output = "output_tpm.csv"
fpkm_output = "output_fpkm.csv"

# 调用 getTPM.py
subprocess.run(["python2", "/home/data1/RNA_get/getTPM.py", "-i", target_dir, "-g", tpm_output])

# 调用 getFPKM.py
subprocess.run(["python2", "/home/data1/RNA_get/getFPKM.py", "-i", target_dir, "-g", fpkm_output])

finally:
# 最后返回原始工作目录
os.chdir(current_dir)

print(“RNA-seq analysis pipeline completed.”)

RNA3_ensemble.py

代码在下方,只需要改路径

最后就能得到FPKM表

import os
import subprocess

文件路径和目录设置

id_txt = “/home/data1/Ghl/test_RNA3/SRR_Acc_List.txt”
base_dir = “/home/data1/Ghl/test_RNA3”
directories = [
“all_sra”,
“fastq1_2”,
“fastqc”,
“fastp”,
“sam”,
“bam”,
“short_bam”,
“gtf”,
“htseq”,
“_e_gtf”
]

确保所有目录存在

for directory in directories:
dir_path = os.path.join(base_dir, directory)
os.makedirs(dir_path, exist_ok=True)
print(“All directories are ensured to exist.”)

读取SRR序列ID

srr_ids = []
try:
with open(id_txt, ‘r’) as file:
for line in file:
srr_id = line.strip() # 去除行尾的换行符和空格
if srr_id: # 确保不是空行
srr_ids.append(srr_id)
print(“SRR IDs read successfully:”, srr_ids)
except FileNotFoundError:
print(“File not found.”)
except Exception as e:
print(“An error occurred:”, e)

base_dir = “/home/data1/Ghl/test_RNA3” #设置基本工作路径,一般是sra文件的上一级文件夹
sra_dir = f”{base_dir}/all_sra”
fastq_dir = f”{base_dir}/fastq1_2”
fastqc_dir = f”{base_dir}/fastqc”
fastp_dir = f”{base_dir}/fastp”
sam_dir = f”{base_dir}/sam”
bam_dir = f”{base_dir}/bam”
short_bam_dir = f”{base_dir}/short_bam”
gtf_dir = f”{base_dir}/gtf”
htseq_dir = f”{base_dir}/htseq”
e_gtf_dir = f”{base_dir}/_e_gtf”

hisat2_index = “/home/data1/EN_ref/GallusGRCg7b_index” #设置hisat2_index索引,这个暂时不要改变路径
reference_gtf = “/home/data1/EN_ref/GallusGRCg7b.gtf” #设置参考基因的gtf文件,可以用此路径执行,未来也可以在ensembl中下载鸡的gtf文件
output_path = “/home/data1/EN_ref/mergelist.txt” #设置输出mergelist.txt的输出路径,此时会创建一个mergelist.txt的文件,让输出的内容进入到这个txt文件夹里
stringtie_merge_path = “/home/data1/EN_ref/GallusGRCg7b.gtf” #设置参考基因的gtf文件,用于不同路径参数设置
###注意:在最下方处也有要修改路径,在运行这个脚本前,应当新建一个_e_gtf文件夹,然后将_e_gtf文件夹的绝对路径输入至target_dir处

Ensure all directories exist

for d in [sra_dir, fastq_dir, fastqc_dir, fastp_dir, sam_dir, bam_dir, short_bam_dir, gtf_dir, htseq_dir, e_gtf_dir]:
os.makedirs(d, exist_ok=True)

检查并下载缺失的SRA文件

for srr_id in srr_ids:
sra_file_path = os.path.join(sra_dir, f”{srr_id}.sra”)
if not os.path.exists(sra_file_path):
print(f”Downloading {srr_id}…”)
subprocess.run([“prefetch”, srr_id], check=True)
subprocess.run([“mv”, os.path.join(“sra”, f”{srr_id}.sra”), sra_dir], check=True)
else:
print(f”{srr_id}.sra already exists, skipping download.”)

Converting SRA to FASTQ

for srr_id in srr_ids:
print(f”Converting {srr_id} to FASTQ…”)
subprocess.run([“fastq-dump”, “–outdir”, fastq_dir, “–split-files”, os.path.join(sra_dir, f”{srr_id}.sra”)], check=True)

Quality control with FastQC

for srr_id in srr_ids:
print(f”Quality control for {srr_id}…”)
subprocess.run([“fastqc”, os.path.join(fastq_dir, f”{srr_id}_1.fastq”), os.path.join(fastq_dir, f”{srr_id}_2.fastq”), “-o”, fastqc_dir], check=True)

Trimming reads with Fastp

print(f"Processing sample {srr_id} with fastp...")
subprocess.run([
    "fastp",
    "-i", os.path.join(fastq_dir, f"{srr_id}_1.fastq"),
    "-I", os.path.join(fastq_dir, f"{srr_id}_2.fastq"),
    "-o", os.path.join(fastp_dir, f"output{srr_id}_1.fastq"),
    "-O", os.path.join(fastp_dir, f"output{srr_id}_2.fastq"),
    "--length_required", "36",
    "--low_complexity_filter",
    "--qualified_quality_phred", "10",
    "--unqualified_percent_limit", "50",
    "--n_base_limit", "10",
    "--compression", "6",
    "-R", srr_id,
    "-h", os.path.join(fastp_dir, f"{srr_id}.html")
])

Alignment with HISAT2

for srr_id in srr_ids:
print(f”Aligning {srr_id} using HISAT2…”)
subprocess.run([
“hisat2”, “-p”, “8”, “–dta”,
“-x”, hisat2_index,
“-1”, os.path.join(fastp_dir, f”output{srr_id}_1.fastq”),
“-2”, os.path.join(fastp_dir, f”output{srr_id}_2.fastq”),
“-S”, os.path.join(sam_dir, f”{srr_id}.sam”)
], check=True)

SAM转换为BAM并排序

for srr_id in srr_ids:
print(f”Converting and sorting {srr_id} SAM to BAM…”)

# 临时BAM文件的路径
temp_bam_path = os.path.join(sra_dir, f"{srr_id}.bam")

# 使用samtools view将SAM转换为未排序的BAM,输出到临时文件
subprocess.run(["samtools", "view", "-bS", os.path.join(sam_dir, f"{srr_id}.sam")], stdout=open(temp_bam_path, 'wb'), check=True)

# 对临时BAM文件进行排序,并将结果保存到最终的路径
sorted_bam_path = os.path.join(short_bam_dir, f"{srr_id}.sorted.bam")
subprocess.run(["samtools", "sort", "-o", sorted_bam_path, temp_bam_path], check=True)

# 删除临时BAM文件以节省空间
os.remove(temp_bam_path)

Generating GTF files with StringTie

for srr_id in srr_ids:
print(f”Generating GTF for {srr_id} with StringTie…”)
subprocess.run([
“stringtie”, “-p”, “8”, “-G”, reference_gtf, “-o”, os.path.join(gtf_dir, f”{srr_id}.gtf”),
os.path.join(short_bam_dir, f”{srr_id}.sorted.bam”)
], check=True)

for srr_id in srr_ids:
print(f”Quantifying gene expression for {srr_id}…”)
bam_file = os.path.join(short_bam_dir, f”{srr_id}.sorted.bam”)
output_file = os.path.join(htseq_dir, f”{srr_id}.counts.txt”)
with open(output_file, ‘w’) as out:
subprocess.run([
“htseq-count”, “-s”, “no”, “-f”, “bam”, bam_file, reference_gtf
], stdout=out, check=True)

Estimating transcript abundances with StringTie using merged GTF

for srr_id in srr_ids:
out_dir = os.path.join(e_gtf_dir, srr_id)
os.makedirs(out_dir, exist_ok=True)
print(f”Estimating transcript abundances for {srr_id}…”)
subprocess.run([
“stringtie”, “-e”, “-B”, “-p”, “8”, “-G”, reference_gtf,
“-o”, os.path.join(out_dir, f”{srr_id}.gtf”),
os.path.join(short_bam_dir, f”{srr_id}.sorted.bam”)
], check=True)

遍历 _e_gtf 文件夹中的所有子文件夹(以 SRR 开头的)

sample_dirs = [d for d in os.listdir(e_gtf_dir) if os.path.isdir(os.path.join(e_gtf_dir, d)) and d.startswith(“SRR”)]

创建一个列表,用于存储每个子文件夹的名称和对应的路径

sample_paths = []

遍历每个子文件夹,获取其名称并构建其对应的完整路径,同时将名称和路径存储到 sample_paths 列表中

for sample_dir in sample_dirs:
sample_id = sample_dir
gtf_path = os.path.join(e_gtf_dir, sample_dir, f”{sample_dir}.gtf”)
if os.path.exists(gtf_path): # 检查 gtf 文件是否存在
sample_paths.append((sample_id, gtf_path))

创建 mergelist.txt 文件并写入每个子文件夹的名称和路径

with open(output_path, “w”) as file:
for sample_id, gtf_path in sample_paths:
file.write(f”{sample_id} {gtf_path}\n”)

只有当有 .gtf 文件时,才尝试执行后续的命令

if sample_paths: # 检查列表是否为空
gtf_files = [path for _, path in sample_paths] # 从路径列表中获取所有 gtf 文件
gtf_list = “ “.join(gtf_files)
# 你可以在这里继续你的处理,例如使用 stringtie –merge
# 例如:subprocess.run([“stringtie”, “–merge”, “-o”, “merged.gtf”] + gtf_files)
else:
print(“没有找到任何 .gtf 文件,请检查你的 e_gtf_dir 目录”)

执行stringtie –merge命令

import glob

使用 glob 寻找当前目录及其子目录下的所有 .gtf 文件

如果你只需要在当前目录下查找,去掉 ‘**/‘ 即可

gtf_files = glob.glob(‘**/*.gtf’, recursive=True)

列表推导用于移除空字符串已经不再需要,因为 glob 不会返回空字符串

将找到的文件路径列表转换为字符串,文件路径之间用空格分隔

gtf_list = “ “.join(gtf_files)

print(gtf_list)

执行stringtie命令处理每个bam文件

执行 ls 命令查找 *.sorted.bam 文件

bam_files = glob.glob(“**/*.sorted.bam”)

移除空字符串和空格

bam_files = [file.strip() for file in bam_files if file.strip()]

打印查找到的文件列表

print(“Found BAM files:”, bam_files)

for bam_file in bam_files:
sample_id = os.path.splitext(bam_file)[0]
output_dir = f”ballgown/{sample_id.split(‘_’)[0]}”
os.makedirs(output_dir, exist_ok=True)
subprocess.run([“stringtie”, bam_file, “-G”, stringtie_merge_path, “-o”, f”{output_dir}/{sample_id}.gtf”, “-A”, f”{sample_id}.tab”, “-B”, “-e”, “-p”, “16”])

import subprocess
import os

current_dir = os.getcwd()

指定目标路径

target_dir = “/home/data1/Ghl/test_RNA3/_e_gtf”

try:
# 切换到目标路径
os.chdir(target_dir)

# 定义 gene_count_matrix.csv 和 transcript_count_matrix.csv 的路径
gene_count_matrix = "gene_count_matrix.csv"
transcript_count_matrix = "transcript_count_matrix.csv"

# 调用 prepDE.py 脚本并传递参数
subprocess.run(["python3", "/home/data1/RNA_get/prepDE.py3", "-g", gene_count_matrix, "-t", transcript_count_matrix])

# 假设 getTPM.py 和 getFPKM.py 脚本需要 GTF 文件和输出文件路径

tpm_output = "output_tpm.csv"
fpkm_output = "output_fpkm.csv"

# 调用 getTPM.py
subprocess.run(["python2", "/home/data1/RNA_get/getTPM.py", "-i", target_dir, "-g", tpm_output])

# 调用 getFPKM.py
subprocess.run(["python2", "/home/data1/RNA_get/getFPKM.py", "-i", target_dir, "-g", fpkm_output])

finally:
# 最后返回原始工作目录
os.chdir(current_dir)

print(“RNA-seq analysis pipeline completed.”)

从 NCBI数据库中获取6组转录组数据,分 别为 未 受 NDV 感 染 的 对 照 组 (登 录 号 分 别 为
SRR13021942、SRR13021943、SRR13021946)和 受NDV 感染的处理组(登录号分别为 SRR13021947、
SRR13021955、SRR13021956),

将 两 组 的3个 重 复均 一 化 后,通过各组数据中每千碱基百万片段(FPKM)值对 Wnt表达谱进行评估,并采用log2 进行转换归一化

你的问题涉及到转录组数据分析的一系列步骤,我将尽量简明地解释每个步骤及其意义。

转录组数据分析流程概述

  1. 获取数据:首先,你从NCBI数据库获取了六组转录组数据,分别代表对照组和处理组(受NDV感染)的样本。这些数据通常以测序读段(reads)的形式提供,每个读段是一个短的DNA片段序列。

  2. 质量控制:在进行下一步之前,通常需要对原始测序数据进行质量控制,移除低质量的读段和污染。

  3. 读段比对:将清洗后的读段比对到参考基因组或转录组上。这一步是为了确定每个读段在基因组中的位置。

  4. 计算表达量:在读段成功比对后,下一步是计算每个基因的表达量。FPKM(每千碱基百万片段)是一种常用的表达量衡量方式,用于描述某个基因表达水平的标准化值。

均一化和FPKM

  • 均一化(Normalization):在生物信息学中,均一化是数据处理的一种方法,旨在消除实验设计和测序过程中的偏差。例如,不同样本的测序深度(即测序的总读段数)可能不同,直接比较原始的读段计数可能会误导。因此,需要进行均一化处理来确保样本间的可比性。

  • FPKM:FPKM代表“每千碱基百万片段”。它是一种衡量基因表达量的标准化方法,考虑了基因长度和测序深度的影响,从而使不同样本或基因之间的表达量可比。计算FPKM之前已经包括了一种均一化过程,以消除样本间测序深度和基因长度变异带来的影响。

log2转换

  • log2转换:在得到FPKM值后,为了使数据更适合统计分析,通常会进行log2转换。这一转换有几个好处:首先,它可以帮助稳定方差,因为大的FPKM值的波动对结果的影响会比小的FPKM值大;其次,log转换后的数据更接近正态分布,这对许多统计测试来说是一个重要的前提条件。log2转换也便于在处理组和对照组之间的比较中,用对数比率直观地表示表达量的变化。

总结

所以,你的数据处理流程大致为:从NCBI获取数据 → 质量控制 → 读段比对 → 计算FPKM(已包含一种均一化) → 对FPKM值进行log2转换以进一步归一化和方便分析。

每一步都有其特定的目的和重要性,确保了最终得到的数据既可比较又适合进行生物学上的解释和分析。

下载NCBI数据库中的转录组数据并分析通常涉及多个步骤和不同的生物信息学工具。以下是一般的流程和相应代码示例,使用的是一些流行的命令行工具。请注意,实际分析可能需要根据具体数据和研究目标进行调整。

步骤1: 下载数据

使用SRA Toolkitfastq-dump工具从NCBI的SRA数据库下载数据。安装SRA Toolkit后,可以使用以下命令下载数据:

1
2
3
4
5
6
fastq-dump --split-files SRR13021942
fastq-dump --split-files SRR13021943
fastq-dump --split-files SRR13021946
fastq-dump --split-files SRR13021947
fastq-dump --split-files SRR13021955
fastq-dump --split-files SRR13021956

--split-files参数用于将成对的测序数据分开下载。

步骤2: 质量控制

使用FastQC进行质量检查,并用Trimmomaticfastp进行质量控制,去除低质量的序列。

1
fastp -i SRR13021942_1.fastq -I SRR13021942_2.fastq -o SRR13021942_1_trimmed.fastq -O SRR13021942_2_trimmed.fastq

重复上述命令,替换相应的SRR编号以处理所有样本。

步骤3: 读段比对

使用HISAT2STARBowtie2等工具将读段比对到参考基因组。

HISAT2为例:

1
hisat2 -x reference_genome_index -1 SRR13021942_1_trimmed.fastq -2 SRR13021942_2_trimmed.fastq -S SRR13021942_aligned.sam

这里reference_genome_index是参考基因组的索引,需要预先建立。重复上述命令处理所有样本。

步骤4: 计算FPKM

使用StringTieCufflinks从比对结果中计算FPKM。

StringTie为例:

1
stringtie SRR13021942_aligned.bam -G reference_annotation.gtf -e -B -o SRR13021942.gtf

这里reference_annotation.gtf是参考基因组的注释文件。

步骤5: log2转换

log2转换通常在数据汇总和分析阶段进行,这可以使用R语言来完成:

1
2
# 假设df是包含FPKM值的数据框架,其中一列名为FPKM
df$log2FPKM <- log2(df$FPKM + 1) # 加1是为了避免log2(0)的情况

注意事项

  • 每一步骤的具体命令和参数可能需要根据你的数据和实验设计进行调整。
  • 参考基因组的索引建立、注释文件等需要根据你的目标物种准备。
  • 上述过程中的每个步骤都可能需要相当的计算资源,尤其是读段比对和表达量计算步骤。

这个流程是比较通用的,但根据具体的项目要求和数据特点,可能还需要其他的步骤或调整。

创建一个自动化脚本来处理从下载到生成FPKM的整个流程是可能的,但需要你的环境中已经安装了所有必需的软件,并且有适当的参考基因组及其索引。下面是一个简化的示例流程,展示如何使用bash脚本来自动化这一过程。请注意,你可能需要根据自己的具体需求调整这个脚本。

这个脚本假设你已经安装了:

  • SRA Toolkit (对于fastq-dump)
  • FastQC (对于质量检查)
  • Trimmomatic 或 fastp (对于质量控制)
  • HISAT2 (对于比对)
  • StringTie (对于计算FPKM)

步骤1: 创建下载列表

首先,创建一个文本文件(假设命名为sra_list.txt),其中包含你想下载的SRA运行编号,每行一个。

1
2
3
4
5
6
SRR13021942
SRR13021943
SRR13021946
SRR13021947
SRR13021955
SRR13021956

步骤2: 编写自动化脚本

接下来,创建一个bash脚本(比如命名为run_analysis.sh),将以下内容粘贴进去。确保修改脚本中的路径以匹配你的环境和文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash

# 设置工作目录
WORK_DIR=/path/to/your/workdir
cd $WORK_DIR

# 参考基因组和注释文件
REF_GENOME=/path/to/reference/genome.fa
REF_ANNOTATION=/path/to/reference/annotation.gtf

# HISAT2索引的基本名称
GENOME_INDEX_BASENAME=/path/to/index/prefix

# 循环遍历SRA编号列表
while read SRR; do
echo "Processing $SRR..."

# 下载数据
fastq-dump --split-files $SRR

# 质量控制
fastp -i ${SRR}_1.fastq -I ${SRR}_2.fastq -o ${SRR}_1_trimmed.fastq -O ${SRR}_2_trimmed.fastq

# 比对
hisat2 -x $GENOME_INDEX_BASENAME -1 ${SRR}_1_trimmed.fastq -2 ${SRR}_2_trimmed.fastq -S ${SRR}.sam

# SAM转BAM
samtools view -Sb ${SRR}.sam > ${SRR}.bam

# 排序BAM
samtools sort ${SRR}.bam -o ${SRR}_sorted.bam

# 计算FPKM
stringtie ${SRR}_sorted.bam -G $REF_ANNOTATION -e -B -o ${SRR}/stringtie_output.gtf

done < sra_list.txt

echo "All processes have been completed."

确保给予脚本执行权限:

1
chmod +x run_analysis.sh

步骤3: 运行脚本

在终端中运行脚本:

1
./run_analysis.sh

这个脚本将自动遍历你提供的SRA运行编号,下载数据,执行质量控制,比对到参考基因组,然后计算每个样本的FPKM值。

注意:

  • 这个脚本非常基础,仅用于演示目的。在实际使用中,你可能需要添加额外的错误检查和日志记录,以确保每个步骤都按预期完成。
  • 根据你的具体情况,可能需要调整命令的参数或添加额外的步骤(如索引构建或质量评估报告)。
  • 确保所有软件的路径都设置正确,参考基因组和注释文件已准备好,并且相应的索引适合于你使用的比对工具。

上面的脚本为一个基础示例,用于展示如何自动化处理转录组数据,从下载到FPKM计算的整个过程。在实际使用中,这个脚本需要根据你的环境和数据进行适当的调整。我会基于你的提问对代码进行简要的错误检查和提出潜在的冲突点,同时提供一些改进建议。

错误检查和潜在冲突

  1. 环境依赖:确保所有依赖的软件(如fastq-dumpfastphisat2samtoolsstringtie)都已正确安装,并且在你的$PATH环境变量中,以便脚本能够直接调用这些命令。

  2. 文件命名和路径:在处理多个样本时,输出文件(如BAM、SAM文件)的命名应该避免相互冲突。在脚本中,输出文件是根据SRA编号命名的,这有助于减少冲突。但是,如果脚本被多次运行而没有清理或移动上一次运行的结果,可能会导致输出文件被意外覆盖。

  3. 并行处理和资源管理:脚本以序列方式处理每个样本,这意味着在处理大量数据时可能会非常慢。此外,没有对系统资源进行管理,可能会在资源有限的系统上遇到问题。

改进建议

  • 避免文件覆盖:在处理每个样本之前,检查输出文件是否已存在,如果已存在,则跳过该样本或提示用户。
1
2
3
4
if [ -f "${SRR}_sorted.bam" ]; then
echo "${SRR}_sorted.bam already exists, skipping..."
continue
fi
  • 并行处理:考虑使用GNU parallel或在一个高性能计算环境中使用作业调度系统来并行处理样本,这可以显著提高处理速度。

  • 日志记录和错误检查:对每个命令的执行结果进行检查,并将输出和错误记录到日志文件中。这有助于调试和跟踪进度。

1
2
3
4
5
fastp -i ${SRR}_1.fastq -I ${SRR}_2.fastq -o ${SRR}_1_trimmed.fastq -O ${SRR}_2_trimmed.fastq >> ${SRR}_fastp.log 2>&1
if [ $? -ne 0 ]; then
echo "fastp failed for ${SRR}, see ${SRR}_fastp.log for details."
continue
fi
  • 资源管理:如果在资源受限的环境下运行,考虑限制并行任务的数量,或者根据工具的文档调整每个工具的资源使用(如内存和CPU)。

记得在运行脚本前,根据实际路径和环境调整其中的路径和参数设置。希望这些建议能帮助你优化脚本,提高数据处理的效率和稳定性。

在您提供的代码中,使用到了以下软件和工具:

  1. Hisat2 - 可以从设置的 hisat2_index 变量推断出,Hisat2 用于比对,构建了索引路径。
  2. HTSeq - 在代码中使用 htseq-count 命令来计数基因表达,用于RNA-seq数据分析。
  3. StringTie - 使用了 stringtie 命令来估算转录本丰度和合并转录本,这是处理 RNA-seq 数据的常用工具。
  4. prepDE.py - 用于生成基因和转录本计数矩阵的 Python 脚本,通常与 StringTie 输出文件一起使用。
  5. getTPM.pygetFPKM.py - 这些脚本可能用于从 RNA-seq 数据中计算 TPM(Transcripts Per Million)和 FPKM(Fragments Per Kilobase of transcript per Million mapped reads),尽管这些脚本并非广为人知的标准工具,可能是自定义或特定实验室内部使用的脚本。

以上列出的软件都是生物信息学领域常用的工具,主要应用于高通量测序数据的处理和分析。

在你提供的 RNA-seq 数据分析流程中,我们可以探讨哪些步骤具有 Windows 可执行文件(EXE)版本的软件工具。

步骤1: 下载数据

  • SRA Toolkit: 有 Windows 版本。SRA Toolkit 提供了一个 fastq-dump 的 EXE 文件,允许用户在 Windows 系统上直接运行这些命令。

步骤2: 质量控制

  • FastQC: FastQC 有一个图形用户界面(GUI)和命令行版本,均提供 Windows 版本。
  • Trimmomatic: 没有官方提供的 EXE 文件,这是一个 Java 程序,所以在任何安装了 Java 的操作系统上运行。
  • fastp: 不提供 Windows EXE 版本,通常在 Linux 或通过 WSL 在 Windows 上运行。

步骤3: 读段比对

  • HISAT2: 如之前讨论,HISAT2 提供 Windows 的 EXE 版本。
  • STAR: 不提供 Windows EXE 版本,需要通过 WSL 或虚拟机在 Windows 上运行。
  • Bowtie2: 也有 Windows 版本,可以直接在 Windows 上使用。

步骤4: 计算FPKM

  • StringTie: 没有 Windows EXE 版本,需要通过 WSL 或虚拟机来运行。
  • Cufflinks: 旧版本有 Windows 支持,但新版本的使用可能需要通过 WSL。

步骤5: log2转换

  • 这一步通常使用 R语言 完成,R及其各种包均提供了 Windows 版本。

总结

在你的流程中,如 SRA Toolkit、FastQC、HISAT2 和 Bowtie2 提供了 Windows 可执行文件,可以直接在 Windows 系统中使用。而其他步骤如 Trimmomatic(需要 Java)、fastp、STAR、StringTie 及 Cufflinks(较新版本)则可能需要借助 WSL 或其他方法在 Windows 上运行。对于基本的数据处理和统计分析,R 语言提供了全面的 Windows 支持。

Hisat2
http://www.di.fc.ul.pt/~afalcao/hisat2_windows.html

Trimmomatic
https://github.com/usadellab/Trimmomatic/releases


文章作者: 花粱
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 花粱 !
  目录