X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=cluster_tools%2FmergeDoseByRegions.sh;h=598df6925c89c48ae1429e4635a052c85beb04c2;hb=20147f097d36f54eae548368df24f577e5567677;hp=d7a390af7fa194b5671d927bad94cd82a3bae0fd;hpb=41e17601d6204e6036fa27a3db4c8d1e6bd175a7;p=clitk.git diff --git a/cluster_tools/mergeDoseByRegions.sh b/cluster_tools/mergeDoseByRegions.sh index d7a390a..598df69 100755 --- a/cluster_tools/mergeDoseByRegions.sh +++ b/cluster_tools/mergeDoseByRegions.sh @@ -2,102 +2,140 @@ set -u function usage { - echo "$0 -i -j -o " + echo "$0 -i -j -o " exit 1 } -if [ $# != 6 ] -then - usage -fi - -IN1=$2 -IN2=$4 -RESULT=$6 - -test -f ${IN1} && test -f ${IN2} || usage - -TMP="$(mktemp)" -echo "merging dose by regions file" -# check if all 3 text files have the same number of lines -nblines=`cat ${IN1} | wc -l` -nb2=`cat ${IN2} | wc -l` -nb3=`cat ${RESULT} | wc -l` +function addToPartialResult { + IN1=$2 + IN2=$4 + RESULT=$6 + + test -f ${IN1} && test -f ${IN2} || usage + + TMP="$(mktemp)" + + # check if all 3 text files have the same number of lines + nblines=`cat ${IN1} | wc -l` + nb2=`cat ${IN2} | wc -l` + nb3=`cat ${RESULT} | wc -l` + + if [ $nblines -ne $nb2 ] || [ $nblines -ne $nb3 ]; then + echo "Files does not have the same size" + exit 1 + fi + + #Copy the 1st line in output + line1=`sed -n "1p" < ${RESULT}` + echo "${line1}" >> ${TMP} + # for all lines (except the 1st), split according tab + # sum the some elements (dose, edep) ... + for i in $(seq 2 $nblines); do + #Get the 3 lines + file1=`sed -n "${i}p" < ${IN1}` + file2=`sed -n "${i}p" < ${IN2}` + file3=`sed -n "${i}p" < ${RESULT}` + + # sum edep: get the 2 values, sum them and replace it in the file3 + # The /#./0. is important to add 0 for decimal value between 0 and 1 + edep1=$(echo ${file1} | cut -f3 -d' ') + edep2=$(echo ${file2} | cut -f3 -d' ') + edep3=$(python -c "print($edep1+$edep2)") + edep3=${edep3/#./0.} + file3=$(echo $file3 |awk -v r=${edep3} '{$3=r}1') + + # sum square_edep: get the 2 values, sum them and replace it in the file3 + sqEdep1=$(echo ${file1} | cut -f5 -d' ') + sqEdep2=$(echo ${file2} | cut -f5 -d' ') + sqEdep3=$(python -c "print($sqEdep1+$sqEdep2)") + sqEdep3=${sqEdep3/#./0.} + file3=$(echo $file3 |awk -v r=${sqEdep3} '{$5=r}1') + + # sum dose: get the 2 values, sum them and replace it in the file3 + dose1=$(echo ${file1} | cut -f6 -d' ') + dose2=$(echo ${file2} | cut -f6 -d' ') + dose3=$(python -c "print($dose1+$dose2)") + dose3=${dose3/#./0.} + file3=$(echo $file3 |awk -v r=${dose3} '{$6=r}1') + + # sum square_dose: get the 2 values, sum them and replace it in the file3 + sqDose1=$(echo ${file1} | cut -f8 -d' ') + sqDose2=$(echo ${file2} | cut -f8 -d' ') + sqDose3=$(python -c "print($sqDose1+$sqDose2)") + sqDose3=${sqDose3/#./0.} + file3=$(echo $file3 |awk -v r=${sqDose3} '{$8=r}1') + + # sum n_hits: get the 2 values, sum them and replace it in the file3 + hit1=$(echo ${file1} | cut -f9 -d' ') + hit2=$(echo ${file2} | cut -f9 -d' ') + hit3=$(python -c "print($hit1+$hit2)") + file3=$(echo $file3 |awk -v r=${hit3} '{$9=r}1') + + # sum n_event_hits: get the 2 values, sum them and replace it in the file3 + event1=$(echo ${file1} | cut -f10 -d' ') + event2=$(echo ${file2} | cut -f10 -d' ') + event3=$(python -c "print($event1+$event2)") + file3=$(echo $file3 |awk -v r=${event3} '{$10=r}1') + + #Write the output + echo "${file3}" >> ${TMP} + done + mv -f ${TMP} ${RESULT} +} -if [ $nblines -ne $nb2 ] || [ $nblines -ne $nb3 ]; then - echo "Files does not have the same size" - exit 1 -fi - -#Copy the 1st line in output -line1=`sed -n "1p" < ${RESULT}` -echo "${line1}" >> ${TMP} - -# for all lines (except the 1st), split according tab -# sum the some elements (dose, edep) ... -for i in $(seq 2 $nblines); do - #Get the 3 lines - line1=`sed -n "${i}p" < ${IN1}` - line2=`sed -n "${i}p" < ${IN2}` - line3=`sed -n "${i}p" < ${RESULT}` - - # sum edep: get the 2 values, sum them and replace it in the line3 - # The /#./0. is important to add 0 for decimal value between 0 and 1 - edep1=$(echo ${line1} | cut -f3 -d' ') - edep2=$(echo ${line2} | cut -f3 -d' ') - edep3=$(echo "scale=30;$edep1+$edep2" | bc) - edep3=${edep3/#./0.} - line3=$(echo $line3 |awk -v r=${edep3} '{$3=r}1') - - # sqrt sum square std_edep: get the 2 values, sum the square, take the sqrt and replace it in the line3 - edep1=$(echo ${line1} | cut -f4 -d' ') - edep2=$(echo ${line2} | cut -f4 -d' ') - edep3=$(echo "scale=30;sqrt($edep1*$edep1+$edep2*$edep2)" | bc) - edep3=${edep3/#./0.} - line3=$(echo $line3 |awk -v r=${edep3} '{$4=r}1') - - # sum square_edep: get the 2 values, sum them and replace it in the line3 - edep1=$(echo ${line1} | cut -f5 -d' ') - edep2=$(echo ${line2} | cut -f5 -d' ') - edep3=$(echo "scale=30;$edep1+$edep2" | bc) - edep3=${edep3/#./0.} - line3=$(echo $line3 |awk -v r=${edep3} '{$5=r}1') - - # sum dose: get the 2 values, sum them and replace it in the line3 - edep1=$(echo ${line1} | cut -f6 -d' ') - edep2=$(echo ${line2} | cut -f6 -d' ') - edep3=$(echo "scale=30;$edep1+$edep2" | bc) - edep3=${edep3/#./0.} - line3=$(echo $line3 |awk -v r=${edep3} '{$6=r}1') - - # sqrt sum square std_dose: get the 2 values, sum the square, take the sqrt and replace it in the line3 - edep1=$(echo ${line1} | cut -f7 -d' ') - edep2=$(echo ${line2} | cut -f7 -d' ') - edep3=$(echo "scale=30;sqrt($edep1*$edep1+$edep2*$edep2)" | bc) - edep3=${edep3/#./0.} - line3=$(echo $line3 |awk -v r=${edep3} '{$7=r}1') - - # sum square_dose: get the 2 values, sum them and replace it in the line3 - edep1=$(echo ${line1} | cut -f8 -d' ') - edep2=$(echo ${line2} | cut -f8 -d' ') - edep3=$(echo "scale=30;$edep1+$edep2" | bc) - edep3=${edep3/#./0.} - line3=$(echo $line3 |awk -v r=${edep3} '{$8=r}1') - - # sum n_hits: get the 2 values, sum them and replace it in the line3 - edep1=$(echo ${line1} | cut -f9 -d' ') - edep2=$(echo ${line2} | cut -f9 -d' ') - edep3=$(echo "scale=30;$edep1+$edep2" | bc) - line3=$(echo $line3 |awk -v r=${edep3} '{$9=r}1') - - # sum n_event_hits: get the 2 values, sum them and replace it in the line3 - edep1=$(echo ${line1} | cut -f10 -d' ') - edep2=$(echo ${line2} | cut -f10 -d' ') - edep3=$(echo "scale=30;$edep1+$edep2" | bc) - line3=$(echo $line3 |awk -v r=${edep3} '{$10=r}1') - - #Write the output - echo "${line3}" >> ${TMP} -done -mv -f ${TMP} ${RESULT} +function divideUncertaintyResult { + IN1=$2 + value=$4 + RESULT=$6 + + TMP="$(mktemp)" + + # check if all 2 text files have the same number of lines + nblines=`cat ${IN1} | wc -l` + nb3=`cat ${RESULT} | wc -l` + + if [ $nblines -ne $nb3 ]; then + echo "Files does not have the same size" + exit 1 + fi + + #Copy the 1st line in output + line1=`sed -n "1p" < ${RESULT}` + echo "${line1}" >> ${TMP} + # for all lines (except the 1st), split according tab + # sum the some elements (dose, edep) ... + for i in $(seq 2 $nblines); do + #Get the lines + file1=`sed -n "${i}p" < ${IN1}` + file3=`sed -n "${i}p" < ${RESULT}` + + # Divide uncertainty and replace it in the file3 + edep1=$(echo ${file1} | cut -f3 -d' ') + sqEdep1=$(echo ${file1} | cut -f5 -d' ') + stdEdep3=$(python <> ${TMP} + done + mv -f ${TMP} ${RESULT} +}