upgraded to work with the upgraded MainPipelineScript
[htsworkflow.git] / htswdataprod / scripts / MPListener
1 #!/bin/sh                                                                                                                           
2 # Illumina Data Analysis Pipeline "Listener" fr Standard or IPAR mode. Checks for finished.txt in each main directory of the pipeline                                                                      
3
4 # params
5 exptrackmainsc="/usr/local/src/EXPTRACK/exp_track_main.py"
6 fcid=$1
7 runfolder=$2
8 tocycle=$3
9
10
11
12 ## DBG: python $exptrackmainsc updsts $fcid $runfolder 1 ListenerStarted
13
14
15 analysis_mode='standard'
16 pipeline_version='1.3'
17 ## The Command that runs the making of the "make" files
18 if [ -d Data/IPAR_$pipeline_version ]
19 then
20   datadir=Data/IPAR_$pipeline_version
21   analysis_mode='IPAR'
22 else
23   datadir=Data
24 fi
25
26 ## Make sure we find the ONE specific Start folder (Firecrest or Standard / Bustard for IPAR)
27 if [ $analysis_mode == 'IPAR' ]
28 then
29   #firecrestdir=`ls $datadir | grep "Firecrest"`
30   #countdirs=`ls $datadir | grep -c Firecrest`
31   #Rami
32   startdir=`ls $datadir | grep Bustard$pipeline_version`
33   countdirs=`ls $datadir | grep -c Bustard$pipeline_version`
34 else
35   startdir=`ls $datadir | grep C1-[0-9][0-9]_Firecrest`
36   countdirs=`ls $datadir | grep -c C1-[0-9][0-9]_Firecrest`
37 fi
38
39 if [ $countdirs == 1 ]
40 then
41   echo "ok. start folder '$startdir' found"
42 else
43   if [ $countdirs -gt 1 ]
44   then
45     echo "MPListner ERROR: Found too many ($countdirs) start  directories (firecrest/bustard(for IPAR)). You need to specify ONE folder or REMOVE duplicates. Found:"
46     echo ""
47     echo $startdir
48     python $exptrackmainsc updsts $fcid $runfolder 0 ERROR:_Need_Specific_Start_Dir
49     exit
50   else
51     echo "MPListner ERROR: Start (firecrest/bustard(for IPAR)) directory NOT FOUND."
52     python $exptrackmainsc updsts $fcid $runfolder 0 ERROR:_Start_Dir_Not_Found
53     exit
54   fi
55 fi
56
57 # ---------------------- Check for finished.txt in each main directory of the pipeline ------------                                
58
59 if [ $analysis_mode == 'IPAR' ]
60 then
61   firecrestfinished=$datadir/$startdir/finished.txt # dummy check, since there's no need to check this one in IPAR
62   bustfinished=$datadir/$startdir/finished.txt
63   gerfinished=$datadir/$startdir/GERALD_*/finished.txt
64 else
65   firecrestfinished=$datadir/$startdir/finished.txt
66   bustfinished=$datadir/$startdir/Bustard*_*/finished.txt
67   gerfinished=$datadir/$startdir/Bustard*_*/GERALD_*/finished.txt
68 fi
69
70 # Wait for 48 hours max                                                                                                  
71 timeremain=`expr 60 \* 60 \* 72`
72 interval=10
73
74 ## ---- Wait for Firecrest -----                                                                                                    
75 while [ $analysis_mode != 'IPAR' ] && [ ! -f $firecrestfinished ] && [ $timeremain -gt 0 ]
76 do
77   #echo "wating $interval secs more to check for firecrestfinished ($timeremain secs left)"
78   sleep $(( $interval ))
79   timeremain=`expr $timeremain - $interval`
80 done
81
82 if [ $timeremain -gt 0 ]
83 then
84   if [ $analysis_mode != 'IPAR' ]
85   then
86     echo "Firecrest finished at `date`"
87     python $exptrackmainsc updsts $fcid $runfolder 1 Firecrest_finished
88   fi
89 else
90   echo "Script time expired while waiting for Firecrest to finish."
91   python $exptrackmainsc updsts $fcid $runfolder 2 Script_time_expired_during_Firecrest
92 fi
93
94 ## -------- Wait for Bustard ------                                                                                  
95 while [ ! -f $bustfinished ] && [ $timeremain -gt 0 ]
96 do
97   #echo "wating $interval secs more to check for bustfinished ($timeremain secs left)"
98   sleep $(( $interval ))
99   timeremain=`expr $timeremain - $interval`
100 done
101
102 if [ $timeremain -gt 0 ]
103 then
104   echo "Bustard finished at `date`"
105   python $exptrackmainsc updsts $fcid $runfolder 1 Bustard_finished
106 else
107   echo "Script time expired while waiting for Bustard to finish."
108   python $exptrackmainsc updsts $fcid $runfolder 2 Script_time_expired_during_Bustard
109 fi
110
111 ## -------- Wait for Gerald ------                                                                                     
112 while [ ! -f $gerfinished ] && [ $timeremain -gt 0 ]
113 do
114   echo "wating $interval secs more to check for $gerfinished  ($timeremain secs left)"
115   sleep $(( $interval ))
116   timeremain=`expr $timeremain - $interval`
117 done
118
119
120 if [ $timeremain -gt 0 ]
121 then
122   echo "Gerald finished at `date`"
123   python $exptrackmainsc updsts $fcid $runfolder 3 Gerald_finished__Starting_DataAnalysis
124   echo "Finished LISTENING TO SOLEXA PIPELINE ..."
125   echo "Starting DATA ANALYSIS PHASE ..."
126   /usr/local/src/EXPTRACK/MPAnalysis $fcid $runfolder
127 else
128   echo "Script time expired while waiting for Gerald to finish."
129   python $exptrackmainsc updsts $fcid $runfolder 2 Script_time_expired_during_Gerald
130 fi
131
132 exit
133
134 ## ---------------------------------------------------------------------------------