5656 ]
5757TSV_FIELDS ['read_group' ]["conditional" ]= []
5858
59+ EGA_FIELDS = {
60+ "ega_file_id" :"EGAF" ,
61+ "ega_dataset_id" :"EGAD" ,
62+ "ega_experiment_id" :"EGAX" ,
63+ "ega_sample_id" :"EGAN" ,
64+ "ega_study_id" :"EGAS" ,
65+ "ega_run_id" :"EGAR" ,
66+ "ega_policy_id" :"EGAP" ,
67+ "ega_analysis_id" :"EGAZ" ,
68+ "ega_submission_id" :"EGAB" ,
69+ "ega_dac_id" :"EGAC"
70+ }
71+
5972TSV_FIELDS ['file' ]= {}
6073TSV_FIELDS ['file' ]["core" ]= ['type' , 'name' , 'size' , 'md5sum' , 'path' , 'format' ]
61- TSV_FIELDS ['file' ]["conditional" ]= [
62- "ega_file_id" ,"ega_dataset_id" ,"ega_experiment_id" ,"ega_sample_id" ,"ega_study_id" ,
63- "ega_run_id" ,"ega_policy_id" ,"ega_analysis_id" ,"ega_submission_id" ,"ega_dac_id" ]
64-
74+ TSV_FIELDS ['file' ]["conditional" ]= list (EGA_FIELDS .keys ())
6575
6676
6777def empty_str_to_null (metadata ):
@@ -222,10 +232,9 @@ def main(metadata, extra_info=dict()):
222232
223233 # optional experiment arguements
224234 # Strings
225- optional_experimental_fields = [
226- "library_isolation_protocol" ,"library_preparation_kit" ,
227- "library_strandedness" ,"dv200" ,"spike_ins_included" ,
228- "spike_ins_fasta" ,"spike_ins_concentration" ,"sequencing_center" ]
235+ optional_experimental_fields = TSV_FIELDS ['experiment' ]["conditional" ]
236+ optional_experimental_fields .remove ("rin" )
237+
229238 for optional_experimental_field in optional_experimental_fields :
230239 if metadata .get (optional_experimental_field ):
231240 payload ['experiment' ][optional_experimental_field ]= metadata .get (optional_experimental_field )
@@ -259,12 +268,6 @@ def main(metadata, extra_info=dict()):
259268 payload ['samples' ].append (sample )
260269
261270 # get file of the payload
262-
263- optional_file_fields = [
264- "ega_file_id" ,"ega_dataset_id" ,"ega_experiment_id" ,"ega_sample_id" ,"ega_study_id" ,
265- "ega_run_id" ,"ega_policy_id" ,"ega_analysis_id" ,"ega_submission_id" ,"ega_dac_id"
266- ]
267-
268271 for input_file in metadata .get ("files" ):
269272 payload ['files' ].append (
270273 {
@@ -279,9 +282,12 @@ def main(metadata, extra_info=dict()):
279282 }
280283 }
281284 )
282- for optional_file_field in optional_file_fields :
285+ for optional_file_field in TSV_FIELDS [ 'file' ][ "conditional" ] :
283286 if input_file .get (optional_file_field ):
284- payload ['files' ][- 1 ][optional_file_field ]= input_file .get (optional_file_field )
287+ if re .findall ("^" + EGA_FIELDS [optional_file_field ]+ '[0-9]{1,32}$' ,input_file .get (optional_file_field )):
288+ payload ['files' ][- 1 ]['info' ][optional_file_field ]= input_file .get (optional_file_field )
289+ else :
290+ sys .exit (f"Field '%s' in file '%s' with value '%s' does not match expected regex pattern '^%s[0-9]{ 1 ,32 } $'" % (optional_file_field ,input_file .get ('name' ),input_file .get (optional_file_field ),EGA_FIELDS [optional_file_field ]))
285291
286292 for rg in metadata .get ("read_groups" ):
287293 rg .pop ('type' ) # remove 'type' field
0 commit comments