@@ -159,7 +159,7 @@ def validate_args(args):
159159 ))
160160
161161
162- def main (metadata ):
162+ def main (metadata , extra_info = dict () ):
163163 empty_str_to_null (metadata )
164164
165165 payload = {
@@ -198,6 +198,24 @@ def main(metadata):
198198 }
199199 }
200200
201+ if extra_info :
202+ if extra_info ['sample' ].get (sample ['submitterSampleId' ]):
203+ sample ['sampleId' ] = extra_info ['sample' ][sample ['submitterSampleId' ]]
204+ else :
205+ sys .exit (f"Provided extra_info_tsv misses mapping for submitter sample ID: { sample ['submitterSampleId' ]} " )
206+
207+ if extra_info ['specimen' ].get (sample ['specimen' ]['submitterSpecimenId' ]):
208+ sample ['specimenId' ] = extra_info ['specimen' ][sample ['specimen' ]['submitterSpecimenId' ]]
209+ sample ['specimen' ]['specimenId' ] = sample ["specimenId" ]
210+ else :
211+ sys .exit (f"Provided extra_info_tsv misses mapping for submitter specimen ID: { sample ['specimen' ]['submitterSpecimenId' ]} " )
212+
213+ if extra_info ['donor' ].get (sample ['donor' ]['submitterDonorId' ]):
214+ sample ['donor' ]['donorId' ] = extra_info ['donor' ][sample ['donor' ]['submitterDonorId' ]]
215+ sample ['specimen' ]['donorId' ] = sample ['donor' ]['donorId' ]
216+ else :
217+ sys .exit (f"Provided extra_info_tsv misses mapping for submitter donor ID: { sample ['donor' ]['submitterDonorId' ]} " )
218+
201219 payload ['samples' ].append (sample )
202220
203221 # get file of the payload
@@ -235,6 +253,8 @@ def main(metadata):
235253 help = "tsv file containing read_group information submitted from user" )
236254 parser .add_argument ("-f" , "--file-info-tsv" ,
237255 help = "tsv file containing file information submitted from user" )
256+ parser .add_argument ("-e" , "--extra-info-tsv" ,
257+ help = "tsv file containing file information submitted from user" )
238258 args = parser .parse_args ()
239259
240260 validate_args (args )
@@ -258,4 +278,24 @@ def main(metadata):
258278 # all TSV are well-formed, let's load them
259279 metadata = load_all_tsvs (args .experiment_info_tsv , args .read_group_info_tsv , args .file_info_tsv )
260280
261- main (metadata )
281+ extra_info = dict ()
282+ if args .extra_info_tsv :
283+ with open (args .extra_info_tsv , 'r' ) as f :
284+ for row in csv .DictReader (f , delimiter = '\t ' ):
285+ type = row ['type' ]
286+ submitter_id = row ['submitter_id' ]
287+ uniform_id = row ['uniform_id' ]
288+ if type in extra_info :
289+ sys .exit (f"Values in 'type' field duplicated. Offending value: { type } , in file: { args .extra_info_tsv } " )
290+ else :
291+ extra_info [type ] = dict ()
292+
293+ if submitter_id in extra_info [type ]:
294+ sys .exit (f"Values in 'submitter_id' field duplicated. Offending value: { submitter_id } , for type: { type } , in file: { args .extra_info_tsv } " )
295+ else :
296+ extra_info [type ][submitter_id ] = uniform_id
297+
298+ if 'donor' not in extra_info or 'specimen' not in extra_info or 'sample' not in extra_info :
299+ sys .exit (f"Provided extra_info_tsv file '{ args .extra_info_tsv } ' is required to have ID mappings for 'donor', 'specimen' and 'sample'" )
300+
301+ main (metadata , extra_info )
0 commit comments