def from_json(cls, json: JSON) -> 'ProjectPublication': title = lookup(json, 'title', 'publication_title') url = lookup(json, 'url', 'publication_url', default=None) return cls(title=title, url=url, official_hca=json.get('official_hca_publication'), doi=json.get('doi'))
def __init__(self, json: JSON): super().__init__(json) content = json.get('content', json) self.genus_species = {ontology_label(gs) for gs in content['genus_species']} self.diseases = {ontology_label(d) for d in lookup(content, 'diseases', 'disease', default=[]) if d} self.organism_age = content.get('organism_age') self.organism_age_unit = ontology_label(content.get('organism_age_unit'), default=None) self.sex = lookup(content, 'sex', 'biological_sex')
def __init__(self, json: JSON): super().__init__(json) content = json.get('content', json) preservation_storage = content.get('preservation_storage') self.storage_method = preservation_storage.get('storage_method') if preservation_storage else None self.preservation_method = preservation_storage.get('preservation_method') if preservation_storage else None self.diseases = {ontology_label(d) for d in lookup(content, 'diseases', 'disease', default=[]) if d} self.organ = ontology_label(content.get('organ'), default=None) organ_parts = lookup(content, 'organ_parts', 'organ_part', default=[]) if not isinstance(organ_parts, list): organ_parts = [organ_parts] self.organ_parts = {ontology_label(d) for d in organ_parts if d}
def __init__(self, json: JSON, metadata_manifest_entry: Optional[ManifestEntry]) -> None: super().__init__(json, metadata_manifest_entry) content = json.get('content', json) self.estimated_cell_count = lookup(content, 'estimated_cell_count', 'total_estimated_cells', default=None) self.selected_cell_types = { ontology_label(sct) for sct in lookup(content, 'selected_cell_types', 'selected_cell_type', default=[]) }
def __init__(self, json: JSON, metadata_manifest_entry: Optional[ManifestEntry]) -> None: super().__init__(json, metadata_manifest_entry) content = json.get('content', json) self.type = lookup(content, 'type', 'cell_line_type') self.model_organ = ontology_label(content.get('model_organ'), default=None)
def __init__(self, json: JSON, metadata_manifest_entry: Optional[ManifestEntry]) -> None: super().__init__(json, metadata_manifest_entry) content = json.get('content', json) core = content['project_core'] self.project_short_name = lookup(core, 'project_short_name', 'project_shortname') self.project_title = core['project_title'] self.project_description = core.get('project_description') self.publications = set( ProjectPublication.from_json(publication) for publication in content.get('publications', [])) self.contributors = { ProjectContact.from_json(contributor) for contributor in content.get('contributors', []) } self.supplementary_links = set(content.get('supplementary_links', [])) self.estimated_cell_count = content.get('estimated_cell_count') accessions = set() for name, value in content.items(): prefix, _, suffix = name.rpartition('_') if suffix == 'accessions': assert prefix, name assert isinstance(value, list) accessions.update( Accession(namespace=prefix, accession=v) for v in value) self.accessions = accessions
def from_json(cls, json: JSON) -> Iterable['Link']: if 'source_id' in json: # v5 yield cls(source_id=UUID4(json['source_id']), source_type=json['source_type'], destination_id=UUID4(json['destination_id']), destination_type=json['destination_type']) else: # vx process_id = UUID4(json['process']) for source_id in json['inputs']: yield cls(source_id=UUID4(source_id), source_type=json['input_type'], destination_id=process_id, destination_type='process') for destination_id in json['outputs']: yield cls(source_id=process_id, source_type='process', destination_id=UUID4(destination_id), destination_type=json['output_type']) for protocol in json['protocols']: yield cls(source_id=process_id, source_type='process', destination_id=UUID4(protocol['protocol_id']), destination_type=lookup(protocol, 'type', 'protocol_type'))
def __init__(self, json: JSON, metadata_manifest_entry: Optional[ManifestEntry]) -> None: super().__init__(json, metadata_manifest_entry) content = json.get('content', json) self.probe = [ ImagingProbe.from_json(probe) for probe in lookup(content, 'probe', 'target', default=[]) ]
def __init__(self, json: JSON): super().__init__(json) content = json.get('content', json) self.genus_species = {gs['text'] for gs in content['genus_species']} self.disease = {d['text'] for d in content.get('disease', []) if d} self.organism_age = content.get('organism_age') self.organism_age_unit = content.get('organism_age_unit', {}).get('text') self.sex = lookup(content, 'sex', 'biological_sex')
def __init__(self, json: JSON, metadata_manifest_entry: Optional[ManifestEntry]) -> None: super().__init__(json, metadata_manifest_entry) content = json.get('content', json) temp = lookup(content, 'library_construction_method', 'library_construction_approach') self.library_construction_method = ontology_label(temp) if isinstance( temp, dict) else temp self.nucleic_acid_source = content.get('nucleic_acid_source')
def __init__(self, json: JSON, metadata_manifest_entry: Optional[ManifestEntry]) -> None: super().__init__(json, metadata_manifest_entry) content = json.get('content', json) self.model_organ = ontology_label(lookup(content, 'model_organ', 'model_for_organ'), default=None) self.model_organ_part = ontology_label(content.get('model_organ_part'), default=None)
def __init__(self, json: JSON, metadata_manifest_entry: Optional[ManifestEntry]) -> None: super().__init__(json, metadata_manifest_entry) content = json.get('content', json) self.genus_species = { ontology_label(gs) for gs in content['genus_species'] } self.diseases = { ontology_label(d) for d in lookup(content, 'diseases', 'disease', default=[]) if d } self.organism_age = content.get('organism_age') self.organism_age_unit = ontology_label( content.get('organism_age_unit'), default=None) self.sex = lookup(content, 'sex', 'biological_sex') self.development_stage = ontology_label( content.get('development_stage'), default=None)
def __init__(self, json: JSON, manifest: Mapping[str, ManifestEntry]): super().__init__(json) content = json.get('content', json) core = content['file_core'] self.format = lookup(core, 'format', 'file_format') self.manifest_entry = manifest[core['file_name']] self.content_description = {ontology_label(cd) for cd in core.get('content_description', [])} self.from_processes = {} self.to_processes = {}
def from_json(cls, json: JSON) -> 'ProjectContact': project_role = json.get('project_role') project_role = ontology_label(project_role) if isinstance(project_role, dict) else project_role return cls(name=lookup(json, 'name', 'contact_name'), email=json.get('email'), institution=json.get('institution'), laboratory=json.get('laboratory'), corresponding_contributor=json.get('corresponding_contributor'), project_role=project_role)
def __init__(self, json: JSON, metadata_manifest_entry: Optional[ManifestEntry]) -> None: super().__init__(json, metadata_manifest_entry) content = json.get('content', json) self.instrument_manufacturer_model = ontology_label( content.get('instrument_manufacturer_model'), default=None) self.paired_end = lookup(content, 'paired_end', 'paired_ends', default=None)
def __init__(self, json: JSON) -> None: super().__init__(json) content = json.get('content', json) core = content['project_core'] self.project_short_name = lookup(core, 'project_short_name', 'project_shortname') self.laboratory_names = { c.get('laboratory') for c in content['contributors'] } - {None}
def __init__(self, json: JSON, metadata_manifest_entry: Optional[ManifestEntry]) -> None: super().__init__() self.json = json self.metadata_manifest_entry = metadata_manifest_entry provenance = json.get('hca_ingest') or json['provenance'] self.document_id = UUID4(provenance['document_id']) # Some older DCP/1 bundles use different UUIDs in the manifest and # metadata. # noinspection PyUnreachableCode if False and self.metadata_manifest_entry is not None: assert self.document_id == self.metadata_manifest_entry.uuid self.submitter_id = provenance.get('submitter_id') submission_date = lookup(provenance, 'submission_date', 'submissionDate') self.submission_date = self._datetime(submission_date) update_date = lookup(provenance, 'update_date', 'updateDate', default=None) self.update_date = self._optional_datetime(update_date)
def __init__(self, json: JSON) -> None: super().__init__(json) content = json.get('content', json) core = content['project_core'] self.project_short_name = lookup(core, 'project_short_name', 'project_shortname') self.project_title = core['project_title'] self.project_description = core.get('project_description') self.publications = set(ProjectPublication.from_json(publication) for publication in content.get('publications', [])) self.contributors = {ProjectContact.from_json(contributor) for contributor in content.get('contributors', [])} self.insdc_project_accessions = set(content.get('insdc_project_accessions', [])) self.geo_series_accessions = set(content.get('geo_series_accessions', [])) self.array_express_accessions = set(content.get('array_express_accessions', [])) self.insdc_study_accessions = set(content.get('insdc_study_accessions', [])) self.supplementary_links = set(content.get('supplementary_links', []))
def __init__(self, json: JSON, metadata_manifest_entry: Optional[ManifestEntry], manifest: Mapping[str, ManifestEntry]): super().__init__(json, metadata_manifest_entry) content = json.get('content', json) # '/' was once forbidden in file paths and was encoded with '!'. Now # '/' is allowed and we force it in the metadata so that backwards # compatibility is simplified downstream. core = content['file_core'] core['file_name'] = core['file_name'].replace('!', '/') self.format = lookup(core, 'format', 'file_format') self.manifest_entry = manifest[core['file_name']] self.content_description = { ontology_label(cd) for cd in core.get('content_description', []) } self.file_source = core.get('file_source') self.from_processes = {} self.to_processes = {}
def ontology_label( ontology: Optional[Mapping[str, str]], default: Union[str, None, LookupDefault] = LookupDefault.RAISE) -> str: """ Return the best-suited value from the given ontology dictionary. >>> ontology_label({'ontology_label': '1', 'text': '2', 'ontology': '3'}) '1' >>> ontology_label({'text': '2', 'ontology': '3'}) '2' >>> ontology_label({'ontology': '3'}) '3' >>> ontology_label({}, default=None) >>> ontology_label({}, default='default') 'default' >>> ontology_label(None, default=None) >>> ontology_label(None, default='default') 'default' >>> ontology_label({}) Traceback (most recent call last): ... KeyError: 'ontology_label' >>> ontology_label(None) Traceback (most recent call last): ... TypeError: 'NoneType' object is not subscriptable """ if ontology is None and default is not LookupDefault.RAISE: return default else: return lookup(ontology, 'ontology_label', 'text', 'ontology', default=default)
def __init__(self, json: JSON): super().__init__(json) content = json.get('content', json) self.instrument_manufacturer_model = ontology_label(content.get('instrument_manufacturer_model'), default=None) self.paired_end = lookup(content, 'paired_end', 'paired_ends', default=None)
def __init__(self, json: JSON) -> None: super().__init__(json) content = json.get('content', json) temp = lookup(content, 'library_construction_method', 'library_construction_approach') self.library_construction_method = ontology_label(temp) if isinstance(temp, dict) else temp
def __init__(self, json: JSON) -> None: super().__init__(json) content = json.get('content', json) self.model_organ = ontology_label(lookup(content, 'model_organ', 'model_for_organ'), default=None) self.model_organ_part = ontology_label(content.get('model_organ_part'), default=None)
def __init__(self, json: JSON) -> None: super().__init__(json) content = json.get('content', json) self.type = lookup(content, 'type', 'cell_line_type') self.model_organ = ontology_label(content.get('model_organ'), default=None)
def __init__(self, json: JSON) -> None: super().__init__(json) content = json.get('content', json) self.estimated_cell_count = lookup(content, 'estimated_cell_count', 'total_estimated_cells', default=None) self.selected_cell_types = {ontology_label(sct) for sct in lookup(content, 'selected_cell_types', 'selected_cell_type', default=[])}
def from_json(cls, json: JSON, schema_version: Tuple[int]) -> Iterable['Link']: if 'source_id' in json: # DCP/1 v5 (obsolete) yield cls(source_id=UUID4(json['source_id']), source_type=json['source_type'], destination_id=UUID4(json['destination_id']), destination_type=json['destination_type']) elif schema_version[0] == 1: # DCP/1 vx (current) process_id = UUID4(json['process']) for source_id in json['inputs']: yield cls(source_id=UUID4(source_id), source_type=json['input_type'], destination_id=process_id, destination_type='process') for destination_id in json['outputs']: yield cls(source_id=process_id, source_type='process', destination_id=UUID4(destination_id), destination_type=json['output_type']) for protocol in json['protocols']: yield cls(source_id=process_id, source_type='process', destination_id=UUID4(protocol['protocol_id']), destination_type=lookup(protocol, 'type', 'protocol_type')) elif schema_version[0] in (2, 3): # DCP/2 (current) link_type = json['link_type'] if link_type == 'process_link': process_id = UUID4(json['process_id']) process_type = json['process_type'] for input_ in json['inputs']: yield cls(link_type=link_type, source_id=UUID4(input_['input_id']), source_type=input_['input_type'], destination_id=process_id, destination_type=process_type) for output in json['outputs']: yield cls(link_type=link_type, source_id=process_id, source_type=process_type, destination_id=UUID4(output['output_id']), destination_type=output['output_type']) for protocol in json['protocols']: yield cls(link_type=link_type, source_id=process_id, source_type=process_type, destination_id=UUID4(protocol['protocol_id']), destination_type=protocol['protocol_type']) elif link_type == 'supplementary_file_link': entity = json['entity'] for supp_file in json['files']: yield cls(link_type=link_type, source_id=UUID4(entity['entity_id']), source_type=entity['entity_type'], destination_id=UUID4(supp_file['file_id']), destination_type=supp_file['file_type']) else: assert False, f'Unknown link_type {link_type}' else: assert False, f'Unknown schema_version {schema_version}'
def from_json(cls, json: JSON) -> 'ProjectPublication': title = lookup(json, 'title', 'publication_title') url = lookup(json, 'url', 'publication_url', default=None) return cls(title=title, url=url)