Skip to content

Commit 4f2aa2a

Browse files
laemtlregisoc
andauthored
Project, event validation and protobuf update (#823)
* Project, event validation and protobuf update * Site and project search when creating candidate * missing import * correct pscid search * Events validation * flake rules update * review, and NULL value filtered out for site and project * flake * flake Co-authored-by: regisoc <regis.ongaro-carcy@mcin.ca>
1 parent 565ad5e commit 4f2aa2a

File tree

5 files changed

+70
-99
lines changed

5 files changed

+70
-99
lines changed

.github/workflows/flake8_python_linter.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535
# E241: Multiple spaces after ','
3636
# E251: Unexpected spaces around keyword / parameter equals
3737
# E272: Multiple spaces before keyword
38-
flake8_args: "--ignore=W291,W292,W293,E202,E203,E221,E241,E251,E272 --max-line-length 120"
38+
flake8_args: "--ignore=W291,W292,W293,W503,E202,E203,E221,E241,E251,E272
39+
--max-line-length 120
40+
--exclude python/react-series-data-viewer/protocol_buffers/"
3941
github_token: ${{ secrets.GITHUB_TOKEN }}
4042

python/lib/candidate.py

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,53 +83,87 @@ def create_candidate(self, db, participants_info):
8383
if 'age' in row:
8484
self.age = row['age']
8585

86-
if 'site' in row:
86+
# three steps to find site:
87+
# 1. try matching full name from 'site' column in participants.tsv in db
88+
# 2. try extracting alias from pscid
89+
# 3. try finding previous site in candidate table
90+
91+
if 'site' in row and row['site'].lower() not in ("null", ""):
92+
# search site id in psc table by its full name
8793
site_info = db.pselect(
8894
"SELECT CenterID FROM psc WHERE Name = %s",
8995
[row['site'], ]
9096
)
91-
if(len(site_info) > 0):
97+
if len(site_info) > 0:
9298
self.center_id = site_info[0]['CenterID']
93-
else:
99+
100+
if self.center_id is None:
101+
# search site id in psc table by its alias extracted from pscid
94102
db_sites = db.pselect("SELECT CenterID, Alias FROM psc")
95103
for site in db_sites:
96104
if site['Alias'] in row['participant_id']:
97105
self.center_id = site['CenterID']
98106

99-
if 'project' in row:
107+
if self.center_id is None:
108+
# try to find participant site in db
109+
candidate_site_project = db.pselect(
110+
"SELECT RegistrationCenterID FROM candidate WHERE pscid = %s",
111+
[self.psc_id, ]
112+
)
113+
if len(candidate_site_project) > 0:
114+
self.center_id = candidate_site_project[0]['RegistrationCenterID']
115+
116+
# two steps to find project:
117+
# 1. find full name in 'project' column in participants.tsv
118+
# 2. find previous in candidate table
119+
120+
if 'project' in row and row['project'].lower() not in ("null", ""):
121+
# search project id in Project table by its full name
100122
project_info = db.pselect(
101123
"SELECT ProjectID FROM Project WHERE Name = %s",
102124
[row['project'], ]
103125
)
104-
if(len(project_info) > 0):
126+
if len(project_info) > 0:
105127
self.project_id = project_info[0]['ProjectID']
106128

129+
if self.project_id is None:
130+
# try to find participant project
131+
candidate_site_project = db.pselect(
132+
"SELECT RegistrationProjectID FROM candidate WHERE pscid = %s",
133+
[self.psc_id, ]
134+
)
135+
if len(candidate_site_project) > 0:
136+
self.center_id = candidate_site_project[0]['RegistrationProjectID']
137+
107138
if not self.center_id:
108139
print("ERROR: could not determine site for " + self.psc_id + "."
109140
+ " Please check that your psc table contains a site with an"
110141
+ " alias matching the BIDS participant_id or a name matching the site mentioned in"
111142
+ " participants.tsv's site column")
112143
sys.exit(lib.exitcode.PROJECT_CUSTOMIZATION_FAILURE)
113144

145+
if not self.project_id:
146+
print("ERROR: could not determine project for " + self.psc_id + "."
147+
+ " Please check that your project table contains a project with a"
148+
+ " name matching the participants.tsv's project column")
149+
sys.exit(lib.exitcode.PROJECT_CUSTOMIZATION_FAILURE)
150+
114151
if self.verbose:
115152
print("Creating candidate with \n"
116153
+ "PSCID = " + self.psc_id + ",\n"
117154
+ "CandID = " + str(self.cand_id) + ",\n"
118155
+ "CenterID = " + str(self.center_id) + ",\n"
119156
+ "ProjectID = " + str(self.project_id))
120157

121-
insert_col = ('PSCID', 'CandID', 'RegistrationCenterID')
122-
insert_val = (self.psc_id, str(self.cand_id), str(self.center_id))
158+
insert_col = ('PSCID', 'CandID', 'RegistrationCenterID', 'RegistrationProjectID')
159+
insert_val = (self.psc_id, str(self.cand_id), str(self.center_id), str(self.project_id))
123160

124161
if self.sex:
125162
insert_col = insert_col + ('Sex',)
126163
insert_val = insert_val + (self.sex,)
127164
if self.dob:
128165
insert_col = insert_col + ('DoB',)
129166
insert_val = insert_val + (self.dob,)
130-
if self.project_id:
131-
insert_col = insert_col + ('RegistrationProjectID',)
132-
insert_val = insert_val + (str(self.project_id),)
133167

134168
db.insert(
135169
table_name='candidate',

python/lib/physiological.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -535,13 +535,12 @@ def insert_event_file(self, event_data, event_file, physiological_file_id,
535535
if field not in row.keys():
536536
row[field] = None
537537

538-
# TODO: remove the following if once received confirmation from
539-
# TODO: James it was an error.
540-
if "NaN" in row['duration']:
541-
row['duration'] = 0
538+
duration = 0
539+
if (type(row['duration']) == int or type(row['duration']) == float):
540+
duration = row['duration']
542541

543542
sample = None
544-
if row['event_sample'] and (type(row['event_sample']) == int or type(row['event_sample']) == float):
543+
if type(row['event_sample']) == int or type(row['event_sample']) == float:
545544
sample = row['event_sample']
546545
if row['sample'] and (type(row['sample']) == int or type(row['sample']) == float):
547546
sample = row['sample']
@@ -552,12 +551,16 @@ def insert_event_file(self, event_data, event_file, physiological_file_id,
552551
elif row['value']:
553552
event_value = str(row['value'])
554553

554+
response_time = None
555+
if type(row['response_time']) == int or type(row['response_time']) == float:
556+
response_time = row['response_time']
557+
555558
values_tuple = (
556559
str(physiological_file_id),
557560
row['onset'],
558-
row['duration'],
561+
duration,
559562
row['trial_type'],
560-
row['response_time'],
563+
response_time,
561564
row['event_code'],
562565
event_value,
563566
sample,

python/react-series-data-viewer/chunking.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
from scipy import signal
88
import sys
99

10-
try:
11-
from .protocol_buffers import chunk_pb2 as chunk_pb
12-
except Exception:
13-
from protocol_buffers import chunk_pb2 as chunk_pb
10+
from protocol_buffers import chunk_pb2 as chunk_pb
1411

1512

1613
def pad_channels(channels, chunk_size):

python/react-series-data-viewer/protocol_buffers/chunk_pb2.py

Lines changed: 12 additions & 77 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)