# # Airway RNA-Seq from the Biostar Handbook # # http://www.biostarhandbook.com # # The design matrix DESIGN = airway.csv # The default SRR accession number SRR = SRR1039508 # The default sample name SAMPLE = Ctrl_N61311 # How many reads to download # Start with 5 million reads N ?= 5000000 # The number of CPUs to use. NCPU ?= 2 # The name of this Makefile MAKE_FILE = $(lastword $(MAKEFILE_LIST)) # The URL for the Human transcriptome. FASTA_URL = https://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_50/GRCh38.p14.genome.fa.gz # The name of the genome FASTA file. FASTA = fasta/GRCh38.p14.genome.fa # The base name of the genome index file. FASTA_IDX_BASE = fasta/idx/$(notdir ${FASTA}) # A file in the index directory FASTA_IDX = ${FASTA_IDX_BASE}.1.ht2 # The URL for the Human gene annotation. GTF_URL = https://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_50/gencode.v50.chr_patch_hapl_scaff.basic.annotation.gtf.gz # The name of the gene annotation file locally. GTF = gtf/gencode.v50.basic.annotation.gtf.gz # Read 1 file R1 = fastq/${SAMPLE}_1.fastq # Read 2 file R2 = fastq/${SAMPLE}_2.fastq # The alignment BAM file BAM = bam/${SAMPLE}.bam # The coverage bigwig file BW = bw/${SAMPLE}.bw # featureCounts output are text files COUNTS = counts/${SAMPLE}.txt # Summarized gene counts GENE_COUNTS = csv/gene_counts.csv # Differential expression analysis results DIFF_EXPR = csv/differential_expression.csv # PCA plot PCA_PLOT = pdf/pca.pdf # Flags we pass to parallel in each invocation FLAGS = -v --eta --colsep , --header : -j ${NCPU} --lb # # Makefile settings to make it more robust # SHELL := bash .SHELLFLAGS := -eu -o pipefail -c MAKEFLAGS += --warn-undefined-variables --no-print-directory .DELETE_ON_ERROR: # This is required for the automatic design matrix generation. .ONESHELL: # Detect Makefile version. MAKE_MAJOR := $(firstword $(subst ., ,$(MAKE_VERSION))) HASH := \# # Check that the GNU make version is 4 or higher. ifneq ($(firstword $(sort 4 $(MAKE_MAJOR))),4) $(info $(HASH) This Makefile needs make version 4 or higher.) $(info $(HASH) Activate the bioinfo environment.) $(error Stop.) endif # Print usage by default usage: @echo "#" @echo "# Airway RNA-Seq workflow in the Biostar Handbook" @echo "#" @echo "# See: https://www.biostarhandbook.com/" @echo "#" @echo "# Parameters:" @echo "#" @echo "# FASTA=${FASTA}" @echo "# GTF=${GTF}" @echo "# DESIGN=${DESIGN} " @echo "#" @echo "# Usage:" @echo "#" @echo "# make design # generates the design matrix" @echo "# make genome # download Human reference genome" @echo "# make fastq # downloads the fastq files" @echo "# make align # performs slamon quantification" @echo "#" @echo "# make all # runs all the steps above" @echo "#" # Download and unzip the reference genome. ${FASTA}: mkdir -p $(dir ${FASTA}) curl ${FASTA_URL} | gunzip -c > ${FASTA} samtools faidx ${FASTA} # Sort the GTF file by chromosome and start position. ${GTF}: mkdir -p $(dir ${GTF}) curl ${GTF_URL} | gunzip -c | LC_ALL=C sort -t "$$(printf '\t')" -k1,1 -k4,4n | bgzip -c > ${GTF} tabix -p gff ${GTF} # Trigger the reference indexing. genome: ${FASTA} ${GTF} ls -l ${FASTA} ls -l ${GTF} # Download the fastq files. ${R1} ${R2}: mkdir -p $(dir ${R1}) fastq-dump -X ${N} --split-3 ${SRR} -O $(dir ${R1}) mv $(dir ${R1})/${SRR}_1.fastq ${R1} mv $(dir ${R1})/${SRR}_2.fastq ${R2} # Show the fastq files. fastq: ${R1} ${R2} ls -lh ${R1} ls -lh ${R2} # The index file ${FASTA_IDX}: ${FASTA} mkdir -p $(dir ${FASTA_IDX}) hisat2-build ${FASTA} ${FASTA_IDX_BASE} # Show the index file. index: ${FASTA_IDX} ls -lh ${FASTA_IDX} # The rules to generate the BAM file ${BAM}: ${FASTA_IDX} ${R1} mkdir -p $(dir ${BAM}) hisat2 --threads ${NCPU} --sensitive -x ${FASTA_IDX_BASE} -1 ${R1} -2 ${R2} | \ samtools sort -@ ${NCPU} --write-index -o ${BAM} # Show the BAM and bigwig files. align: ${BAM} ls -lh ${BAM} # The rules to generate the bigwig file ${BW}: ${BAM} mkdir -p $(dir ${BW}) bamCoverage -p 4 --binSize 1 -b ${BAM} -o ${BW} # Show the bigwig file. coverage: ${BW} ls -lh ${BW} # Count reads overlapping genes. ${COUNTS}: ${BAM} ${GTF} mkdir -p $(dir $@) featureCounts -p --countReadPairs -a ${GTF} -s 2 -o ${COUNTS} ${BAM} counts: ${COUNTS} ls -lh ${COUNTS} # Create the design matrix. ${DESIGN}: @cat << EOF > ${DESIGN} srr,group,celltype,sample SRR1039508,Ctrl,N61311,Ctrl_N61311 SRR1039512,Ctrl,N052611,Ctrl_N052611 SRR1039516,Ctrl,N080611,Ctrl_N080611 SRR1039520,Ctrl,N061011,Ctrl_N061011 SRR1039509,Dex,N61311,Dex_N61311 SRR1039513,Dex,N052611,Dex_N052611 SRR1039517,Dex,N080611,Dex_N080611 SRR1039521,Dex,N061011,Dex_N061011 EOF @echo "# Created airway design: ${DESIGN}" # This code is explained in the Biostar Handbook. ${GENE_COUNTS}: ${COUNTS} mkdir -p $(dir $@) Rscript src/combine_gene_counts.r -d ${DESIGN} -g ${GTF} -o ${GENE_COUNTS} Rscript src/edger.r -d ${DESIGN} -c ${GENE_COUNTS} -o csv/edger.csv gene_counts: ${GENE_COUNTS} ls -lh ${GENE_COUNTS} ls -lh ${DIFF_EXPR} plot: Rscript src/pca.r -d ${DESIGN} -c ${GENE_COUNTS} --color_by group -o pdf/pca-group.pdf Rscript src/pca.r -d ${DESIGN} -c ${GENE_COUNTS} --color_by celltype -o pdf/pca-celltype.pdf # Show the design matrix. design: ${DESIGN} ls -lh ${DESIGN} # Run all steps at once. all: design genome index fastq align coverage counts # Execute the batch workflow batch: ${DESIGN} # Run the workflow for one sample to check all steps. make -f ${MAKE_FILE} all # Run the workflow for all samples. cat ${DESIGN} | parallel -j ${NCPU} ${FLAGS} make -f ${MAKE_FILE} SRR={srr} SAMPLE={sample} all # Current directory DIR = $(shell pwd) # Netcat command to send commands to IGV NC = nc localhost 60151 # Visualize with IGV igv: echo "new" | ${NC} echo "genome ${DIR}/$(FASTA)" | ${NC} echo "load ${DIR}/$(GTF)" | ${NC} # Load all bigwig files cat ${DESIGN} | parallel -j 1 ${FLAGS} 'echo "load ${DIR}/bw/{sample}.bw" | ${NC}' # Targets that are not files .PHONY: usage data genome fastq align coverage all batch igv