def _export_compound_set(self, ref, file_type): logging.info("Exporting {} as {}".format(ref, file_type)) compoundset = self.dfu.get_objects({'object_refs': [ref]})['data'][0]['data'] temp_dir = "{}/{}".format(self.scratch, uuid.uuid4()) os.mkdir(temp_dir) out_dir = "{}/{}".format(temp_dir, compoundset['name']) os.mkdir(out_dir) target = "{}/{}.{}".format(out_dir, compoundset['name'], file_type) if file_type == 'tsv': parse.write_tsv(compoundset, target) elif file_type == 'sdf': parse.write_sdf(compoundset, target) else: raise ValueError("Bad file_type: {}".format(file_type)) handle = self.dfu.package_for_download({ 'file_path': out_dir, 'ws_refs': [ref] }) output = {'shock_id': handle['shock_id']} return output
def compound_set_to_file(self, ctx, params): """ CompoundSetToFile string compound_set_name string output_format :param params: instance of type "compoundset_download_params" -> structure: parameter "compound_set_ref" of String, parameter "output_format" of String :returns: instance of type "compoundset_download_results" -> structure: parameter "file_path" of String, parameter "packed_mol2_files_path" of String, parameter "comp_id_mol2_file_name_map" of mapping from String to String """ # ctx is the context object # return variables are: output #BEGIN compound_set_to_file self._check_param(params, ['compound_set_ref', 'output_format']) ret = self.dfu.get_objects( {'object_refs': [params['compound_set_ref']]})['data'][0] compoundset = ret['data'] ext = params['output_format'] out = f"{self.scratch}/{uuid.uuid4()}" os.mkdir(out) out += f"/{compoundset['name']}" if ext == 'sdf': outfile_path = parse.write_sdf(compoundset, out) elif ext == 'tsv': outfile_path = parse.write_tsv(compoundset, out) else: outfile_path = parse.write_mol_dir(compoundset, out, ext) packed_mol2_files_path, comp_id_mol2_file_name_map = self._fetch_mol2_files( params['compound_set_ref']) output = { 'file_path': outfile_path, 'packed_mol2_files_path': packed_mol2_files_path, 'comp_id_mol2_file_name_map': comp_id_mol2_file_name_map } #END compound_set_to_file # At some point might do deeper type checking... if not isinstance(output, dict): raise ValueError('Method compound_set_to_file return value ' + 'output is not type dict as required.') # return the results return [output]