-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepu.plot_coords_v2.sh
executable file
·179 lines (160 loc) · 4.98 KB
/
epu.plot_coords_v2.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
#
#
############################################################################
#
# Author: "Kyle L. Morris"
# eBIC Diamond Light Source 2022
# MRC London Institute of Medical Sciences 2019
#
# 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/>.
#
############################################################################
# https://stackoverflow.com/questions/29449675/gnuplot-plot-image-without-white-border
echo "------------------------------------------------------------------"
echo "$(basename $0)"
echo "------------------------------------------------------------------"
echo "-i - Star file input (required)"
echo "-m - Search term for micrograph to plot coordinates"
echo " Type 'all' to plot all coordinates"
echo " Useful if plotting from *manualpick.star"
echo "-x - Detector size px x"
echo "-y - Detector size px y"
echo "-d - Pick diameter (px)"
echo "-s - Surpress output (optional) y/n"
echo "-f - Flip coordinates (optional) y/n"
echo "-o - Output directory (optional)"
echo ""
echo "------------------------------------------------------------------"
flagcheck=0
while getopts ':-i:m:x:y:d:s:f:o:' flag; do
case "${flag}" in
i) starin=$OPTARG
flagcheck=0 ;;
m) mic=$OPTARG
flagcheck=1 ;;
x) x=$OPTARG
flagcheck=1 ;;
y) y=$OPTARG
flagcheck=1 ;;
d) d=$OPTARG # For manual input
flagcheck=1 ;;
s) suppress=$OPTARG
flagcheck=1 ;;
f) flip=$OPTARG
flagcheck=1 ;;
o) dirout=$OPTARG
flagcheck=1 ;;
\?)
echo ""
echo "Invalid option, please read initial program instructions..."
echo ""
exit 1 ;;
esac
done
if [ $flagcheck = 0 ] ; then
echo ""
echo "No options used, exiting, I require an input..."
echo ""
exit 1
fi
# Program display
# https://stackoverflow.com/questions/394230/how-to-detect-the-os-from-a-bash-script/18434831
if [[ "$OSTYPE" == "linux-gnu" ]]; then
display=eog
elif [[ "$OSTYPE" == "darwin"* ]]; then
display=open
else
echo 'OS type unknown'
fi
# Directory and folder names of the inputs
ext=$(echo ${starin##*.})
name=$(basename $starin .${ext})
dir=$(dirname $starin)
# Coordinate column names
coord1=rlnCoordinateX
coord2=rlnCoordinateY
#Get column number in sar file
echo ''
echo 'star file in: ' $starin
echo 'Column name to plot: ' $coord1
echo 'Column name to plot: ' $coord2
echo ''
column1=$(grep ${coord1} ${starin} | awk '{print $2}' | sed 's/#//g')
columnname1=$(grep ${coord1} ${starin} | awk '{print $1}' | sed 's/#//g')
column2=$(grep ${coord2} ${starin} | awk '{print $2}' | sed 's/#//g')
columnname2=$(grep ${coord2} ${starin} | awk '{print $1}' | sed 's/#//g')
echo "Column number: #${column1}"
echo "Column number: #${column2}"
echo ''
#Report important inputs
echo "Detector size input as (px): ${x} x ${y}"
echo ""
#Send column data to file, filter out empty lines and remove any file path or particle numbering
if [[ $mic == "all" ]]; then
awk 'NF > 2' ${starin} | awk -v column1=$column1 -v column2=$column2 {'print $column1,$column2'} | grep -v '^$' | sed 's!.*/!!' > .coordinates.dat
output=$name
else
grep ${mic} ${starin} | awk -v column1=$column1 -v column2=$column2 {'print $column1,$column2'} | grep -v '^$' | sed 's!.*/!!' > .coordinates.dat
output=$mic
fi
#Report how many particles
echo 'Number of particles in star file to plot coordinates: ' $(wc -l .coordinates.dat | awk '{print $1}')
# Reverse axis for horizontal flip or not
if [[ $flip == y ]]; then
reversey="reverse"
reversex=""
elif [[ $flip == x ]]; then
reversey=""
reversex="reverse"
elif [[ $flip == n ]]; then
reversey=""
reversex=""
else
reversey=""
reversex=""
fi
# Output
output="${dirout}${output}_particles.png"
# Plot data
gnuplot <<- EOF
set xrange [0:${x}] $reversex
set yrange [0:${y}] $reversey
set term png transparent truecolor
set term png size 1024,1024
set autoscale xfix
set autoscale yfix
set margins 0,0,0,0
unset xtics
unset ytics
unset border
unset key
set output "$output"
plot ".coordinates.dat" using 1:2:(${d}) with circles lc rgb "white" lw 3
EOF
# Tidy up and show plot
if [[ $suppress == "y" ]] ; then
echo "Surpressing output..."
elif [[ $suppress == "n" ]] ; then
$display ${output}
elif [[ -z $suppress ]] ; then
$display ${output}
fi
scp ${output} ${dirout}particles.png
# Finish
echo ""
echo "Done!"
echo "Script written by Kyle Morris"
echo ""
exit