-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRNA_COVERAGE.sh
More file actions
74 lines (62 loc) · 2.14 KB
/
Copy pathRNA_COVERAGE.sh
File metadata and controls
74 lines (62 loc) · 2.14 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
#!/bin/bash
# Usage:
# ./RNA_COVERAGE.sh SAMPLE_NAME FILTERED_BAM STAR_INDEX_DIR CHROM_SIZES OUTDIR THREADS
set -euo pipefail
if [[ $# -lt 6 ]]; then
echo "Usage: $0 SAMPLE_NAME FILTERED_BAM STAR_INDEX_DIR CHROM_SIZES OUTDIR THREADS" >&2
exit 1
fi
sample_name="${1}"
INBAM="${2}"
path_refDB="${3}"
path_refCHROMSIZES="${4}"
outdir="${5}"
threads="${6}"
STAR_BIN="${STAR_BIN:-STAR}"
BEDGRAPH_TO_BIGWIG_BIN="${BEDGRAPH_TO_BIGWIG_BIN:-bedGraphToBigWig}"
if [[ ! -d "${path_refDB}" ]]; then
echo "ERROR: STAR index directory missing: ${path_refDB}" >&2
exit 1
fi
if [[ ! -s "${path_refCHROMSIZES}" ]]; then
echo "ERROR: chromosome sizes file missing or empty: ${path_refCHROMSIZES}" >&2
exit 1
fi
if [[ ! -s "${INBAM}" ]]; then
echo "ERROR: Input filtered BAM missing or empty: ${INBAM}" >&2
exit 1
fi
echo "Using STAR_BIN=${STAR_BIN}"
echo "Using BEDGRAPH_TO_BIGWIG_BIN=${BEDGRAPH_TO_BIGWIG_BIN}"
echo "Using STAR index directory=${path_refDB}"
echo "Using chromosome sizes=${path_refCHROMSIZES}"
"${STAR_BIN}" \
--runMode inputAlignmentsFromBAM \
--runThreadN "${threads}" \
--genomeDir "${path_refDB}" \
--inputBAMfile "${INBAM}" \
--outWigType bedGraph \
--outWigStrand Stranded \
--outWigNorm RPM \
--outWigReferencesPrefix chr \
--outFileNamePrefix "${outdir}/${sample_name}.stranded_"
"${STAR_BIN}" \
--runMode inputAlignmentsFromBAM \
--runThreadN "${threads}" \
--genomeDir "${path_refDB}" \
--inputBAMfile "${INBAM}" \
--outWigType bedGraph \
--outWigStrand Unstranded \
--outWigNorm RPM \
--outWigReferencesPrefix chr \
--outFileNamePrefix "${outdir}/${sample_name}.unstranded_"
for f in "${outdir}/${sample_name}.stranded_Signal.Unique.str"*.bg; do
sort -k1,1 -k2,2n "$f" > "${f%.bedGraph}.sorted.bg"
"${BEDGRAPH_TO_BIGWIG_BIN}" "${f%.bedGraph}.sorted.bg" "${path_refCHROMSIZES}" "${f%.bg}.bw"
done
for f in "${outdir}/${sample_name}.unstranded_Signal.Unique.str"*.bg; do
sort -k1,1 -k2,2n "$f" > "${f%.bedGraph}.sorted.bg"
"${BEDGRAPH_TO_BIGWIG_BIN}" "${f%.bedGraph}.sorted.bg" "${path_refCHROMSIZES}" "${f%.bg}.bw"
done
rm -f "${outdir}/${sample_name}"*.bg \
"${outdir}/${sample_name}"*.bg