OSDN Git Service

Add: PIONE tutorial for Clustering. v2.0.2p0103
authorkinoshita-eos <kinoshita@yasunaga-lab.bio.kyutech.ac.jp>
Fri, 27 Feb 2015 05:31:52 +0000 (14:31 +0900)
committerkinoshita-eos <kinoshita@yasunaga-lab.bio.kyutech.ac.jp>
Fri, 27 Feb 2015 05:31:52 +0000 (14:31 +0900)
new file:   SampleCode/PIONE/Advanced5/Main.pione
new file:   SampleCode/PIONE/Advanced5/Main_ROIr.pione

SampleCode/PIONE/Advanced5/Main.pione [new file with mode: 0644]
SampleCode/PIONE/Advanced5/Main_ROIr.pione [new file with mode: 0644]

diff --git a/SampleCode/PIONE/Advanced5/Main.pione b/SampleCode/PIONE/Advanced5/Main.pione
new file mode 100644 (file)
index 0000000..299573c
--- /dev/null
@@ -0,0 +1,223 @@
+param $task := 2
+param $divide := 2
+param $refine := 5
+
+Rule Main
+       input '*.roi'.all
+       input 'Makefile'
+       input 'Makefile.config'
+       output '*.avg'.all
+       output '*.tiff'.all
+       output 'all.logps'
+       output 'all.treeinfo'
+       output 'all.avgsortlst'
+Flow
+       rule Preprocess {filelist:$I[1].all, num:1.upto($task), length:$I[1].length()}
+       rule Process
+       rule Refinement {num:1.upto($divide)}
+       rule RefinementRoot
+       rule MontageAverage
+End
+
+Rule Preprocess
+       input $filelist.nth(((($num-1)*((($length-1)/$task)+1))+1).upto((($num*((($length-1)/$task)+1))|$length).min()))
+       input 'Makefile'
+       input 'Makefile.config'
+       output '*.pad'.all
+Action
+       for data in {$I[1]}
+       do
+               make $(basename ${data} ".roi").pad
+       done
+End
+
+Rule Process
+       input '*.pad'.all
+       input 'Makefile'
+       input 'Makefile.config'
+       output 'all.padsortlst'
+       output 'all.treeinfo'
+       output 'all.avgsortlst'
+       output ((1.upto($divide).str())+".lst").d().all()
+       output ((1.upto($divide).str())+".tree").d().all()
+       output ("*.pad"+(1.upto($divide).str())).d().all()
+       output ("*.avg"+(0.upto($divide).str())).d().all()
+       output '*.avglst'.all
+       output 'all.padsortmon.tiff'
+       output 'all.avgsortmon.tiff'
+       output 'all.logps'
+Action
+       ls -1 *.pad > all.padlst
+       make Log
+       make LogPS
+       mrc2tiff -i all.padsortmon -o all.padsortmon.tiff
+       mrc2tiff -i all.avgsortmon -o all.avgsortmon.tiff
+       
+       cp {$O[1]} 1.lst
+       cp {$O[2]} 1.tree
+       for (( i=2; i<={$divide}; i++ ))
+       do
+               max=0
+               for data in $(ls *.lst)
+               do
+                       num=$(wc -l ${data} | awk '{printf $1}')
+                       if [ ${num} -gt ${max} ] ; then
+                               max=${num}
+                               maxlist="${data}"
+                       fi
+               done
+               maxtree="$(basename ${maxlist} '.lst').tree"
+               root=$(head -1 ${maxtree} | awk '{printf("%d", $1)}')
+               rootname=$(basename $(awk -v val=${root} '$2==val {printf("%s", $1)}' ${maxlist}) ".pad")
+               cp ${maxlist} ${rootname}.avglst
+               cp ${rootname}.pad.avg ${rootname}.pad.avg0
+               maxpos=$(awk -v val=${root} '$2==val {printf("%f", $3)}' ${maxlist})
+               line=$(awk -v val=${root} '$2==val {print NR}' ${maxlist})
+               head -$((${line} - 1)) ${maxlist} > ${i}.lst
+               tail -$(($(wc -l ${maxlist} | awk '{print $1}') - ${line} + 1)) ${maxlist} > tmp
+               cp tmp ${maxlist}
+               
+               max_t=$(wc -l ${maxtree} | awk '{printf $1}')
+               max_l=$(wc -l ${maxlist} | awk '{printf $1}')
+               line_t=$(awk -v val=${root} '$1==val {print NR}' ${maxtree})
+               head -$((${max_l} + ${line_t} - 1)) ${maxtree} | tail -$((${max_l} - 1)) > tmp
+               tail -$((${max_t} - ${max_l})) ${maxtree} > ${i}.tree
+               cp tmp ${maxtree}
+       done
+       
+       for (( i=1; i<={$divide}; i++ ))
+       do
+               for data in $(awk '{print $1}' ${i}.lst)
+               do
+                       cp ${data} ${data}${i}
+                       cp ${data}.avg ${data}.avg${i}
+               done
+       done
+End
+
+Rule Refinement
+       input '*.pad{$num}'.all
+       input '*.avg{$num}'.all
+       input '{$num}.lst'
+       input '{$num}.tree'
+       input 'Makefile.config'
+       output ($I[1][1].str()+".pad.avg").d().all()
+       output ($I[1][1].str()+".pad.avg.tiff").d().all()
+       output ($I[1][1].str()+".pad.avg"+$num.str()+".tiff").d().all()
+Action
+       max=$(wc -l {$num}.tree | awk '{printf $1}')
+       data=$(head -1 {$num}.tree)
+       i=$(echo ${data} | awk '{print $1}')
+       name=$(basename $(awk -v i=${i} '$2==i {print $1}' {$num}.lst) ".pad")
+       cp {$num}.lst ${name}.avglst
+       cp {$num}.tree ${name}.tree
+       
+       for (( k=1; k<=max ; k++ ))
+       do
+               i=$(head -${k} {$num}.tree | tail -1 | awk '{print $1}')
+               name=$(basename $(awk -v i=${i} '$2==i {print $1}' {$num}.lst) ".pad")
+
+               if [ $(wc -l ${name}.avglst | awk '{print $1}') -gt 2 ] ; then
+                       tpos=$(awk -v i=${i} '$2==i {print NR}' ${name}.avglst)
+                       tline=$(wc -l ${name}.avglst | awk '{print $1}')
+               
+                       head -$((${tline} - ${tpos} + 1)) ${name}.tree | tail -$((${tline} - ${tpos})) > tmp
+                       i_sub1=$(head -1 tmp | tail -1 | awk '{print $1}')
+                       name_sub1=$(basename $(awk -v i=${i_sub1} '$2==i {print $1}' ${name}.avglst) ".pad")
+                       if [ $(wc -l tmp | awk '{print $1}') -ne 0 ] ; then
+                               cp tmp ${name_sub1}.tree
+                               tail -$((${tline} - ${tpos} + 1)) ${name}.avglst > ${name_sub1}.avglst
+                       fi
+               
+                       tail -$((${tpos} - 2)) ${name}.tree > tmp
+                       i_sub2=$(head -1 tmp | awk '{print $1}')
+                       name_sub2=$(basename $(awk -v i=${i_sub2} '$2==i {print $1}' ${name}.avglst) ".pad")
+                       if [ $(wc -l tmp | awk '{print $1}') -ne 0 ] ; then
+                               cp tmp ${name_sub2}.tree
+                               head -$((${tpos} - 1)) ${name}.avglst > ${name_sub2}.avglst
+                       fi
+               fi
+       done
+
+       cat Makefile.config | sed -e s/'='/' '/ > Makefile.config.tmp
+       ClusterCorrelationMode=$(awk '$1=="ClusterCorrelationMode" {print $2}' Makefile.config.tmp)
+       ClusterRotationRangeMin=$(awk '$1=="ClusterRotationRangeMin" {print $2}' Makefile.config.tmp)
+       ClusterRotationRangeMax=$(awk '$1=="ClusterRotationRangeMax" {print $2}' Makefile.config.tmp)
+       ClusterRotationRangePartitionNumber=$(awk '$1=="ClusterRotationRangePartitionNumber" {print $2}' Makefile.config.tmp)
+       ClusterRotationIterationNumber=$(awk '$1=="ClusterRotationIterationNumber" {print $2}' Makefile.config.tmp)
+       ClusterRotationCorrelationMode=$(awk '$1=="ClusterRotationCorrelationMode" {print $2}' Makefile.config.tmp)
+       
+       for data in $(ls *.avglst)
+       do
+               name=$(basename ${data} ".avglst")
+               awk '{print $1}' ${data} | sed -e s/.pad/.pad.fit/ > ${name}.fitlst
+               cp ${name}.pad.avg{$num} ${name}.pad.avg
+               for (( i=0; i < {$refine}; i++ ))
+               do
+                       for element in $(awk '{print $1}' ${data})
+                       do
+                               mrcImageAutoRotationCorrelation -i ${element}{$num} -r ${name}.pad.avg -fit ${element}.fit -cor ${element}.cor -O ${element}.corinfo \
+                                                                                               -Method ${ClusterRotationCorrelationMode} -m ${ClusterCorrelationMode} -Iter ${ClusterRotationIterationNumber} \
+                                                                                               -range ${ClusterRotationRangeMin} ${ClusterRotationRangeMax} -n ${ClusterRotationRangePartitionNumber}
+                       done
+                       
+                       mrcImageAverage -i ${name}.fitlst -o ${name}.pad.avg
+               done
+               mrc2tiff -i ${name}.pad.avg -o ${name}.pad.avg.tiff
+               mrc2tiff -i ${name}.pad.avg{$num} -o ${name}.pad.avg{$num}.tiff
+       done
+End
+
+Rule RefinementRoot
+       input '*.pad'.all
+       input '*.pad.avg0'.all
+       input ($I[2][1].str()+".avglst").d().all()
+       input 'Makefile.config'
+       output ($I[1][1].str()+".pad.avg").d().all()
+       output ($I[1][1].str()+".pad.avg.tiff").d().all()
+       output ($I[1][1].str()+".pad.avg0.tiff").d().all()
+Action
+       cat Makefile.config | sed -e s/'='/' '/ > Makefile.config.tmp
+       ClusterCorrelationMode=$(awk '$1=="ClusterCorrelationMode" {print $2}' Makefile.config.tmp)
+       ClusterRotationRangeMin=$(awk '$1=="ClusterRotationRangeMin" {print $2}' Makefile.config.tmp)
+       ClusterRotationRangeMax=$(awk '$1=="ClusterRotationRangeMax" {print $2}' Makefile.config.tmp)
+       ClusterRotationRangePartitionNumber=$(awk '$1=="ClusterRotationRangePartitionNumber" {print $2}' Makefile.config.tmp)
+       ClusterRotationIterationNumber=$(awk '$1=="ClusterRotationIterationNumber" {print $2}' Makefile.config.tmp)
+       ClusterRotationCorrelationMode=$(awk '$1=="ClusterRotationCorrelationMode" {print $2}' Makefile.config.tmp)
+       
+       for data in $(ls *.avglst)
+       do
+               name=$(basename ${data} ".avglst")
+               awk '{print $1}' ${data} | sed -e s/.pad/.pad.fit/ > ${name}.fitlst
+               cp ${name}.pad.avg0 ${name}.pad.avg
+               for (( i=0; i < {$refine}; i++ ))
+               do
+                       for element in $(awk '{print $1}' ${data})
+                       do
+                               mrcImageAutoRotationCorrelation -i ${element} -r ${name}.pad.avg -fit ${element}.fit -cor ${element}.cor -O ${element}.corinfo \
+                                                                                               -Method ${ClusterRotationCorrelationMode} -m ${ClusterCorrelationMode} -Iter ${ClusterRotationIterationNumber} \
+                                                                                               -range ${ClusterRotationRangeMin} ${ClusterRotationRangeMax} -n ${ClusterRotationRangePartitionNumber}
+                       done
+                       
+                       mrcImageAverage -i ${name}.fitlst -o ${name}.pad.avg
+               done
+               mrc2tiff -i ${name}.pad.avg -o ${name}.pad.avg.tiff
+               mrc2tiff -i ${name}.pad.avg0 -o ${name}.pad.avg0.tiff
+       done
+End
+
+Rule MontageAverage
+       input 'all.avgsortlst'
+       input 'all.treeinfo'
+       input '*.pad.avg'.all
+       output 'all.avgrefinemon'
+       output 'all.avgrefinemon.tiff'
+Action
+       root=$(head -1 {$I[2]} | awk '{print $1}')
+       root_file=$(awk -v val=${root} '$2==val {print $1}' {$I[1]})
+       cp ${root_file} $(head -1 {$I[1]} | awk '{print $1}')
+       mrcImageMontageCreate -i {$I[1]} -o {$O[1]}
+       mrc2tiff -i {$O[1]} -o {$O[2]}
+End
+
+param $roi := false
diff --git a/SampleCode/PIONE/Advanced5/Main_ROIr.pione b/SampleCode/PIONE/Advanced5/Main_ROIr.pione
new file mode 100644 (file)
index 0000000..0bd60ce
--- /dev/null
@@ -0,0 +1,71 @@
+Rule Main
+       input '*.ref3d'
+       output '*.roi'.all
+       output '*.tiff'.all
+       param $X_SIZE := 32
+       param $Y_SIZE := 32
+       param $ROI_ROT_MODE := "XEYS"
+       param $ROI_ROT1_NUM := 3
+       param $ROI_ROT2_NUM := 3
+       param $ROI_ROT3_NUM := 3
+       param $ROI_SHIFT_NUM := 2
+       param $ROI_SN := 1
+       param $ROI_NOISE_NUM := 1
+Action
+       data=$(mrcInfo -i {$I[1]} | head -1)
+       x_size=$(echo "${data}" | awk '{printf ("%i", $4)}')
+       y_size=$(echo "${data}" | awk '{printf ("%i", $5)}')
+       z_size=$(echo "${data}" | awk '{printf ("%i", $6)}')
+
+       data=$(mrcInfo -i {$I[1]} | head -5 | tail -1)
+       x_length=$(echo "${data}" | awk '{printf ("%f", $4)}')
+       y_length=$(echo "${data}" | awk '{printf ("%f", $5)}')
+       z_length=$(echo "${data}" | awk '{printf ("%f", $6)}')
+       
+       ref_size=${x_size}
+       length=${x_length}
+       
+       if [ ${ref_size} -lt ${y_size} ] ; then \
+               ref_size=${y_size}
+               length=${y_length}
+       fi
+       
+       if [ ${ref_size} -lt ${z_size} ] ; then \
+               ref_size=${z_size}
+               length=${z_length}
+       fi
+       
+       image_size={$X_SIZE}
+       
+       if [ ${image_size} -lt {$Y_SIZE} ] ; then \
+               image_size={$Y_SIZE}
+       fi
+       
+       sampling_length=$(echo "scale=7; ${length} * ${ref_size} / ${image_size}" | bc)
+       
+       mrcImageSamplingUnitChange -i {$I[1]} -o {$I[1][1]}.sample3d -m 2 -S ${sampling_length} ${sampling_length} ${sampling_length}
+
+       for rot1 in $(randomUniformGet -n {$ROI_ROT1_NUM} -min 0 -max 359)
+       do
+               for rot2 in $(randomUniformGet -n {$ROI_ROT2_NUM} -min 0 -max 359)
+               do
+                       for rot3 in $(randomUniformGet -n {$ROI_ROT3_NUM} -min 0 -max 359)
+                       do
+                               mrc3Dto2D       -i {$I[1][1]}.sample3d -o {$I[1][1]}-${rot1}-${rot2}-${rot3}.data2d -InterpolationMode 2 -EulerMode {$ROI_ROT_MODE} \
+                                                       -Rot1 ${rot1} ${rot1} 1 \
+                                                       -Rot2 ${rot2} ${rot2} 1 \
+                                                       -Rot3 ${rot3} ${rot3} 1
+                               random_list=($(randomUniformGet -n {$ROI_SHIFT_NUM*2} -min -4 -max 4))
+                               for (( j=0; j<{$ROI_SHIFT_NUM*2}; j+=2 ))
+                               do
+                                       mrcImageShift -i {$I[1][1]}-${rot1}-${rot2}-${rot3}.data2d -o {$I[1][1]}-${rot1}-${rot2}-${rot3}-${j}.shift2d -x ${random_list[${j}]} -y ${random_list[((${j}+1))]}
+                                       for (( i=0; i<{$ROI_NOISE_NUM}; i++ ))
+                                       do
+                                               mrcImageNoiseAdd -i {$I[1][1]}-${rot1}-${rot2}-${rot3}-${j}.shift2d -o {$I[1][1]}-${rot1}-${rot2}-${rot3}-${j}-${i}.roi -SN {$ROI_SN}
+                                               mrc2tiff -i {$I[1][1]}-${rot1}-${rot2}-${rot3}-${j}-${i}.roi -o {$I[1][1]}-${rot1}-${rot2}-${rot3}-${j}-${i}.tiff
+                                       done
+                               done
+                       done
+               done
+       done
+End