-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplace_biocLite.sh
executable file
·69 lines (51 loc) · 2.12 KB
/
replace_biocLite.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
#!/bin/bash
LITE_CALL="biocLite"
BIOC_INST="BiocInstaller"
SOURCE_FILES=".*\.[Rr]?[DdNnMmWw]*$"
DESC_FILE="DESCRIPTION"
BIOC_MGR="\1if (!requireNamespace(\"BiocManager\", quietly=TRUE))\2\\
\1install.packages(\"BiocManager\")\2"
CODE_BIOCLITE="\1install.packages(\"BiocManager\")\2"
MGR_INST="BiocManager::install"
SOURCE_LINE_REGEXP="([$># \`'\t]*)source\([\"']http.*$LITE_CALL\.R[\"']\)(.*)$"
CODE_BIOCLITE_REGEXP="^(.*)source\([\"']http.*$LITE_CALL\.R[\"']\)(.*)$"
# SOURCE_LINE_REGEXP="^(\s*)(\`)*source\(.*http.*$LITE_CALL\.R.*\)\`*\s*$"
LIBRARY_LINE_REGEXP="(.*library\(.*)$BIOC_INST(.*)"
FULL_CALL_REGEXP="(.*)$BIOC_INST([: ]*)$LITE_CALL(.*)"
BIOCLITE_CALL_REGEXP="$LITE_CALL\("
library_hits=`find . ! -path . -regex "$SOURCE_FILES" -exec grep -El "$LIBRARY_LINE_REGEXP" {} \+`
if [ ! -z "${library_hits// }" ]; then
echo "Replacing any library\(BiocInstaller\) with BiocManager..."
for i in $library_hits;
do
sed -E -i "s|$LIBRARY_LINE_REGEXP|\1BiocManager\2|g" $i
done
fi
biocLite_hits=`find . ! -path . -regex "$SOURCE_FILES" -exec grep -El "$BIOCLITE_CALL_REGEXP" {} \+`
if [ ! -z "${biocLite_hits// }" ]; then
echo "Replacing biocLite() with BiocManager::install()"
for i in $biocLite_hits;
do
sed -E -i "s|$FULL_CALL_REGEXP|\1BiocManager\2install\3|" $i
sed -E -i "s|$BIOCLITE_CALL_REGEXP|$MGR_INST(|g" $i
done
fi
## for DESCRIPTION files
sed -i "s/\<$BIOC_INST\>/BiocManager/" $DESC_FILE
source_hits=`find . ! -path . -regex "$SOURCE_FILES" -exec grep -El "$SOURCE_LINE_REGEXP" {} \+`
if [ ! -z "${source_hits// }" ]; then
echo "Replacing source('.../biocLite.R') with install.packages('BiocManager')"
for i in $source_hits;
do
sed -E -i "s|$SOURCE_LINE_REGEXP|$BIOC_MGR|" $i
done
fi
code_hits=`find . ! -path . -regex "$SOURCE_FILES" -exec grep -El "$CODE_BIOCLITE_REGEXP" {} \+`
if [ ! -z "${code_hits// }" ]; then
echo "Replacing source(.../biocLite.R) with install.packages"
for i in $code_hits;
do
sed -E -i "s|$CODE_BIOCLITE_REGEXP|$CODE_BIOCLITE|" $i
done
fi
export LITE_FILES="$library_hits $source_hits $biocLite_hits"