erange version 4.0a dev release
[erange.git] / docs / buildMatrix.sh
1 #!/bin/bash
2 echo 'buildMatrix.sh: version 1.2'
3
4 indexPrev=0
5 indexCur=0
6
7 truncateRPKM=""
8 if [ $# -eq 3 ]; then
9     truncateRPKM="--truncate "$3
10 fi
11
12 if [ $# -eq 4 ]; then
13     truncateRPKM="--rescale --truncate "$3
14 fi
15
16 if [ $# -lt 2 ]; then
17         echo 'usage: buildMatrix.sh name datalist.file [truncateRPKM] [--rescale]'
18         echo
19         echo 'where the datalist file is a comma-delimited list of prefix and rds-files'
20         echo
21 else
22         python $ERANGEPATH/recordLog.py buildMatrix.log buildMatrix.sh "with parameters: $1 $2 $truncateRPKM"
23         while read line
24         do 
25                 prefix=`echo $line | cut -f 1 -d ','`
26                 filename=$prefix.partcount
27                 if [ -e $filename ]; then
28                         if [ $indexCur -lt 1 ]; then
29                                 echo "building $1.step0"
30                                 echo -e '\t' > $1.step0
31                                 cut -f 1 $filename >> $1.step0
32                                 indexCur=1
33                         fi
34                                 python $ERANGEPATH/buildMatrix.py $1.step$indexPrev $filename $1.step$indexCur $truncateRPKM
35                                 rm $1.step$indexPrev
36                                 let indexPrev=indexPrev+1
37                                 let indexCur=indexCur+1
38                 else
39                         echo "could not find $filename - skipping"
40                         python $ERANGEPATH/recordLog.py buildMatrix.log buildMatrix.sh "could not find $rds - skipping"
41                 fi
42         done < $2      
43         mv $1.step$indexPrev $1.matrix.tab
44 fi