forked from fgrelard/Esmraldi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_analysis.sh
executable file
·93 lines (87 loc) · 2.62 KB
/
script_analysis.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
88
89
90
91
92
93
#!/bin/bash
## Script to generate NMF analysis for several imzML files
function print_help {
echo "
Generates analysis of dimension reduction methods
for several imzML files
Usage :
$(basename "$0") -i input_dir -o output_name -t theoretical_spectrum -n number_components
where:
-i input root imzML directory (contains 00, 01, 0X subdirectories)
-o output (.csv)
-t theoretical spectrum (.json)
-n number of components for dimension reduction method
-a optional switch if alignment is not needed
-p optional switch is normalization before NMF is not needed
-r optional switch to perform statistical analysis with NMF
-s directory number to start with (region);"
}
START_DIR=0
while getopts "i:o:t:n:s:apr" o; do
case "${o}" in
i)
INPUT=${OPTARG}
;;
o)
OUTPUT=${OPTARG}
;;
t)
THEORETICAL=${OPTARG}
;;
n)
NUMBER_COMPONENTS=${OPTARG}
;;
a)
OPT_NO_ALIGN='true'
;;
p)
OPT_NORMALIZE='true'
;;
r)
OPT_ANALYSIS='true'
;;
s)
START_DIR=${OPTARG}
;;
h|*)
print_help;
exit 2
;;
--)
print_help;
exit 2
;;
esac
done
DIRECTORY_NAMES=$(find $INPUT -maxdepth 1 -mindepth 1 -type d -print0 | sort -z | xargs -r0 echo)
OUTPUT_NAME=$(basename ${OUTPUT%.*})
OUTPUT_DIR=$(dirname $OUTPUT)
echo $OUTPUT_NAME, $OUTPUT_DIR
mkdir -p $OUTPUT_DIR
for dir in $DIRECTORY_NAMES
do
name=$(basename $dir)
imzml=$dir/$name.imzML
align=$dir/$OUTPUT_NAME.imzML
nii=$dir/$OUTPUT_NAME.nii
peaks=$dir/$OUTPUT_NAME.csv
outdir=$OUTPUT_DIR/$name
outname=$outdir/$OUTPUT_NAME.csv
mkdir -p $outdir
if [[ ${name#0} -lt $START_DIR ]];
then
continue
fi
if [[ ! $OPT_NO_ALIGN ]]; then
python3 -m examples.spectra_alignment -i $imzml -o $align -p 2000 -n 3 -z 3 -s 0.055 #--theoretical $THEORETICAL --tolerance_theoretical 0.15
python3 -m examples.tonifti -i $align -o $nii
fi
if [[ $OPT_ANALYSIS ]]; then
if [[ $OPT_NORMALIZE ]]; then
python3 -m examples.evaluation.analysis_reduction -i $nii -m $peaks -o $outname -n $NUMBER_COMPONENTS -t $THEORETICAL -p -f
else
python3 -m examples.evaluation.analysis_reduction -i $nii -m $peaks -o $outname -n $NUMBER_COMPONENTS -t $THEORETICAL -f
fi
python3 -m examples.average_images_same_species -i $nii -m $peaks -o $outdir -t $THEORETICAL
fi
done