-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrelion.star_info.sh
executable file
·162 lines (140 loc) · 6.24 KB
/
relion.star_info.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
#
#
############################################################################
#
# Author: "Kyle L. Morris"
# University of Warwick 2016
# MRC London Institute of Medical Sciences 2019
# Diamond Light Source 2021
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################################
starin=$1
if [[ -z $1 ]] ; then
echo ""
echo "Variables empty, usage is: "
echo ""
echo "$(basename $0) (1)"
echo ""
echo "(1) = Input star file"
echo ""
exit
fi
# Test if star file is present
if [[ -e $starin ]] ; then
echo ''
echo '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
echo 'Star file found...'
echo '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
echo ''
else
echo ''
echo '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
echo 'Star file not found, exiting...'
echo '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
echo ''
exit
fi
dirout=$(echo ".star_info")
# As of Relion3 star file formatting changed
# Use relion.star_extract_data.sh to extract data and header lines
# Assumes all of bashEM repository is in $PATH
relion.star_data_extract.sh ${starin} ${dirout}
################################################################################
# Process star file
################################################################################
#Read the version
versionSearch=$(cat ${dirout}/.version.dat)
#Calculate number of particles by data lines minus header
totallines=$(wc -l $starin | awk {'print $1'})
#mainHeaderLines=$(wc -l mainDataHeader.dat | awk {'print $1'})
mainDataLines=$(wc -l ${dirout}/mainDataLines.dat | awk {'print $1'})
#opticsHeaderLines=$(wc -l opticsDataHeader.dat | awk {'print $1'})
opticsLines=$(wc -l ${dirout}/opticsDataLines.dat | awk {'print $1'})
#Calculate number of micrographs
columnname=rlnMicrographName
column=$(grep ${columnname} ${dirout}/mainDataHeader.dat | awk '{print $2}' | sed 's/#//g')
#echo $columnname 'is column number:' $column
miclines=$(awk -v column=$column '{print $column}' ${dirout}/mainDataLines.dat | sort -u | wc -l | awk {'print $1'})
#Calculate number of image groups
columnname=rlnGroupNumber
column=$(grep ${columnname} ${dirout}/mainDataHeader.dat | awk '{print $2}' | sed 's/#//g')
#echo $columnname 'is column number:' $column
grouplines=$(awk -v column=$column '{print $column}' ${dirout}/mainDataLines.dat | sort -u | wc -l | awk {'print $1'})
#Calculate number of classes
columnname=rlnClassNumber
column=$(grep ${columnname} ${dirout}/mainDataHeader.dat | awk '{print $2}' | sed 's/#//g')
#echo $columnname 'is column number:' $column
classlines=$(awk -v column=$column '{print $column}' ${dirout}/mainDataLines.dat | sort -u | wc -l | awk {'print $1'})
#Calculate ptcls per micrograph in star file
ptclpermic=$(bc <<< "scale=0; ${mainDataLines}/${miclines}")
#Calculate ptcls per class in star file
ptclperclass=$(bc <<< "scale=0; ${mainDataLines}/${classlines}")
#Find cs (mm)
columnname=rlnSphericalAberration
column=$(grep ${columnname} ${dirout}/opticsDataHeader.dat | awk '{print $2}' | sed 's/#//g')
#echo $columnname 'is column number:' $column
cs=$(awk -v column=$column '{print $column}' ${dirout}/opticsDataLines.dat | head -n 1)
#Calculate pixel size, note micrograph and particle files use rlnMicrographPixelSize and rlnImagePixelSize respectively
columnname=ImagePixelSize
#Assess whether this is a micrograph or particle star file
columnEntry=$(grep ${columnname} ${dirout}/opticsDataHeader.dat | awk '{print $1}')
column=$(grep ${columnname} ${dirout}/opticsDataHeader.dat | awk '{print $2}' | sed 's/#//g')
#echo $columnname 'is column number:' $column
apix=$(awk -v column=$column '{print $column}' ${dirout}/opticsDataLines.dat | head -n 1)
#Get defocus column and calculate minimum and maximum defocus
columnname=rlnDefocusU
column=$(grep ${columnname} ${dirout}/mainDataHeader.dat | awk '{print $2}' | sed 's/#//g')
#echo $columnname 'is column number:' $column
tmp=$(awk -v column=$column '{print $column}' ${dirout}/mainDataLines.dat | awk NF | sort -n | head -n 1)
mindf=$(bc <<< "scale=0; ${tmp}/10")
tmp=$(awk -v column=$column '{print $column}' ${dirout}/mainDataLines.dat | awk NF | sort -n | tail -n 1)
maxdf=$(bc <<< "scale=0; ${tmp}/10")
echo ''
echo '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
echo 'Relion star file information '
echo '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
echo ''
echo 'File: ' $starin
echo 'Relion version: ' $versionSearch
echo ''
#echo 'Number of main data header lines in star file: ' $mainHeaderLines
echo 'Number of data/ptcl lines in star file: ' $mainDataLines
#echo ''
#echo 'Number of optics groups header lines: ' $opticsHeaderLines
echo 'Number of optics groups in star file: ' $opticsLines
echo ''
echo 'Number of unique micrographs in star file: ' $miclines
echo 'Number of image groups in star file: ' $grouplines
echo 'Number of classes in star file: ' $classlines
echo ''
echo 'Particles per micrograph in star file: ' $ptclpermic
echo 'Particles per class in star file: ' $ptclperclass
echo ''
echo 'Calibrated pixel size (apix): ' $apix
echo ''
echo 'Spherical abberation (mm): ' $cs
echo ''
echo 'Minimum defocus (nm): ' $mindf
echo 'Maximum defocus (nm): ' $maxdf
echo ''
echo '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
rm -rf .*.dat
# Finish
echo ""
echo "Done!"
echo "Script written by Kyle Morris"
echo ""