-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_meta.sh
48 lines (36 loc) · 2.03 KB
/
setup_meta.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
#!/bin/bash
#Generates up/down regulated gene list based on Log2FoldChange and P-adj values
#results table is generated by DESeq2 and ashr
echo DISCLAIMER: Results table MUST have symbols column and use lfcShrink \(..., type = \"ashr\"\)
#Creates basename "_example"
name=$(basename "$1" | sed 's/\.csv\|res//g')
echo $name
#User inputs L2FC and PADJ threshold
echo Enter Log2FoldChange Threshold
read x
echo Enter P-Adj Threshold
read p
#creates metascape folder for data
mkdir meta${name}
awk -F, -v p=$p '{if(NR != 1 && $6 <= p){print $0}}' $1 >> temp
#generates upregulated and downregulated gene list
awk -F, -v x=$x '{if($3 >= x){print $1}}' temp | sed 's/"//g' >> meta${name}/meta_input_upreg${name}.csv
awk -F, -v x=$x '{if($3 <= -x){print $1}}' temp | sed 's/"//g' >> meta${name}/meta_input_downreg${name}.csv
#counts the number of genes with gene symbols
upreg=$(awk -F, -v x=$x '{if($3 >= x && $7 != "NA"){print $7}}' temp | wc -l)
downreg=$(awk -F, -v x=$x '{if($3 <= -x && $7 != "NA"){print $7}}' temp | wc -l)
#enters inputted data into text file
printf "Metascape Input Data for ${1} \nLog2FoldChange Threshold = ${x} \nP-Adj Threshhold = ${p} \nDown Regulated Genes with Symbols = ${downreg} \nUp Regulated Genes with Symbols = ${upreg}" >> meta${name}/readme.txt
#counts the total number of ensembl ids
total_upreg=$(cat meta${name}/meta_input_upreg${name}.csv | wc -l)
total_downreg=$(cat meta${name}/meta_input_downreg${name}.csv | wc -l)
#enters total number of ensembl ids into text file
printf "\nTotal Down Regulated Gene Ids = ${total_downreg} \nTotal Up Regulated Gene Ids = ${total_upreg} \n" >> meta${name}/readme.txt
#prints out text file for clarity
cat meta$name/readme.txt
rm temp
#removes previous metascape folder if this specific results table has been analyzed
if [ -d "/home/chienlab/metascape/meta${name}" ]; then rm -r /home/chienlab/metascape/meta${name}; fi
#moves data folder into metascape home folder (NEEDS TO BE CREATED BEFORE HAND)
mv meta${name} ~/metascape
echo "Results saved to ~/metascape/meta${name}."