def format_autit_collection(self, audit_collection): organization = map( self.format_organization, ensure_iterable(audit_collection.pop("Organization", None))) person = map(self.format_person, ensure_iterable(audit_collection.pop("Person", None))) return self.writer.AuditCollection(person, organization)
def copy_inputs(self): self.log("Copying Inputs") self.reader.reset() inputs = next(self.reader.iterfind('Inputs')) source_files = map(self.format_source_file, ensure_iterable(inputs.get("SourceFile"))) search_databases = map(self.format_search_database, ensure_iterable(inputs.get("SearchDatabase"))) spectra_data = map(self.format_spectra_data, ensure_iterable(inputs.get("SpectraData"))) self.writer.inputs(source_files, search_databases, spectra_data)
def copy_analysis_protocol_collection(self): self.log("Copying Protocols") self.reader.reset() apc = next( self.reader.iterfind("AnalysisProtocolCollection", retrieve_refs=False)) protocols = [] for sip in ensure_iterable( apc.get("SpectrumIdentificationProtocol", [])): protocols.append(self.format_spectrum_identification_protocol(sip)) for pdp in ensure_iterable(apc.get("ProteinDetectionProtocol", [])): protocols.append(self.format_protein_detection_protocol(pdp)) with self.writer.analysis_protocol_collection(): for protocol in protocols: protocol.write(self.writer)
def format_provider(self, provider): d = {} d.update(provider) contact_role = ensure_iterable(d.pop("ContactRole", {}))[0] d['role'] = contact_role.get("Role") d['contact'] = contact_role.get('contact_ref') return self.writer.Provider.ensure(d)
def format_analysis_software(self, software): d = {} d.update(software) d['name'] = d.pop('SoftwareName') contact_role = ensure_iterable(d.pop("ContactRole", {}))[0] d['role'] = contact_role.get("Role") d['contact'] = contact_role.get('contact_ref') return self.writer.AnalysisSoftware.ensure(d)
def format_referenceable_param_groups(self): self.reader.reset() try: param_list = next(self.reader.iterfind("referenceableParamGroupList", recursive=True, retrive_refs=False)) param_groups = ensure_iterable(param_list.get("referenceableParamGroup", [])) except StopIteration: param_groups = [] return [self.writer.ReferenceableParamGroup.ensure(d) for d in param_groups]
def format_person(self, person): d = {} d.update(person) self._translate_keys(d, ['firstName', 'lastName', 'midInitials']) d['affiliations'] = [ a.get('organization_ref') for a in ensure_iterable(d.pop("Affiliation", {})) if a.get('organization_ref') is not None ] return self.writer.Person.ensure(d)
def format_spectrum_identification_protocol(self, sip): d = dict(sip) d['additional_search_params'] = d.pop("AdditionalSearchParams", []) enzymes = d.pop("Enzymes", {}) d['enzymes'] = self.writer.Enzymes( map(self.format_enzyme, ensure_iterable(enzymes.get("Enzyme", []))), independent=enzymes.get("independent")) d['modification_params'] = map( self.format_search_modification, ensure_iterable( d.pop('ModificationParams', {}).get("SearchModification", []))) d['search_type'] = d.pop("SearchType", None) d['parent_tolerance'] = self.format_tolerance( d.pop("ParentTolerance", {}), self.writer.ParentTolerance) d['fragment_tolerance'] = self.format_tolerance( d.pop("FragmentTolerance", {}), self.writer.FragmentTolerance) d['threshold'] = self._extract_params(d.pop("Threshold")) d['analysis_software_id'] = d.pop("analysisSoftware_ref") return self.writer.SpectrumIdentificationProtocol.ensure(d)
def copy_analysis_collection(self): reader = self.reader writer = self.writer reader.reset() analysis_collection = next(reader.iterfind("AnalysisCollection")) with self.writer.analysis_collection(): for si in analysis_collection.get("SpectrumIdentification", []): self.format_spectrum_identification(si).write(writer) for pi in ensure_iterable( analysis_collection.get("ProteinDetection", [])): self.format_protein_detection(pi).write(writer)
def is_of_type(self, tp): try: tp = self.vocabulary[tp] except KeyError: return False stack = deque([self]) while stack: ref = stack.pop() if ref == tp: return True stack.extend(ensure_iterable(ref.parent())) return False
def _expand_property_value(self, entity): if "property_value" in entity.data: for prop_val in ensure_iterable(entity.data['property_value']): prop, val = prop_val.split(" ", 1) prop = prop.strip(": ") val = val.strip() if val.startswith("\""): val, dtype = val.rsplit(" ", 1) dtype = parse_xsdtype(dtype) try: val = dtype(val[1:-1]) except (ValueError, TypeError): pass entity[prop] = val
def write_term(self, term): self.stream.write("[Term]\nid: %s\nname: %s\ndef: \"%s\"\n" % (term.id, term.name, term.definition)) for xref in term.get('xref', []): self.stream.write("xref: ") for is_a in ensure_iterable(term.get("is_a", [])): self.stream.write("is_a: %s" % str(is_a)) seen = set() for syn in term.get('synonyms', []): if syn in seen: continue seen.add(syn) self.stream.write("synonym: \"%s\" EXACT\n" % str(syn).replace("\n", "\\n")) for prop in term.get('property_value', []): self.stream.write("property_value: %s\n" % prop) self.stream.write("\n")