OSDN Git Service

Add: PIONE tutorial for Clustering.
[eos/tutorial.git] / SampleCode / PIONE / Advanced5 / Main.pione
1 param $task := 2
2 param $divide := 2
3 param $refine := 5
4
5 Rule Main
6         input '*.roi'.all
7         input 'Makefile'
8         input 'Makefile.config'
9         output '*.avg'.all
10         output '*.tiff'.all
11         output 'all.logps'
12         output 'all.treeinfo'
13         output 'all.avgsortlst'
14 Flow
15         rule Preprocess {filelist:$I[1].all, num:1.upto($task), length:$I[1].length()}
16         rule Process
17         rule Refinement {num:1.upto($divide)}
18         rule RefinementRoot
19         rule MontageAverage
20 End
21
22 Rule Preprocess
23         input $filelist.nth(((($num-1)*((($length-1)/$task)+1))+1).upto((($num*((($length-1)/$task)+1))|$length).min()))
24         input 'Makefile'
25         input 'Makefile.config'
26         output '*.pad'.all
27 Action
28         for data in {$I[1]}
29         do
30                 make $(basename ${data} ".roi").pad
31         done
32 End
33
34 Rule Process
35         input '*.pad'.all
36         input 'Makefile'
37         input 'Makefile.config'
38         output 'all.padsortlst'
39         output 'all.treeinfo'
40         output 'all.avgsortlst'
41         output ((1.upto($divide).str())+".lst").d().all()
42         output ((1.upto($divide).str())+".tree").d().all()
43         output ("*.pad"+(1.upto($divide).str())).d().all()
44         output ("*.avg"+(0.upto($divide).str())).d().all()
45         output '*.avglst'.all
46         output 'all.padsortmon.tiff'
47         output 'all.avgsortmon.tiff'
48         output 'all.logps'
49 Action
50         ls -1 *.pad > all.padlst
51         make Log
52         make LogPS
53         mrc2tiff -i all.padsortmon -o all.padsortmon.tiff
54         mrc2tiff -i all.avgsortmon -o all.avgsortmon.tiff
55         
56         cp {$O[1]} 1.lst
57         cp {$O[2]} 1.tree
58         for (( i=2; i<={$divide}; i++ ))
59         do
60                 max=0
61                 for data in $(ls *.lst)
62                 do
63                         num=$(wc -l ${data} | awk '{printf $1}')
64                         if [ ${num} -gt ${max} ] ; then
65                                 max=${num}
66                                 maxlist="${data}"
67                         fi
68                 done
69                 maxtree="$(basename ${maxlist} '.lst').tree"
70                 root=$(head -1 ${maxtree} | awk '{printf("%d", $1)}')
71                 rootname=$(basename $(awk -v val=${root} '$2==val {printf("%s", $1)}' ${maxlist}) ".pad")
72                 cp ${maxlist} ${rootname}.avglst
73                 cp ${rootname}.pad.avg ${rootname}.pad.avg0
74                 maxpos=$(awk -v val=${root} '$2==val {printf("%f", $3)}' ${maxlist})
75                 line=$(awk -v val=${root} '$2==val {print NR}' ${maxlist})
76                 head -$((${line} - 1)) ${maxlist} > ${i}.lst
77                 tail -$(($(wc -l ${maxlist} | awk '{print $1}') - ${line} + 1)) ${maxlist} > tmp
78                 cp tmp ${maxlist}
79                 
80                 max_t=$(wc -l ${maxtree} | awk '{printf $1}')
81                 max_l=$(wc -l ${maxlist} | awk '{printf $1}')
82                 line_t=$(awk -v val=${root} '$1==val {print NR}' ${maxtree})
83                 head -$((${max_l} + ${line_t} - 1)) ${maxtree} | tail -$((${max_l} - 1)) > tmp
84                 tail -$((${max_t} - ${max_l})) ${maxtree} > ${i}.tree
85                 cp tmp ${maxtree}
86         done
87         
88         for (( i=1; i<={$divide}; i++ ))
89         do
90                 for data in $(awk '{print $1}' ${i}.lst)
91                 do
92                         cp ${data} ${data}${i}
93                         cp ${data}.avg ${data}.avg${i}
94                 done
95         done
96 End
97
98 Rule Refinement
99         input '*.pad{$num}'.all
100         input '*.avg{$num}'.all
101         input '{$num}.lst'
102         input '{$num}.tree'
103         input 'Makefile.config'
104         output ($I[1][1].str()+".pad.avg").d().all()
105         output ($I[1][1].str()+".pad.avg.tiff").d().all()
106         output ($I[1][1].str()+".pad.avg"+$num.str()+".tiff").d().all()
107 Action
108         max=$(wc -l {$num}.tree | awk '{printf $1}')
109         data=$(head -1 {$num}.tree)
110         i=$(echo ${data} | awk '{print $1}')
111         name=$(basename $(awk -v i=${i} '$2==i {print $1}' {$num}.lst) ".pad")
112         cp {$num}.lst ${name}.avglst
113         cp {$num}.tree ${name}.tree
114         
115         for (( k=1; k<=max ; k++ ))
116         do
117                 i=$(head -${k} {$num}.tree | tail -1 | awk '{print $1}')
118                 name=$(basename $(awk -v i=${i} '$2==i {print $1}' {$num}.lst) ".pad")
119
120                 if [ $(wc -l ${name}.avglst | awk '{print $1}') -gt 2 ] ; then
121                         tpos=$(awk -v i=${i} '$2==i {print NR}' ${name}.avglst)
122                         tline=$(wc -l ${name}.avglst | awk '{print $1}')
123                 
124                         head -$((${tline} - ${tpos} + 1)) ${name}.tree | tail -$((${tline} - ${tpos})) > tmp
125                         i_sub1=$(head -1 tmp | tail -1 | awk '{print $1}')
126                         name_sub1=$(basename $(awk -v i=${i_sub1} '$2==i {print $1}' ${name}.avglst) ".pad")
127                         if [ $(wc -l tmp | awk '{print $1}') -ne 0 ] ; then
128                                 cp tmp ${name_sub1}.tree
129                                 tail -$((${tline} - ${tpos} + 1)) ${name}.avglst > ${name_sub1}.avglst
130                         fi
131                 
132                         tail -$((${tpos} - 2)) ${name}.tree > tmp
133                         i_sub2=$(head -1 tmp | awk '{print $1}')
134                         name_sub2=$(basename $(awk -v i=${i_sub2} '$2==i {print $1}' ${name}.avglst) ".pad")
135                         if [ $(wc -l tmp | awk '{print $1}') -ne 0 ] ; then
136                                 cp tmp ${name_sub2}.tree
137                                 head -$((${tpos} - 1)) ${name}.avglst > ${name_sub2}.avglst
138                         fi
139                 fi
140         done
141
142         cat Makefile.config | sed -e s/'='/' '/ > Makefile.config.tmp
143         ClusterCorrelationMode=$(awk '$1=="ClusterCorrelationMode" {print $2}' Makefile.config.tmp)
144         ClusterRotationRangeMin=$(awk '$1=="ClusterRotationRangeMin" {print $2}' Makefile.config.tmp)
145         ClusterRotationRangeMax=$(awk '$1=="ClusterRotationRangeMax" {print $2}' Makefile.config.tmp)
146         ClusterRotationRangePartitionNumber=$(awk '$1=="ClusterRotationRangePartitionNumber" {print $2}' Makefile.config.tmp)
147         ClusterRotationIterationNumber=$(awk '$1=="ClusterRotationIterationNumber" {print $2}' Makefile.config.tmp)
148         ClusterRotationCorrelationMode=$(awk '$1=="ClusterRotationCorrelationMode" {print $2}' Makefile.config.tmp)
149         
150         for data in $(ls *.avglst)
151         do
152                 name=$(basename ${data} ".avglst")
153                 awk '{print $1}' ${data} | sed -e s/.pad/.pad.fit/ > ${name}.fitlst
154                 cp ${name}.pad.avg{$num} ${name}.pad.avg
155                 for (( i=0; i < {$refine}; i++ ))
156                 do
157                         for element in $(awk '{print $1}' ${data})
158                         do
159                                 mrcImageAutoRotationCorrelation -i ${element}{$num} -r ${name}.pad.avg -fit ${element}.fit -cor ${element}.cor -O ${element}.corinfo \
160                                                                                                 -Method ${ClusterRotationCorrelationMode} -m ${ClusterCorrelationMode} -Iter ${ClusterRotationIterationNumber} \
161                                                                                                 -range ${ClusterRotationRangeMin} ${ClusterRotationRangeMax} -n ${ClusterRotationRangePartitionNumber}
162                         done
163                         
164                         mrcImageAverage -i ${name}.fitlst -o ${name}.pad.avg
165                 done
166                 mrc2tiff -i ${name}.pad.avg -o ${name}.pad.avg.tiff
167                 mrc2tiff -i ${name}.pad.avg{$num} -o ${name}.pad.avg{$num}.tiff
168         done
169 End
170
171 Rule RefinementRoot
172         input '*.pad'.all
173         input '*.pad.avg0'.all
174         input ($I[2][1].str()+".avglst").d().all()
175         input 'Makefile.config'
176         output ($I[1][1].str()+".pad.avg").d().all()
177         output ($I[1][1].str()+".pad.avg.tiff").d().all()
178         output ($I[1][1].str()+".pad.avg0.tiff").d().all()
179 Action
180         cat Makefile.config | sed -e s/'='/' '/ > Makefile.config.tmp
181         ClusterCorrelationMode=$(awk '$1=="ClusterCorrelationMode" {print $2}' Makefile.config.tmp)
182         ClusterRotationRangeMin=$(awk '$1=="ClusterRotationRangeMin" {print $2}' Makefile.config.tmp)
183         ClusterRotationRangeMax=$(awk '$1=="ClusterRotationRangeMax" {print $2}' Makefile.config.tmp)
184         ClusterRotationRangePartitionNumber=$(awk '$1=="ClusterRotationRangePartitionNumber" {print $2}' Makefile.config.tmp)
185         ClusterRotationIterationNumber=$(awk '$1=="ClusterRotationIterationNumber" {print $2}' Makefile.config.tmp)
186         ClusterRotationCorrelationMode=$(awk '$1=="ClusterRotationCorrelationMode" {print $2}' Makefile.config.tmp)
187         
188         for data in $(ls *.avglst)
189         do
190                 name=$(basename ${data} ".avglst")
191                 awk '{print $1}' ${data} | sed -e s/.pad/.pad.fit/ > ${name}.fitlst
192                 cp ${name}.pad.avg0 ${name}.pad.avg
193                 for (( i=0; i < {$refine}; i++ ))
194                 do
195                         for element in $(awk '{print $1}' ${data})
196                         do
197                                 mrcImageAutoRotationCorrelation -i ${element} -r ${name}.pad.avg -fit ${element}.fit -cor ${element}.cor -O ${element}.corinfo \
198                                                                                                 -Method ${ClusterRotationCorrelationMode} -m ${ClusterCorrelationMode} -Iter ${ClusterRotationIterationNumber} \
199                                                                                                 -range ${ClusterRotationRangeMin} ${ClusterRotationRangeMax} -n ${ClusterRotationRangePartitionNumber}
200                         done
201                         
202                         mrcImageAverage -i ${name}.fitlst -o ${name}.pad.avg
203                 done
204                 mrc2tiff -i ${name}.pad.avg -o ${name}.pad.avg.tiff
205                 mrc2tiff -i ${name}.pad.avg0 -o ${name}.pad.avg0.tiff
206         done
207 End
208
209 Rule MontageAverage
210         input 'all.avgsortlst'
211         input 'all.treeinfo'
212         input '*.pad.avg'.all
213         output 'all.avgrefinemon'
214         output 'all.avgrefinemon.tiff'
215 Action
216         root=$(head -1 {$I[2]} | awk '{print $1}')
217         root_file=$(awk -v val=${root} '$2==val {print $1}' {$I[1]})
218         cp ${root_file} $(head -1 {$I[1]} | awk '{print $1}')
219         mrcImageMontageCreate -i {$I[1]} -o {$O[1]}
220         mrc2tiff -i {$O[1]} -o {$O[2]}
221 End
222
223 param $roi := false