forked from mtruglio/canvas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_mongo_collections.sh
executable file
·70 lines (62 loc) · 2.83 KB
/
setup_mongo_collections.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
#!/bin/bash
usage() { echo "Usage: $0 [-d <string>] [-r <string>]" 1>&2; exit 1; }
die () {
echo "ERROR: $*. Aborting." >&2
exit 1
}
dir=''
build=false
cleanup=false
regex1="genelist"
regex2="tarbase"
regex3="targetscan"
regex4="mirbase"
regex5="enhancer"
regex6="overlap"
regex7="TADs"
while getopts "d:r:" opt; do
case $opt in
d) $cleanup && die "Cannot specify option -d with -r"
build=true
dir=${OPTARG};;
r) $build && die "Cannot specify option -d with -r"
cleanup=true
db=${OPTARG};;
\?)
usage
;;
esac
shift $((OPTIND-1))
if [[ "${cleanup}" == true ]] ; then
mongo ${db} --eval "db.dropDatabase()"
elif [[ "${build}" == true ]] ; then
echo "build"
echo "importing from $dir"
echo "db will be named $(basename $dir)"
for file in ${dir}/*.txt; do
s=${file##*/};
echo "Importing $file as ${s%.txt}";
if [[ "$file" =~ $regex1 ]]; then
mongoimport --host=127.0.0.1 -d $(basename $dir) -c ${s%_genelist.txt} --type tsv --file $file --fields gene
elif [[ "$file" =~ $regex2 ]]; then
mongoimport --host=127.0.0.1 -d $(basename $dir) -c ${s%.txt} --type tsv --file $file --fields geneID,geneName,mirna
elif [[ "$file" =~ $regex3 ]]; then
mongoimport --host=127.0.0.1 -d $(basename $dir) -c ${s%.txt} --type tsv --file $file --fields geneName,mirna
elif [[ "$file" =~ $regex4 ]]; then
mongoimport --host=127.0.0.1 -d $(basename $dir) -c ${s%.txt} --type tsv --file $file --fields chr,source,feature,start,end,score,strand,frame,info
elif [[ "$file" =~ $regex5 ]]; then
mongoimport --host=127.0.0.1 -d $(basename $dir) -c ${s%.txt} --type tsv --file $file --fields info,chr,start,end,CellType,source,TargetGene,ConservationMean,ConservationMedian
mongo $(basename $dir) --eval "db.${s%.txt}.createIndex({chr:1});"
elif [[ "$file" =~ $regex6 ]]; then
mongoimport --host=127.0.0.1 -d $(basename $dir) -c ${s%.txt} --type tsv --file $file --fields chr,start,end,type
mongo $(basename $dir) --eval "db.${s%.txt}.createIndex({chr:1});"
elif [[ "$file" =~ $regex7 ]]; then
mongoimport --host=127.0.0.1 -d $(basename $dir) -c ${s%_TADs.txt} --type tsv --file $file --fields chr,start,end,info
mongo $(basename $dir) --eval "db.${s%_TADs.txt}.createIndex({chr:1});"
else
mongoimport --host=127.0.0.1 -d $(basename $dir) -c ${s%.txt} --type tsv --file $file --fields chr,start,end,info
mongo $(basename $dir) --eval "db.${s%.txt}.createIndex({chr:1});"
fi
done
fi
done