| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
############################################################################### |
| 4 |
# # |
| 5 |
# # |
| 6 |
# Copyright © 2010-2012 -- LIRMM/CNRS # |
| 7 |
# (Laboratoire d'Informatique, de Robotique et de # |
| 8 |
# Microélectronique de Montpellier / # |
| 9 |
# Centre National de la Recherche Scientifique). # |
| 10 |
# LIFL/INRIA # |
| 11 |
# (Laboratoire d'Informatique, du Traitement de # |
| 12 |
# l'Information et des Systèmes) # |
| 13 |
# # |
| 14 |
# Auteurs/Authors: CRAC list <[email protected]> # |
| 15 |
# Nicolas PHILIPPE <[email protected]> # |
| 16 |
# Mikaël SALSON <[email protected]> # |
| 17 |
# Thérèse COMMES <[email protected]> # |
| 18 |
# Éric RIVALS <[email protected]> # |
| 19 |
# Alban MANCHERON <[email protected]> # |
| 20 |
# # |
| 21 |
# ------------------------------------------------------------------------- # |
| 22 |
# # |
| 23 |
# Ce fichier fait partie du programme CRAC. # |
| 24 |
# # |
| 25 |
# Crac est un outil d'analyse de données de RNA-Seq provenant des NGS. # |
| 26 |
# # |
| 27 |
# Ce logiciel est régi par la licence CeCILL soumise au droit français et # |
| 28 |
# respectant les principes de diffusion des logiciels libres. Vous pouvez # |
| 29 |
# utiliser, modifier et/ou redistribuer ce programme sous les conditions de # |
| 30 |
# la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA sur # |
| 31 |
# le site "http://www.cecill.info". # |
| 32 |
# # |
| 33 |
# En contrepartie de l'accessibilité au code source et des droits de copie, # |
| 34 |
# de modification et de redistribution accordés par cette licence, il n'est # |
| 35 |
# offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, # |
| 36 |
# seule une responsabilité restreinte pèse sur l'auteur du programme, le # |
| 37 |
# titulaire des droits patrimoniaux et les concédants successifs. # |
| 38 |
# # |
| 39 |
# À cet égard l'attention de l'utilisateur est attirée sur les risques # |
| 40 |
# associés au chargement, à l'utilisation, à la modification et/ou au # |
| 41 |
# développement et à la reproduction du logiciel par l'utilisateur étant # |
| 42 |
# donné sa spécificité de logiciel libre, qui peut le rendre complexe à # |
| 43 |
# manipuler et qui le réserve donc à des développeurs et des professionnels # |
| 44 |
# avertis possédant des connaissances informatiques approfondies. Les # |
| 45 |
# utilisateurs sont donc invités à charger et tester l'adéquation du # |
| 46 |
# logiciel à leurs besoins dans des conditions permettant d'assurer la # |
| 47 |
# sécurité de leurs systêmes et ou de leurs données et, plus généralement, # |
| 48 |
# à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. # |
| 49 |
# # |
| 50 |
# Le fait que vous puissiez accéder à cet en-tête signifie que vous avez # |
| 51 |
# pris connaissance de la licence CeCILL, et que vous en avez accepté les # |
| 52 |
# termes. # |
| 53 |
# # |
| 54 |
# ------------------------------------------------------------------------- # |
| 55 |
# # |
| 56 |
# This File is part of the CRAC program. # |
| 57 |
# # |
| 58 |
# Crac is a tool to analyse RNA-Seq data provided by NGS. # |
| 59 |
# # |
| 60 |
# This software is governed by the CeCILL license under French law and # |
| 61 |
# abiding by the rules of distribution of free software. You can use, # |
| 62 |
# modify and/ or redistribute the software under the terms of the CeCILL # |
| 63 |
# license as circulated by CEA, CNRS and INRIA at the following URL # |
| 64 |
# "http://www.cecill.info". # |
| 65 |
# # |
| 66 |
# As a counterpart to the access to the source code and rights to copy, # |
| 67 |
# modify and redistribute granted by the license, users are provided only # |
| 68 |
# with a limited warranty and the software's author, the holder of the # |
| 69 |
# economic rights, and the successive licensors have only limited # |
| 70 |
# liability. # |
| 71 |
# # |
| 72 |
# In this respect, the user's attention is drawn to the risks associated # |
| 73 |
# with loading, using, modifying and/or developing or reproducing the # |
| 74 |
# software by the user in light of its specific status of free software, # |
| 75 |
# that may mean that it is complicated to manipulate, and that also # |
| 76 |
# therefore means that it is reserved for developers and experienced # |
| 77 |
# professionals having in-depth computer knowledge. Users are therefore # |
| 78 |
# encouraged to load and test the software's suitability as regards their # |
| 79 |
# requirements in conditions enabling the security of their systems and/or # |
| 80 |
# data to be ensured and, more generally, to use and operate it in the same # |
| 81 |
# conditions as regards security. # |
| 82 |
# # |
| 83 |
# The fact that you are presently reading this means that you have had # |
| 84 |
# knowledge of the CeCILL license and that you accept its terms. # |
| 85 |
# # |
| 86 |
############################################################################### |
| 87 |
|
| 88 |
|
| 89 |
PIPE=`dirname $0`/classify.fifo |
| 90 |
PIPE_OUT=`dirname $0`/classify.out.fifo |
| 91 |
MAX_NB_ITER=100 # 100s |
| 92 |
if [ $# -gt 5 -o "$1" == "-h" -o "$1" == "--help" ] |
| 93 |
then |
| 94 |
echo "Usage: $0 [-in <input_pipe>] [-out <output_pipe>] [-q]" >&2 |
| 95 |
exit 1 |
| 96 |
fi |
| 97 |
|
| 98 |
QUIET=0 |
| 99 |
while [ $# -gt 0 ] |
| 100 |
do |
| 101 |
if [ "$1" == "-in" ]; then |
| 102 |
PIPE=$2 |
| 103 |
shift |
| 104 |
elif [ "$1" == "-out" ]; then |
| 105 |
PIPE_OUT=$2 |
| 106 |
shift |
| 107 |
elif [ "$1" == "-q" ]; then |
| 108 |
QUIET=1 |
| 109 |
else |
| 110 |
echo "Unknown option $1" >&2 |
| 111 |
fi |
| 112 |
shift |
| 113 |
done |
| 114 |
|
| 115 |
if [ $QUIET -eq 0 ]; then |
| 116 |
echo "This is the client of crac v. 2.5.2"; |
| 117 |
fi |
| 118 |
|
| 119 |
[ -p $PIPE ] || PIPE=${PIPE/`dirname $0`/$PWD} |
| 120 |
[ -p $PIPE_OUT ] || PIPE_OUT=${PIPE_OUT/`dirname $0`/$PWD} |
| 121 |
|
| 122 |
if [ ! -p $PIPE -o ! -p $PIPE_OUT ] |
| 123 |
then |
| 124 |
echo "$PIPE or $PIPE_OUT does not exist... Maybe you didn't launch crac --server?" |
| 125 |
exit 1 |
| 126 |
fi |
| 127 |
|
| 128 |
# Connecting |
| 129 |
echo -n "connect@$$" > $PIPE |
| 130 |
cat $PIPE_OUT > /dev/null |
| 131 |
|
| 132 |
SUBPIPE=`dirname $0`/in.$$.fifo |
| 133 |
SUBPIPE_OUT=`dirname $0`/out.$$.fifo |
| 134 |
NB_ITER=0 |
| 135 |
|
| 136 |
[ -p $SUBPIPE ] || SUBPIPE=${SUBPIPE/`dirname $0`/`dirname $PIPE`} |
| 137 |
[ -p $SUBPIPE_OUT ] || SUBPIPE_OUT=${SUBPIPE_OUT/`dirname $0`/`dirname $PIPE_OUT`} |
| 138 |
|
| 139 |
while [ ! -p $SUBPIPE_OUT -a $NB_ITER -le $MAX_NB_ITER ]; do |
| 140 |
sleep 0.1s |
| 141 |
NB_ITER=$((NB_ITER+1)) |
| 142 |
done |
| 143 |
|
| 144 |
if [ $NB_ITER -ge $MAX_NB_ITER ]; then |
| 145 |
echo "Oops! Output pipe was not created. |
| 146 |
Maybe it has not been created in the directory I expected. |
| 147 |
Something going wrong, I'm leaving cowardly." >&2 |
| 148 |
exit 2 |
| 149 |
fi |
| 150 |
|
| 151 |
if [ $QUIET -eq 0 ]; then |
| 152 |
echo -n "> " |
| 153 |
fi |
| 154 |
while read line; do |
| 155 |
set -- $line |
| 156 |
|
| 157 |
PRINT=0 |
| 158 |
if [ "$1" == "help" ]; then |
| 159 |
echo "* Set a variable: set <variable> <value> |
| 160 |
* Locate a pattern: locate <pattern> |
| 161 |
* Locate each k-mer in a sequence: klocate <k> <dna sequence> |
| 162 |
* Get information about a read: <read id> |
| 163 |
* Get information about a read (with its name): name <read name> |
| 164 |
* Get reads sharing the same k-factor as the one at position <pos> in <read id>: <read id>:<pos> |
| 165 |
* Get reads sharing a given factor: tag <factor> |
| 166 |
* Get reads that have a given factor at a given position: tag pos <position> <factor> |
| 167 |
* Retrieve a genome factor: genome [reverse] <chr_name:position> <length> |
| 168 |
* Get GkSA value: GkSA <pos> |
| 169 |
* Quit main server: quit |
| 170 |
* Quit only child server: <Ctrl>+D" |
| 171 |
elif [ "$1" != "" -a "${1:0:1}" != ">" -a "${1:0:1}" != "#" ]; then |
| 172 |
while [ $# -gt 0 ]; do |
| 173 |
if [ "$1" == "set" -a $# -ge 3 ] |
| 174 |
then |
| 175 |
echo -n "set|$2|$3" > $SUBPIPE |
| 176 |
shift 3 |
| 177 |
elif [ "$1" == "name" -a $# -ge 2 ]; then |
| 178 |
echo -n "name|$2" > $SUBPIPE |
| 179 |
shift 2 |
| 180 |
elif [ "$1" == "locate" -a $# -ge 2 ]; then |
| 181 |
echo -n "loc|"`expr length $2`"|$2" > $SUBPIPE |
| 182 |
shift 2 |
| 183 |
elif [ "$1" == "klocate" -a $# -ge 3 ]; then |
| 184 |
k=$2 |
| 185 |
seq=$3 |
| 186 |
for (( i=0 ; $i < $((${#seq}-k+1)); i++ )); do |
| 187 |
echo -n "loc|$k|"${seq:$i:$k} > $SUBPIPE |
| 188 |
cat $SUBPIPE_OUT |
| 189 |
done |
| 190 |
PRINT=1 |
| 191 |
shift 3 |
| 192 |
elif [ "$1" == "tag" -a $# -ge 4 -a "$2" == "pos" ]; then |
| 193 |
echo -n "tag|"`expr length $4`"|$4" > $SUBPIPE |
| 194 |
cat $SUBPIPE_OUT | grep -Ewo "[0-9]+:$3" | awk -F: '{print $1}' |
| 195 |
shift 4 |
| 196 |
PRINT=1 |
| 197 |
elif [ "$1" == "tag" -a $# -ge 2 ]; then |
| 198 |
echo -n "tag|"`expr length $2`"|$2" > $SUBPIPE |
| 199 |
shift 2 |
| 200 |
elif [ "$1" == "GkSA" -a $# -ge 2 ]; then |
| 201 |
echo -n "GkSA|$2" > $SUBPIPE |
| 202 |
shift 2 |
| 203 |
elif [ "$1" == "genome" -a $# -ge 3 ]; then |
| 204 |
if [ "$2" == "reverse" ]; then |
| 205 |
REV="true" |
| 206 |
shift |
| 207 |
else |
| 208 |
REV="false" |
| 209 |
fi |
| 210 |
if [[ $2 == *:* ]]; then |
| 211 |
chr=$(echo $2 | cut -d: -f1) |
| 212 |
pos=$(echo $2 | cut -d: -f2) |
| 213 |
if [ "$REV" == "true" ]; then |
| 214 |
pos=-$pos |
| 215 |
fi |
| 216 |
echo -n "genome|$chr|$pos|$3" > $SUBPIPE |
| 217 |
else |
| 218 |
echo "Missing ``:''" >&2 |
| 219 |
fi |
| 220 |
shift 3 |
| 221 |
elif [ "$1" == "quit" ]; then |
| 222 |
echo -n "q" > $SUBPIPE |
| 223 |
cat $SUBPIPE_OUT |
| 224 |
echo -n "q" > $PIPE |
| 225 |
cat $PIPE_OUT |
| 226 |
exit 0 |
| 227 |
elif [ "$1" == "print" ]; then |
| 228 |
shift |
| 229 |
echo $* |
| 230 |
shift $# |
| 231 |
PRINT=1 |
| 232 |
elif [[ "$1" =~ ^[0-9]+$ ]] || [[ "$1" =~ ^[0-9]+:[0-9]+$ ]]; then |
| 233 |
echo -n "$1" > $SUBPIPE |
| 234 |
shift |
| 235 |
else |
| 236 |
echo "Unkown command." |
| 237 |
shift |
| 238 |
PRINT=1 |
| 239 |
fi |
| 240 |
if [ $PRINT -eq 0 ]; then |
| 241 |
cat $SUBPIPE_OUT |
| 242 |
fi |
| 243 |
done |
| 244 |
fi |
| 245 |
if [ $QUIET -eq 0 ]; then |
| 246 |
echo -n "> " |
| 247 |
fi |
| 248 |
done |
| 249 |
if [ $QUIET -eq 0 ]; then |
| 250 |
echo |
| 251 |
fi |
| 252 |
echo -n "q" > $SUBPIPE |
| 253 |
cat $SUBPIPE_OUT > /dev/null |