-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrelion.star_data_handler.sh
More file actions
executable file
·79 lines (69 loc) · 2.16 KB
/
relion.star_data_handler.sh
File metadata and controls
executable file
·79 lines (69 loc) · 2.16 KB
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
#!/bin/bash
#
echo "------------------------------------------------------------------"
echo "$(basename $0)"
echo "------------------------------------------------------------------"
echo "-i - input star file (required)"
echo "-o - output star file (required)"
echo "-d - Delete column (name)"
echo ""
echo "------------------------------------------------------------------"
flagcheck=0
while getopts ':-i:d:o:' flag; do
case "${flag}" in
i) starin=$OPTARG
flagcheck=0 ;;
o) starout=$OPTARG
flagcheck=1 ;;
d) columndel=$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
#Get input star file basename
file=$(basename $starin .star)
#Dir out
dirout=.star_data_handler
#Delete column
if [[ -z $columndel ]] ; then
echo 'No column to delete'
else
#Split star file into parts
relion.star_data_extract.sh $starin $dirout
#Find column number
columndelno=$(grep $columndel $dirout/mainDataHeader.dat | awk '{print $2}' | sed 's/#//g')
if [[ -z $columndelno ]] ; then
echo ''
echo 'Column not found, skipping delete option...'
else
#Remove column data
awk -v col=$columndelno '!($col="")' $dirout/mainDataLines.dat > $dirout/.tmp.dat
mv $dirout/.tmp.dat $dirout/mainDataLines.dat
#Reformat data header - remove header for deleted column and renumber columns
grep -v $columndel $dirout/mainDataHeader.dat | grep '_rln' | cut -d "#" -f1 | awk '{print $0,"#"FNR}' > $dirout/.tmp.dat
#Reformat data header - renumber the header columns
printf "data_particles\nloop\n" | cat - $dirout/.tmp.dat > $dirout/mainDataHeader.dat
fi
fi
if [[ -z $starout ]] ; then
echo 'No output...'
else
#Recombine to new star file
cat $dirout/.version.dat <(echo) $dirout/opticsDataHeader.dat $dirout/opticsDataLines.dat <(echo) $dirout/.version.dat <(echo) $dirout/mainDataHeader.dat $dirout/mainDataLines.dat > tmp.star
mv tmp.star $starout
fi
# Finish
echo ""
echo "Done!"
echo "Script written by Kyle Morris"
echo ""