TITLE: RatGTEx pipeline
AUTHORS: Daniel  Munro, Laura M Saba, Hao Chen, Abraham  Palmer, Pejman Mohammadi

[DESCRIPTION]
This is the pipeline used to process data for the RatGTEx Portal. It is loosely based on the GTEx eQTL mapping pipeline, though it includes some utility scripts from there in their entirety. All code for this pipeline can be found in the repository. It is built on Snakemake, a Python-based framework for reproducible data analysis. The commands reproduced here use Snakemake-style templating, with variables in brackets to represent different input/output file names and parameters.

[STEPS]
SECTION: Align RNA-Seq reads
1. Generate the index for STAR.
 

 

SECTION: Align RNA-Seq reads
3. Align RNA-Seq reads for a sample using STAR.
 

 

SECTION: Align RNA-Seq reads
2. Get an individual-specific VCF file. This is used by STAR to consider the individual's variants for better alignment.

 

 

SECTION: Identify and correct sample mixups
4. Get all exon regions from gene annotations.

 

SECTION: Identify and correct sample mixups
5. Subset genotypes to only exon SNPs, SNPs with MAF >= 0.2, and SNPs with <10% missing values.

 

 

 

 



SECTION: Identify and correct sample mixups
6. Count reads with REF vs. ALT allele in a sample for each SNP.
 

 

SECTION: Identify and correct sample mixups
7. Compare similarity of genotypes and allele counts from RNA-Seq to identify mixups.

qc_rna_to_geno_similarity.py

Produces a matrix of RNA-Seq samples x VCF individuals giving similarity across the test SNPs. Similarity is mean(1 - abs(RNA_frac - geno_frac)), where RNA_frac is fraction of reads with ALT allele for each SNP, and geno_frac is fraction of DNA strands with ALT allele (i.e. 0, 0.5, or 1) for each SNP. Also produces a summary table with top similarity per RNA-Seq sample to quickly check for mismatches.
SECTION: Identify and correct sample mixups
8. For samples without a genotype match, check for matches in all rats.

qc_rna_to_geno_all_rats.py

After running the previous step, some mismatched RNA samples might still not have a genotype match. This rule will compare their test SNPs to those of all 6000+ rats we have genotypes for to see if any match. It's good to also include at least one RNA sample ID that did match as a positive control (as long as it's included in the all-rat VCF).
SECTION: Identify and correct sample mixups
9. Examine the outputs to identify samples that need to be relabeled (e.g. if two labels get swapped) or removed.

To relabel a sample, edit the ID in the 2nd column of fastq_map.txt for all of its FASTQ files so that its BAM file gets labeled correctly. You'll then need to regenerate the BAM file since it will now use the correct VCF individual as input to STAR.
To remove a sample, remove its ID from rat_ids.txt and delete its BAM and any other generated files.

If a match is found with a rat outside the current dataset in the previous step, you'll need to add the new matching genotypes to the VCF file. However, if the matching genotypes differ greatly from the current dataset, e.g. they include a very different set of SNPs, it may be better to just remove the sample.
SECTION: Quantify gene expression
10. Generate the index for RSEM.

 

 

SECTION: Quantify gene expression
11. Quantify expression from a BAM file.

 

 

 

 

SECTION: Quantify gene expression
12. Combine all isoforms of a gene into a single transcript.

collapse_annotation.py

Originally used in the GTEx pipeline.

 

SECTION: Quantify gene expression
13. Combine RSEM output from all samples into log-count and TPM expression tables.

assemble_expression.py

Also computes inverse-quantile normalized values to use for eQTL mapping. The filtered version is to avoid a tensorQTL error on phenotypes with 1 nonzero value.

 

 

 

 

SECTION: Map eQTLs
14. Get SNPs with sufficient variation in a given set of samples and convert VCF to plink.

 

 

SECTION: Map eQTLs
15. Prune genotypes to compute covariate PCs.

--indep-pairwise parameters are based on GTEx methods.

 

 

 

SECTION: Map eQTLs
16. Compute genotype (n=5) and expression (n=20) PCs and combine into covariates table.
 
covariates.R

 

SECTION: Map eQTLs
17. Map cis-eQTLs, determining significance using permutations.

Outputs the top association per gene. This script calls tensorQTL and uses the random_tiebreak parameter, which is important for outbred populations in which there are often multiple top eSNPs in 100% LD. Without the random tiebreak, the first or last tied top SNP is returned, resulting in positional bias.

 
run_tensorqtl.py
 

SECTION: Map eQTLs
18. Use stepwise regression to identify multiple conditionally independent cis-eQTLs per gene.

 

 

SECTION: Map eQTLs
19. Get summary statistics for all tested cis-window SNPs per gene.

 

 

SECTION: Map eQTLs
20. Map trans-eQTLs.

 

 

SECTION: Map eQTLs
21. Extract all significant cis SNP-gene pairs.

tensorqtl_all_signif.py

 

SECTION: Map eQTLs
22. Extract p-values for all tested cis-window SNPs per gene.

tensorqtl_all_cis_pvals.py

 

SECTION: Map eQTLs
23. Get effect size (allelic fold change) for top association per gene and all significant cis-eQTLs.

 

prepare_qtl_for_afc.py