-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpatialPath.sh
executable file
·87 lines (72 loc) · 2.67 KB
/
SpatialPath.sh
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
#!/bin/bash
source "$(conda info --base)/etc/profile.d/conda.sh"
conda activate SpatialPath_v0.1 || { echo "Failed to activate conda environment"; exit 1; }
# Default values
threads=1
input_folder=""
species=""
spatialpath_dir=""
# Usage function to display help message
usage() {
echo "Usage: $0 -t <threads> -i <input_folder> -s <species> -p <spatialpath_directory> [-h]"
echo ""
echo "Options:"
echo " -t Number of threads (default: 1)"
echo " -i Input folder (required, output of spaceranger)"
echo " -s Species (mouse or human, required)"
echo " -p Path to spatialpath installation directory (required)"
echo " -h Display this help message"
echo ""
exit 0
}
# Parse command-line options
while getopts "t:i:s:p:h" opt; do
case ${opt} in
t) threads=${OPTARG} ;;
i) input_folder=${OPTARG} ;;
s) species=${OPTARG} ;;
p) spatialpath_dir=${OPTARG} ;;
h) usage ;;
*) usage ;;
esac
done
# Check if required options are provided
if [[ -z "$input_folder" || -z "$species" || -z "$spatialpath_dir" ]]; then
echo "Error: Input folder, species, and spatialpath directory are required."
usage
fi
# Validate species input
if [[ "$species" != "mouse" && "$species" != "human" ]]; then
echo "Error: Species must be either 'mouse' or 'human'."
usage
fi
# Select GTF file based on species
gtf_file=""
if [[ "$species" == "mouse" ]]; then
gtf_file="$spatialpath_dir/references/Mus_musculus.GRCm38.113.gtf"
elif [[ "$species" == "human" ]]; then
gtf_file="$spatialpath_dir/references/Homo_sapiens.GRCh38.113.gtf"
fi
# Print settings for confirmation
echo "Running SpatialPath with the following parameters:"
echo " Threads: $threads"
echo " Input Folder: $input_folder"
echo " Species: $species"
echo " GTF File: $gtf_file"
echo " SpatialPath Directory: $spatialpath_dir"
# Generate barcodes_in_tissue.csv
awk 'BEGIN{FS=","} NR>1 && $2==1 {print $1}' "$input_folder/spatial/tissue_positions.csv" > barcodes_in_tissue.csv
# Create split directory
mkdir -p split
# Run samtools split
samtools view -u -D CB:barcodes_in_tissue.csv possorted_genome_bam.bam | \
samtools split -d CB -M 5000 --output-fmt bam -f 'split/%!.bam' -
# Run featureCounts
featureCounts -T "$threads" -t exon -g gene_id -a "$gtf_file" -o featureCounts_SP.txt split/*bam
# Filter featureCounts output
cut -f1-5 -d " " featureCounts_SP.txt | sed 's/split\///g' | cut -f 1,7- | grep -v ";" > filtered_feature_counts.txt
# Run R scripts
Rscript "$spatialpath_dir/R_scripts/$species/Spatial_pathR_step1_processing_lcpm.R"
Rscript "$spatialpath_dir/R_scripts/$species/Spatial_pathR_step2_GSVA.R" $spatialpath_dir
cd ../
Rscript "$spatialpath_dir/R_scripts/$species/Spatial_pathR_step3_Seurat.R"