-
Notifications
You must be signed in to change notification settings - Fork 3
/
sondovac_functions
243 lines (229 loc) · 11.7 KB
/
sondovac_functions
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# Functions required by probe design script Sondovač
# Version of the script
SCRIPTVERSION=1.3
RELEASEDATE=2017-12-18
# Web page of the script
WEB="https://github.com/V-Z/sondovac/"
# Introductory message for users
echo " ##############################################################################"
echo " # #"
echo " # Sondovač is a script to create orthologous low-copy nuclear probes #"
echo " # from transcriptome and genome skim data for target enrichment #"
echo " # #"
echo " # Copyright (C) 2015 R. Schmickl, A. Liston, V. Zeisek and others #"
echo " # #"
echo " # When using this script, please cite Schmickl et al. 2016 #"
echo " # #"
echo " ##############################################################################"
echo
echo -e "\tThis is version ${SCRIPTVERSION} released ${RELEASEDATE}."
echo -e "\tFor newest version check ${WEB} or \"$0 -u\""
echo -e "\tIn case of problems not covered in README.md for user support see ${WEB}"
echo -e "\tFor basic usage see \"$0 -h\""
echo -e "\tFor detailed usage instructions see README.md or \"$0 -r\""
echo
echo "This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. For more information see LICENSE.md, https://gnu.org/licenses/gpl.html or \"$0 -l\"."
echo
echo "This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details."
echo
echo "################################################################################"
echo
# Help for command line options shared by both parts of the script
function generaloptions {
echo
echo "Usage options:"
echo -e "\t-h, -v\tPrint this help message and exit."
echo -e "\t-l\tDisplay LICENSE.md for license information (this script is licensed under GNU GPL v.3, other software under variable licenses). Exit viewing by pressing the \"Q\" key."
echo -e "\t-r\tDisplay README.md for detailed usage instructions. Exit viewing by pressing the \"Q\" key. More information is available in the PDF manual."
echo -e "\t-p\tDisplay INSTALL.md for detailed installation instructions. Exit viewing by pressing the \"Q\" key. More information is available in the PDF manual."
echo -e "\t-e\tDisplay detailed citation information and exit."
echo -e "\t-o\tSet name of output files. Output files will start with that name. Do not use spaces or special characters, only letters, numbers, dots, underscores or minuses. See README.md or PDF manual for details."
}
# Check availability of basic UNIX binaries
function checktools {
{ command -v "$1" >/dev/null 2>&1 && echo "Command \"$1\" is available. OK."; } || {
echo "Error! Command\"$1\" is required but not installed! Aborting. Please, install \"$1\" and ensure it is in PATH. It should be readily available for any UNIX-based system (Linux, Mac OS X, BSD, ...). See PDF manual for more information."
echo
exit 1
}
}
# Display license information
function licenser {
checktools less
less "${SCRIPTDIR}"/LICENSE.md || {
echo "Error! Can not display file ${SCRIPTDIR}/LICENSE.md! Is your installation correct? See https://gnu.org/licenses/gpl.html for GNU GPL v.3 and ${WEB} to ensure you have all needed files."
echo
exit 1
}
echo
exit
}
# Display README.md
function readmeview {
checktools less
less "${SCRIPTDIR}"/README.md || {
echo "Error! Can not display file ${SCRIPTDIR}/README.md! Is your installation correct? See ${WEB} to ensure you have all needed files."
echo
exit 1
}
echo
exit
}
# Display INSTALL.md
function installview {
checktools less
less "${SCRIPTDIR}"/INSTALL.md || {
echo "Error! Can not display file ${SCRIPTDIR}/INSTALL.md! Is your installation correct? See ${WEB} to ensure you have all needed files."
echo
exit 1
}
echo
exit
}
# Display detailed citation information
function citationreference {
echo
echo "################################################################################"
echo
echo "When using Sondovač, please cite:"
echo "Roswitha Schmickl, Aaron Liston, Vojtěch Zeisek, Kenneth Oberlander, Kevin Weitemier, Shannon C.K. Straub, Richard C. Cronn, Léanne L. Dreyer and Jan Suda"
echo "Phylogenetic marker development for target enrichment from transcriptome and genome skim data: the pipeline and its application in southern African Oxalis (Oxalidaceae)"
echo "Molecular Ecology Resources (2016)"
echo "http://onlinelibrary.wiley.com/doi/10.1111/1755-0998.12487/abstract"
echo
echo "Citations of scientific software used by Sondovač:"
echo "BLAT:"
echo "* W. James Kent"
echo " BLAT – the BLAST-like alignment tool"
echo " Genome Research (2002) 12:656-664"
echo " http://genome.cshlp.org/content/12/4/656.short"
echo "Bowtie2:"
echo "* Ben Langmead and Steven L. Salzberg"
echo " Fast gapped-read alignment with Bowtie 2"
echo " Nature Methods (2012) 9:357-359"
echo " http://www.nature.com/nmeth/journal/v9/n4/full/nmeth.1923.html"
echo "CD-HIT:"
echo "* Weizhong Li, Lukasz Jaroszewski and Adam Godzik"
echo " Clustering of highly homologous sequences to reduce the size of large protein databases"
echo " Bioinformatics (2001) 17:282-283."
echo " http://bioinformatics.oxfordjournals.org/content/17/3/282.short"
echo "* Weizhong Li, Lukasz Jaroszewski and Adam Godzik"
echo " Tolerating some redundancy significantly speeds up clustering of large protein databases"
echo " Bioinformatics (2002) 18:77-82"
echo " http://bioinformatics.oxfordjournals.org/content/18/1/77.short"
echo "* Weizhong Li and Adam Godzik"
echo " Cd-hit: a fast program for clustering and comparing large sets of protein or nucleotide sequences"
echo " Bioinformatics (2006) 22:1658-1659"
echo " http://bioinformatics.oxfordjournals.org/content/22/13/1658.short"
echo "* Limin Fu, Beifang Niu, Zhengwei Zhu, Sitao Wu and Weizhong Li"
echo " CD-HIT: accelerated for clustering the next generation sequencing data"
echo " Bioinformatics (2012) 28:3150-3152"
echo " http://bioinformatics.oxfordjournals.org/content/28/23/3150.short"
echo "* Ying Huang, Beifang Niu, Ying Gao, Limin Fu and Weizhong Li"
echo " CD-HIT Suite: a web server for clustering and comparing biological sequences"
echo " Bioinformatics (2010) 26:680"
echo " http://bioinformatics.oxfordjournals.org/content/26/5/680.short"
echo "* Beifang Niu, Limin Fu, Shulei Sun and Weizhong Li"
echo " Artificial and natural duplicates in pyrosequencing reads of metagenomic data"
echo " BMC Bioinformatics (2010) 11:187"
echo " http://www.biomedcentral.com/1471-2105/11/187"
echo "* Weizhong Li, Limin Fu, Beifang Niu, Sitao Wu and John Wooley"
echo " Ultrafast clustering algorithms for metagenomic sequence analysis"
echo " Briefings in Bioinformatics (2012) 13(6):656-668"
echo " http://bib.oxfordjournals.org/content/13/6/656.abstract"
echo "FLASH:"
echo "* Tanja Magoč and Steven L. Salzberg"
echo " FLASH: fast length adjustment of short reads to improve genome assemblies"
echo " Bioinformatics (2011) 27(21):2957-2963"
echo " http://bioinformatics.oxfordjournals.org/content/27/21/2957.abstract"
echo "Geneious:"
echo "* Matthew Kearse, Richard Moir, Amy Wilson, Steven Stones-Havas, Matthew Cheung, Shane Sturrock, Simon Buxton, Alex Cooper, Sidney Markowitz, Chris Duran, Tobias Thierer, Bruce Ashton, Peter Meintjes1, and Alexei Drummond"
echo " Geneious Basic: An integrated and extendable desktop software platform for the organization and analysis of sequence data"
echo " Bioinformatics (2012) 28(12):1647-1649"
echo " http://bioinformatics.oxfordjournals.org/content/28/12/1647"
echo "SAMtools:"
echo "* Heng Li, Bob Handsaker, Alec Wysoker, Tim Fennell, Jue Ruan, Nils Homer, Gabor Marth, Goncalo Abecasis, Richard Durbin and 1000 Genome Project Data Processing Subgroup"
echo " The Sequence Alignment/Map format and SAMtools"
echo " Bioinformatics (2009) 25(16): 2078-2079"
echo " http://bioinformatics.oxfordjournals.org/content/25/16/2078.abstract"
echo "* Heng Li"
echo " A statistical framework for SNP calling, mutation discovery, association mapping and population genetical parameter estimation from sequencing data"
echo " Bioinformatics (2011) 27(21): 2987-2993"
echo " http://bioinformatics.oxfordjournals.org/content/27/21/2987.abstract"
echo "* Heng Li"
echo " Improving SNP discovery by base alignment quality"
echo " Bioinformatics (2011) 27(8): 1157-1158."
echo " http://bioinformatics.oxfordjournals.org/content/27/8/1157.short"
echo
echo "For more information see README.md, you can do so by \"$0 -r\" and/or PDF manual and/or visit ${WEB}"
echo
exit
}
# Set variables for working directory and PATH
function workdirpath {
# Check if there is bin directory, if not, create it
checktools pwd
checktools mkdir
WORKDIR="$(pwd)"
mkdir -p "${WORKDIR}"/bin/bin || {
echo "Error! Can not create directory \"bin\" in directory \"${WORKDIR}\"! Do you have write permission for directory \"${WORKDIR}\"?"
echo
exit 1
}
BIN="${WORKDIR}"/bin/bin
echo "For future work consider adding \"${BIN}\" to PATH, as it will contain binaries of tools used in this pipeline. Alternatively, you can move whole \"${WORKDIR}/bin\" to your preferred location, but ensure to move all files and keep relative paths."
echo
cd "${WORKDIR}" || {
echo "Error! Can't go to${WORKDIR}! Do you have write permission for directory \"${WORKDIR}\"?"
echo
exit 1
}
# Add bin directory in current directory into PATH
export PATH="${BIN}:${PATH}"
}
# Check if input files have DOS or UNIX encoding
function eolcheck {
if awk '/\r$/{exit 0;} 1{exit 1;}' "$1"; then
echo "Input file $1 has DOS end of lines. It will be converted into UNIX end of lines"
dos2unix "$1" || {
echo "Error! Conversion to UNIX EOL failed. Aborting. Check if $1 is valid file."
echo
exit 1
}
echo
else
echo "Input file $1 has UNIX end of lines. OK."
echo
fi
}
# Function to convert interleaved FASTA into non-interleaved (if necessary)
# $1 is input FASTA file provided by the user, $2 is output non-interleaved FASTA file
function noninterleavedfasta {
echo "Converting possibly interleaved FASTA file $1 into non-interleaved FASTA file $2"
{ awk 'BEGIN{RS=">"}NR>1{sub("\n","\t");gsub("\n",""); print RS$0}' "$1" | sed 's/\t/\n/g' > "$2"; } || {
echo "Error! Conversion of FASTA failed. Aborting. Check if $1 is correct FASTA file."
echo
exit 1
}
echo
}
# Check if BLAT is available
function checkblat {
{ command -v blat >/dev/null 2>&1 && echo "\"BLAT\" is available. OK."; } || {
echo "BLAT is required but not installed or available in PATH."
echo "See https://genome.ucsc.edu/FAQ/FAQblat.html for installation of BLAT. The simplest is download of precompiled Linux x86_64 binary from https://hgdownload.soe.ucsc.edu/admin/exe/linux.x86_64/blat/"
echo
exit 1
}
}
# Function to convert FASTA to TAB
# $1 is input file in FASTA, $2 output file in TAB
function fasta2tab {
#awk '/>/{if (x)print x;x="";}{x=(!x)?$0:x"\t"$0;}END{print x;}' $1 | sed 's/>[[:blank:]]*/>/g' | sed 's/[[:blank:]]+/ /g' | tr "\n" "\t" | sed 's/\t>/\n>/g' | sed 's/^>//g' | sed 's/[[:blank:]]*$//g' > $2
sed 's/[[:blank:]]\{1,\}/_/g' "$1" | awk '/>/{if (x)print x;x="";}{x=(!x)?$0:x"\t"$0;}END{print x;}' | sed 's/^>//g' > "$2" || {
echo "Error! Conversion of FASTA to TAB (TSV) failed. Aborting. Check if $1 is correct FASTA file."
echo
exit 1
}
echo
}