-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunv4-align.sh
More file actions
124 lines (108 loc) · 3.54 KB
/
Copy pathrunv4-align.sh
File metadata and controls
124 lines (108 loc) · 3.54 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
# RNA-seq Analysis Pipeline v3.1 with UMI processing
# Parameter parsing
usage() {
echo "Usage: $0 {h|m|r} [options]"
echo "Options:"
echo " --r1 FILE Read1 input (default: input/r1.fq.gz)"
echo " --r2 FILE Read2 input (default: input/r2.fq.gz)"
echo " --sample FILE Sample-barcode mapping (default: input/sample.csv)"
echo " --metadata FILE Metadata file (default: input/metadata.csv)"
exit 1
}
# Defaults
species=$1
shift
r1="input/r1.fq.gz"
r2="input/r2.fq.gz"
sample="input/sample.csv"
metadata="input/metadata.csv"
# Parse options
while [[ $# -gt 0 ]]; do
case "$1" in
--r1) r1="$2"; shift 2 ;;
--r2) r2="$2"; shift 2 ;;
--sample) sample="$2"; shift 2 ;;
--metadata) metadata="$2"; shift 2 ;;
*) echo "Unknown option: $1"; usage ;;
esac
done
# Species index
case $species in
h) index="genome/human/index" ;;
m) index="genome/mouse/index" ;;
r) index="genome/rat/index" ;;
*) echo "Invalid species: $species"; exit 1 ;;
esac
case $species in
h) gtf="genome/human/gtf/h.gtf.gz" ;;
m) gtf="genome/mouse/gtf/m.gtf.gz" ;;
r) gtf="genome/rat/gtf/r.gtf.gz" ;;
*) echo "Invalid species: $species"; exit 1 ;;
esac
# 4. Alignment with STAR
echo "Aligning..."
mkdir -p output/aligned
STAR --genomeLoad LoadAndExit --genomeDir $index
rm -r /home/dingqi/3rnaseq/STARtemp/temp
for r1_file in output/trimmed/*_R1.fastq; do
base=$(basename "$r1_file" _R1.fastq)
outdir="output/aligned/$base"
mkdir -p "$outdir"
#mkdir -p STAR_temp # Generate temp dir
STAR \
--runThreadN 40 \
--genomeLoad LoadAndKeep \
--genomeDir $index \
--readFilesIn $r1_file \
--outTmpDir /home/dingqi/3rnaseq/STARtemp/temp \
--outFilterType BySJout \
--outFilterMultimapNmax 200 \
--alignSJoverhangMin 8 \
--alignSJDBoverhangMin 1 \
--outFilterMismatchNmax 999 \
--outFilterMismatchNoverLmax 0.6 \
--outFilterScoreMinOverLread 0 \
--outFilterMatchNminOverLread 0 \
--outFilterMatchNmin 0 \
--alignIntronMin 20 \
--alignIntronMax 1000000 \
--alignMatesGapMax 1000000 \
--outSAMtype BAM SortedByCoordinate \
--outSAMattributes NH HI NM MD \
--limitIObufferSize 200000000 200000000 \
--limitOutSJcollapsed 5000000 \
--limitBAMsortRAM 90000000000 \
--outFileNamePrefix "$outdir/${base}_";
rm -r /home/dingqi/3rnaseq/STARtemp/temp;
done
STAR --genomeLoad Remove --genomeDir "$index"
# 5. UMI Deduplication
echo "Deduplicating UMIs..."
for bam_file in output/aligned/*/*_Aligned.sortedByCoord.out.bam; do
dir=$(dirname "$bam_file")
base=$(basename "$bam_file" _Aligned.sortedByCoord.out.bam)
samtools index "$bam_file"
umi_tools dedup \
--stdin "$bam_file" \
--stdout "$dir/${base}_dedup.bam" \
--method unique \
--per-cell \
samtools index "$dir/${base}_dedup.bam"
done
# 6. Quantification
echo "Counting reads..."
for bam_file in output/aligned/*/*_dedup.bam; do
dir=$(dirname "$bam_file")
base=$(basename "$bam_file" _dedup.bam)
htseq-count \
--format bam \
"$bam_file" \
"$gtf" \
> "$dir/${base}_counts.tab"
done
# 7. Downstream analysis (uncomment when ready)
Rscript countsV3.R "$species" "$metadata"
Rscript 3RNA_analyzer.R "output/analysis/counts/counts.matrix.txt" "$metadata" "$species" "output/analysis"
Rscript upstream_analysis_summary.R "$metadata" "$sample"
echo "Pipeline completed!"