-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheztrack-main
executable file
·118 lines (89 loc) · 4.82 KB
/
eztrack-main
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
#!/usr/bin/env bash
PROJECT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
patient_id=$1
[[ ! -z "$patient_id" ]] || { echo "Usage: $0 <patient_id (e.g. PY12N008)>" ; exit 1 ; }
set -eu
matlab_jvm="matlab -nodesktop -nosplash -r"
[[ ! -z "`which matlab`" ]] || \
{ echo "MATLAB not found on the PATH; please check the Getting Started section in the README" ; exit 1 ; }
####### Input parameter validation #######
# Force GNU date syntax via coreutils on OS X
date=date
if [[ $OSTYPE == darwin* ]]; then
date=gdate
fi
offset=60000000 # one minute pre and post-ictal period offset in microseconds
frequency=1000 # number of samples / second in source data
printf "\n== Validating $patient_id.csv ==\n"
# Events should be marked up by the clinician as follows in, e.g. PY15N012.csv
#
# patient_id,date,onset_time,offset_time,num_channels,included_channels
# PY15N012,2015-08-17,16:16:57,16:21:57,48,[1:48]
# Read the csv: Assume only one entry for now, though we could process all to find all segments, start, and end marks.
IFS=',' read -r -a inputs <<< "$(head -n 2 $PROJECT_HOME/data/patients/$patient_id.csv | tail -n 1)"
# dt="${inputs[1]}"
# recording_start="${inputs[2]}"
# s_onset="${inputs[3]}"
# s_offset="${inputs[4]}"
# recording_duration="${inputs[5]}"
# num_channels="${inputs[6]}"
# included_channels="${inputs[7]}"
# Convert dates to uUTC:
# recording_start_time=$(TZ=America/New_York $date --date="$dt $recording_start" +%s%6N)
# seizure_onset_time=$(TZ=America/New_York $date --date="$dt $s_onset" +%s%6N)
# seizure_offset_time=$(TZ=America/New_York $date --date="$dt $s_offset" +%s%6N)
# printf "recording_start_time\t${recording_start_time}\n"
# printf "seizure_onset_time\t${seizure_onset_time}\n"
# printf "seizure_offset_time\t${seizure_offset_time}\n\n"
# start_mark=$(( (seizure_onset_time - recording_start_time) / 1000000 ))
# echo "start mark must be greater than 60:"
# printf "\tstart_mark:\t$start_mark\n"
# # TODO: Review whether or not to give the end mark offset a 1s wider margin to avoid 'Matrix dimensions must agree' errors.
# end_mark=$(( (seizure_offset_time - recording_start_time) / 1000000 ))
# echo "end_mark must be at least 60s less than recording_duration."
# printf "\tend_mark:\t$end_mark\n"
# printf "\trecording_duration:\t$recording_duration\n"
# number_of_samples=$(( recording_duration * frequency ))
# printf "\tnumber_of_samples:\t$number_of_samples\n"
# For EZT data:
dt="${inputs[1]}"
recording_start="${inputs[2]}"
start_mark="${inputs[3]}"
end_mark="${inputs[4]}"
number_of_samples="${inputs[5]}"
num_channels="${inputs[6]}"
included_channels="${inputs[7]}"
start_mark=$(( start_mark / 1000 ))
echo "start mark must be greater than 60:"
printf "\tstart_mark:\t$start_mark\n"
end_mark=$(( end_mark / 1000 ))
echo "end_mark must be at least 60s less than recording_duration."
printf "\tend_mark:\t$end_mark\n"
recording_duration=$(( number_of_samples / 1000 ))
printf "\trecording_duration:\t$recording_duration\n"
###### End of input parameter validation #######
sizes="[$number_of_samples]" # number of samples in each file. For PY12N008: "[640000, 672000, 737000, 729000] corresponding to 640s, 672s, etc. at 1kHz"
eeg_output=$PROJECT_HOME/output/eeg/$patient_id
eeg2fsv_out=$eeg_output/adj_pwr
temporal_out=/tmp/eztrack-temporal
############################## Run EEG to Frequency Singular Values ##############################
# comment out if already ran to save time!
printf "\n== eeg2fsv ==\n"
rm -rf $eeg2fsv_out
cd $PROJECT_HOME/eeg2fsv && \
echo "Invoking matlab with eeg2fsv('$eeg_output', '$patient_id', $num_channels, $included_channels, $sizes, $frequency)" && \
$matlab_jvm "eeg2fsv('${eeg_output}/', '$patient_id', $num_channels, $included_channels, $sizes, $frequency); exit"
# Copy results to output dir used in fsv2heatmap computation.
cp $eeg2fsv_out/svd_vectors/fsv_pwr$patient_id.mat $PROJECT_HOME/output/fsv
# Copy the list of labels extracted from the EDF files to a backup.
cp $eeg_output/${patient_id}_labels.csv $eeg_output/${patient_id}_all_labels.csv
# Copy the list of labels that will actually be used in the analysis.
# cp $PROJECT_HOME/data/patients/${patient_id}_channels.csv $eeg_output/${patient_id}_labels.csv
############################## Create Heatmap from FSV ##############################
printf "\n== fsv2heatmap ==\n"
cd $PROJECT_HOME/fsv2heatmap && \
$matlab_jvm "csv_file = temporal_ieeg_results('$PROJECT_HOME', '$patient_id', '${patient_id}_labels.csv', $included_channels, $start_mark, $end_mark, $frequency); display(csv_file); exit" > $temporal_out
# HACK: Have fsv2heatmap save this output path to a different file to avoid relying on position with tail.
results=`tail -n 3 $temporal_out | head -n 1`
echo $results > /tmp/eztrack.out
printf "\nEZTrack is finished processing $patient_id. Results saved to:\n$results\nThis path is also in /tmp/eztrack.out\n"