5 Restacking Aligned Falcon Frames for Tomography

Captured frame stack has date and time stamp in the filename, such as Falcon_2014_03_01-22_20_46_0.mrcs, but it doesn't have any tilting angle information like in extended header of SerialEM stacks. Recent implement of bi-directional way of collecting a tilting series in SerialEM makes this order even more complicated. We need a way to assemble all the aligned outputs from each captured Falcon stack into a tilting stack with the same correct order as mdoc file. Considering there could be time difference between capturing Linux computer and Tf30 computer on which mdoc file is generated, I have found that it is not a very easy job to me. I finally come up a script to do it. I hope that , there is a much better and easy way.

Basically, I extract DateTime info from the mdoc file and compare it with the timestamp in Falcon frame filenames. If it is less then a threshold value, I conclude it is THAT tilt. I made it into a fileinput and stack them using newstack.

Example 3. stack-Falcon-Frames-by-mdoc.sh


# find correspondent Falcon*.mrc file belong to which
# section (tilts) and stack them together. 

usage (){
	echo usage: $0 "mdoc-file"

if [ $# -ne 1 ]; then

grep -n $var $mdoc > tmp
no=`grep -c $var $mdoc`
echo $no > fileinlist
while read line; do
#Z=`echo $line | cut -d":" -f2 | grep -oP '\[\K[^\]]+'`
      Z=`echo $line | cut -d":" -f2`
      line=`echo $line | cut -d":" -f1` 
      tiltline=`expr $line + 1`
      tilt=`sed -n ${tiltline}p $mdoc | cut -d"=" -f2 | tr '\n' ' '`
      line=`expr $line + 18`
      datetime=`sed -n ${line}p $mdoc | cut -d"=" -f2 | tr '\n' ' '`
      sec_mdoc=`date --date "$datetime" +%s`
      for file in Falcon*.mrc; do
            year=`basename $file .mrc | cut -d"-" -f1 | cut -d"_" -f2`
            month=`basename $file .mrc | cut -d"-" -f1 | cut -d"_" -f3`
            mon=`date --date $month +%b`
            date=`basename $file .mrc | cut -d"-" -f1 | cut -d"_" -f4`
            hour=`basename $file .mrc | cut -d"-" -f2 | cut -d"_" -f1`
            min=`basename $file .mrc | cut -d"-" -f2 | cut -d"_" -f2`
            sec=`basename $file .mrc | cut -d"-" -f2 | cut -d"_" -f3`
            str_datetime="$date-$mon-$year $hour:$min:$sec"
            second=`date --date "$str_datetime" +%s`
            diff=`expr $sec_mdoc - $second`
            abs=`echo ${diff#-}`
            if [ "$abs" -le "${offset}" ]; then
              echo ""
              echo "      $datetime"
              echo $file "--" "$Z"
              echo "      Tilt angle =$tilt"			
              echo $file >> fileinlist			
              echo 0 >> fileinlist
            #  echo too different
done < tmp
#rm -f tmp

# make the stack file
newstack --fileinlist fileinlist Falcon-`echo $mdoc | cut -d"." -f1`.st