Skip to content

Commit c791048

Browse files
committed
add scripts
1 parent e120b54 commit c791048

5 files changed

Lines changed: 173 additions & 14 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

docs/1_pipeline_setup/2_database.md

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,50 @@ parent: Pipeline Setup
77

88
## Part II: Database Preparation
99

10-
In addition to the tools and dependencies, you will also need to prepare **databases for reference genomes** which will be used in alignment, quantification and QC assessment.
10+
In addition to installiing the necessary tools and dependencies, you will also need to prepare **reference genome databases** for use in alignment, quantification and QC assessment.
1111

12-
In this pipeline, we manage the databases in **one database per reference genome** manner. Below is an overview of database preparation (use hg38 as an example):
12+
For this pipeline, each reference genome assembly has its own dedicated database folder. Below is an overview of the database preparation process and key inputs and outputs of each step:
1313

1414
![Picture](../figures/database_preparation.png)
1515

1616
1. **Data collection**
1717

18-
There are **FOUR** files required in dataset preparation, and three of them can be directly downloaded from websites:
18+
There are **FOUR** files required for database preparation. Three of them can be directly downloaded from online resources:
1919

20-
- **<u>*annotation.gtf*</u>**: **Gene Annotation file in [GTF](https://biocorecrg.github.io/PhD_course_genomics_format_2021/gtf_format.html) (Gene Transfer Format) format**
20+
- **<u>*annotation.gtf*</u>**: Gene Annotation file in [GTF](https://biocorecrg.github.io/PhD_course_genomics_format_2021/gtf_format.html) (Gene Transfer Format) format.
2121

22+
- ***<u>transcriptome.fa</u>***: Transcriptome sequence file in [FASTA](https://www.ncbi.nlm.nih.gov/genbank/fastaformat/) format
2223

23-
- ***<u>transcriptome.fa</u>***: **Transcriptome sequence file in [FASTA](https://www.ncbi.nlm.nih.gov/genbank/fastaformat/) format**
24+
- ***<u>genome.fa</u>***: Genome sequence file in [FASTA](https://www.ncbi.nlm.nih.gov/genbank/fastaformat/) format
2425

25-
- ***<u>genome.fa</u>***: **Genome sequence file in [FASTA](https://www.ncbi.nlm.nih.gov/genbank/fastaformat/) format**
26+
```bash
27+
# locate to your conda env, change the path accordingly
28+
cd /research_jude/rgs01_jude/groups/yu3grp/projects/software_JY/yu3grp/conda_env/bulkRNAseq_2025
29+
30+
# create and change to the database folder
31+
mkdir -p pipeline/databases/hg38/gencode.release48 # for annotation release 48 for hg38
32+
cd pipeline/databases/hg38/gencode.release48
33+
34+
# download the three files from https://www.gencodegenes.org/human/release_48.html
35+
wget https://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_48/gencode.v48.primary_assembly.annotation.gtf.gz
36+
wget https://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_48/gencode.v48.transcripts.fa.gz
37+
wget https://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_48/GRCh38.primary_assembly.genome.fa.gz
38+
39+
# decompress them
40+
gunzip *
41+
42+
# rename them
43+
mv gencode.v48.primary_assembly.annotation.gtf annotation.gtf
44+
mv gencode.v48.transcripts.fa.gz transcripts.fa
45+
mv GRCh38.primary_assembly.genome.fa.gz genome.fa
46+
```
2647

27-
***<u>NOTE:</u>*** For human and mouse, we recommend [GENCODE](https://www.gencodegenes.org/) to download them, while for other species, we recommend [Ensembl](https://useast.ensembl.org/info/data/ftp/index.html).
48+
***<u>NOTE:</u>*** For the three files listed above, we recommend downloading them from [GENCODE](https://www.gencodegenes.org/) for human and mouse. For other species, we suggest using [Ensembl](https://useast.ensembl.org/info/data/ftp/index.html).
2849

2950
- ***<u>HouseKeeping gene list</u>***: the housekeeping genes defined by [this study](https://www.sciencedirect.com/science/article/pii/S0168952513000899?via%3Dihub) (N = 3804).
3051

31-
52+
***<u>NOTE:</u>*** For human, the list of housekeeping genes can be downloaded [here](https://github.com/jyyulab/bulkRNAseq_quantification_pipeline/blob/main/databases/housekeepingGenes_human.txt). For other species, you can generate the housekeeping gene list by gene homology conversion using BiomaRt or other tools. Below is the codes we used to generate the housekeeping genes for mouse (avaibale [here](https://github.com/jyyulab/bulkRNAseq_quantification_pipeline/blob/main/databases/housekeepingGenes_mouse.txt)):
3253

33-
***<u>NOTE:</u>*** For human, the housekeeping genes can be downloaded [here](https://github.com/jyyulab/bulkRNAseq_quantification_pipeline/blob/main/databases/housekeepingGenes_human.txt); While for other species, you can generate the housekeeping gene list by gene homology conversion using BiomaRt or other tools. Below is the codes I used to generate the housekeeping genes in mouse (avaibale [here](https://github.com/jyyulab/bulkRNAseq_quantification_pipeline/blob/main/databases/housekeepingGenes_mouse.txt)):
34-
3554
``` R
3655
library(NetBID2)
3756
@@ -47,12 +66,12 @@ In this pipeline, we manage the databases in **one database per reference genome
4766

4867
2. **Parsing annotation file**
4968

50-
In this step, we will parse the gene annotation file and generate four files that required in downstream analysis:
69+
In this step, we will parse the gene annotation file to generate four files required for downstream analysis:
5170

52-
- **`annotation.gene2transcript.txt`** & **`annotation.transcript2gene.txt`**: mappings between transcripts and genes. They are required in gene-level quantification.
53-
- **`annotation.geneAnnotation.txt`** & **`annotation.transcriptAnnotation.txt`**: annotation files for genes and transcripts. They are required in the final gene expression matrix generation.
71+
- **`annotation.gene2transcript.txt`** & **`annotation.transcript2gene.txt`**: These files provide mappings between transcripts and genes, which are necessary for gene-level quantification.
72+
- **`annotation.geneAnnotation.txt`** & **`annotation.transcriptAnnotation.txt`**: These files contain detailed annotations for genes and transcripts, and are used in generating the final gene expression matrix.
5473

55-
To make the parsing analysis easiler, we created a script, **`parseAnnotation.pl`**, that you can easily generate the four files with it:
74+
To simplify this process, we have provided a script, **`parseAnnotation.pl`**, which allows you to easily generate all four filest:
5675

5776
``` bash
5877
## parse the gene anotation file

scripts/.DS_Store

6 KB
Binary file not shown.

scripts/setup/createBins.pl

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use warnings;
5+
use File::Path qw(make_path);
6+
7+
## We take the longest transcript to present each gene. The genes of which the longest transcript is less than 300nt were excluded.
8+
9+
if (@ARGV == 3) {
10+
if (-e $ARGV[0]) { unless ($ARGV[0] =~ /\.fa$/ig) { print "ERROR: The transcriptome sequence file, $ARGV[0], must be in FASTA format, and the file name much be ended with '.fa'.\n"; die; }
11+
} else { print "ERROR: The transcriptome sequence file, $ARGV[0], doesn't exist. Please check and retry.\n"; die; }
12+
unless (-e $ARGV[1]) { print "ERROR: The housekeeping gene file, $ARGV[1], doesn't exist. Please check and retry.\n"; die; }
13+
unless (-d $ARGV[2]) { print "The output directory, $ARGV[2], doesn't exist. We are generating it...\n"; make_path($ARGV[2]); }
14+
} else {
15+
print "ERROR: Please use THREE arguments to specify 1) transcriptome sequence file, 2) housekeeping gene file, 3) directory to save output files, respectively.\n\n\tperl prepareBins.pl xxx.transcripts.fa housekeeping_genes.xxx.txt ./bulkRNAseq/genebodyBins\n\n"; die;
16+
}
17+
18+
my $input_gtf = $ARGV[0];
19+
my $input_hk = $ARGV[1];
20+
my $outout_dir = $ARGV[2];
21+
22+
open (REF, $input_gtf) or die;
23+
print "We are paring $input_gtf ...\n";
24+
my %ref = ();
25+
while (<REF>) {
26+
chomp;
27+
next unless ($_ =~ /^>ENS/);
28+
my @F = split(/\|/, $_);
29+
next if ($F[6] < 300);
30+
$F[0] =~ /^>(.+)/; my $isoform = $1;
31+
if (exists $ref{$F[5]}) {
32+
for my $x (sort keys %{$ref{$F[5]}}) {
33+
if ($ref{$F[5]}{$x} > $F[6]) {
34+
next;
35+
}
36+
else {
37+
delete $ref{$F[5]}{$x};
38+
$ref{$F[5]}{$isoform} = $F[6];
39+
}
40+
}
41+
}
42+
else {
43+
$ref{$F[5]}{$isoform} = $F[6];
44+
}
45+
}
46+
close REF;
47+
48+
my %hk_genes = ();
49+
open (HK, $input_hk) or die;
50+
print "We are collecting housekeeping genes from $input_hk ...\n";
51+
while (<HK>) {
52+
chomp;
53+
next if ($_ =~ /^#/);
54+
my @HK = split(/\t/, $_);
55+
$hk_genes{$HK[0]}++;
56+
}
57+
close HK;
58+
59+
open (OUT1, "> $outout_dir/genebodyBins_all.txt") or die;
60+
open (OUT2, "> $outout_dir/genebodyBins_housekeeping.txt") or die;
61+
print "We are writing the outputs ...\n";
62+
for my $x (sort keys %ref) {
63+
for my $y (sort keys %{$ref{$x}}) {
64+
my $length = $ref{$x}{$y};
65+
my $width = $length / 100;
66+
67+
for my $i (0 .. 99) {
68+
my $start = int($width * $i) + 1;
69+
my $end = int($width * ($i + 1));
70+
$end = $length if ($end > $length);
71+
my $k = $i + 1;
72+
print OUT1 "$y\t$start\t$end\t$x\|Bin$k\n";
73+
print OUT2 "$y\t$start\t$end\t$x\|Bin$k\n" if (exists($hk_genes{$x}));
74+
}
75+
}
76+
}
77+
close OUT1; close OUT2;
78+
print "Done!\n";

scripts/setup/parseAnnotation.pl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use warnings;
5+
6+
if (@ARGV == 1) {
7+
unless (-e $ARGV[0]) {
8+
print "ERROR: The INPUT file doesn't exist. Please check and retry.\n"; die;
9+
}
10+
} elsif (@ARGV < 1) {
11+
print "ERROR: Please specify the gene annotation file to parse!\n\n\tperl parseAnnotation.pl xxx.annotation.gtf\n\n"; die;
12+
} else {
13+
print "ERROR: Please use only ONE argument which specifies the gene annotation file to parse!\n\n\tperl parseAnnotation.pl xxx.annotation.gtf\n\n"; die;
14+
}
15+
16+
my $f_input = $ARGV[0];
17+
if ($f_input =~ /\.gtf$/ig) {
18+
print "We are parsing $f_input ...\n";
19+
20+
open (IN, $f_input) or die;
21+
my %tr = (); my %gene = (); my %tr2gene = (); my %gene2tr = (); my %hash = ();
22+
while (<IN>) {
23+
chomp;
24+
next if ($_ =~ /^#/);
25+
my @F = split(/\t/, $_);
26+
next unless ($F[2] eq "transcript");
27+
$F[8] =~ /gene_id "(ENS.+)"; transcript_id "(ENS.+)"; gene_type "(\w+)";.* gene_name "(.+)"; transcript_type "(\w+)";.* transcript_name "(.+)"; level /;
28+
$tr{$2} = "$2\t$6\t$5\t$1\t$4";
29+
$gene{$1} = "$1\t$4\t$3";
30+
$tr2gene{$2} = "$2\t$1"; $gene2tr{$2} = "$1\t$2"; $hash{$2} = "$2\t$6\t$1\t$4";
31+
}
32+
close IN;
33+
34+
print "We are writing the outputs ...\n";
35+
(my $f_output = $f_input) =~ s/\.gtf$//g;
36+
open (OUT1, "> $f_output.transcriptAnnotation.txt") or die;
37+
print OUT1 "transcript_id\ttranscript_name\ttranscript_type\tgene_id\tgene_name\n";
38+
for my $x (sort keys %tr) {
39+
print OUT1 "$tr{$x}\n";
40+
}
41+
close OUT1;
42+
43+
open (OUT2, "> $f_output.geneAnnotation.txt") or die;
44+
print OUT2 "gene_id\tgene_name\tgene_type\n";
45+
for my $x (sort keys %gene) {
46+
print OUT2 "$gene{$x}\n";
47+
}
48+
close OUT2;
49+
50+
open (OUT3, "> $f_output.transcript2gene.txt") or die;
51+
open (OUT4, "> $f_output.gene2transcript.txt") or die;
52+
for my $x (sort keys %hash) {
53+
print OUT3 "$tr2gene{$x}\n";
54+
print OUT4 "$gene2tr{$x}\n";
55+
}
56+
close OUT3; close OUT4;
57+
print "Done!\n";
58+
}
59+
else {
60+
print "ERROR: The INPUT file must be in GTF(Gene Transfer Format) format, and the file name much be ended with '.gtf' or '.GTF'.\n";
61+
}
62+

0 commit comments

Comments
 (0)