Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

Commit

Permalink
Release beta 15
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes-ucsc committed May 2, 2019
2 parents 09d0993 + e366e9e commit 3db22b5
Show file tree
Hide file tree
Showing 9 changed files with 3,857 additions and 45 deletions.
2 changes: 2 additions & 0 deletions security.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
If you'd like to report a security issue please contact us
Contact: security-leads@data.humancellatlas.org
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="hca-metadata-api",
version="1.0b14",
version="1.0b15",
license='MIT',
install_requires=[
'dataclasses >= 0.6'
Expand Down
83 changes: 65 additions & 18 deletions src/humancellatlas/data/metadata/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,31 @@ def __init__(self, entity: LinkedEntity, other_entity: Entity, forward: bool) ->

@dataclass(frozen=True)
class ProjectPublication:
publication_title: str
publication_url: Optional[str]
title: str
url: Optional[str]

@classmethod
def from_json(cls, json: JSON) -> 'ProjectPublication':
return cls(publication_title=json['publication_title'],
publication_url=json.get('publication_url'))
title = lookup(json, 'title', 'publication_title')
url = lookup(json, 'url', 'publication_url', default=None)
return cls(title=title, url=url)

@property
def publication_title(self):
warnings.warn(f"ProjectPublication.publication_title is deprecated. "
f"Use ProjectPublication.title instead.", DeprecationWarning)
return self.title

@property
def publication_url(self):
warnings.warn(f"ProjectPublication.publication_url is deprecated. "
f"Use ProjectPublication.url instead.", DeprecationWarning)
return self.url


@dataclass(frozen=True)
class ProjectContact:
contact_name: str
name: str
email: Optional[str]
institution: Optional[str] # optional up to project/5.3.0/contact
laboratory: Optional[str]
Expand All @@ -132,12 +145,20 @@ class ProjectContact:

@classmethod
def from_json(cls, json: JSON) -> 'ProjectContact':
return cls(contact_name=json['contact_name'],
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=json.get('project_role'))
project_role=project_role)

@property
def contact_name(self) -> str:
warnings.warn(f"ProjectContact.contact_name is deprecated. "
f"Use ProjectContact.name instead.", DeprecationWarning)
return self.name


@dataclass(init=False)
Expand Down Expand Up @@ -290,24 +311,38 @@ def __init__(self, json: JSON) -> None:
@dataclass(init=False)
class CellSuspension(Biomaterial):
estimated_cell_count: Optional[int]
selected_cell_type: Set[str]
selected_cell_types: Set[str]

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_type = {ontology_label(sct) for sct in content.get('selected_cell_type', [])}
self.selected_cell_types = {ontology_label(sct) for sct in
lookup(content, 'selected_cell_types', 'selected_cell_type', default=[])}

@property
def total_estimated_cells(self) -> int:
warnings.warn(f"CellSuspension.total_estimated_cells is deprecated. "
f"Use CellSuspension.estimated_cell_count instead.", DeprecationWarning)
return self.estimated_cell_count

@property
def selected_cell_type(self) -> Set[str]:
warnings.warn(f"CellSuspension.selected_cell_type is deprecated. "
f"Use CellSuspension.selected_cell_types instead.", DeprecationWarning)
return self.selected_cell_types


@dataclass(init=False)
class CellLine(Biomaterial):
pass
cell_line_type: str
model_organ: Optional[str]

def __init__(self, json: JSON) -> None:
super().__init__(json)
content = json.get('content', json)
self.cell_line_type = content['cell_line_type']
self.model_organ = ontology_label(content.get('model_organ'), default=None)


@dataclass(init=False)
Expand Down Expand Up @@ -527,7 +562,7 @@ def from_json(cls, json: JSON):

@dataclass(init=False)
class File(LinkedEntity):
file_format: str
format: str
from_processes: MutableMapping[UUID4, Process] = field(repr=False)
to_processes: MutableMapping[UUID4, Process]
manifest_entry: ManifestEntry
Expand All @@ -536,7 +571,7 @@ def __init__(self, json: JSON, manifest: Mapping[str, ManifestEntry]):
super().__init__(json)
content = json.get('content', json)
core = content['file_core']
self.file_format = core['file_format']
self.format = lookup(core, 'format', 'file_format')
self.manifest_entry = manifest[core['file_name']]
self.from_processes = {}
self.to_processes = {}
Expand All @@ -550,6 +585,12 @@ def _connect_to(self, other: Entity, forward: bool) -> None:
else:
raise LinkError(self, other, forward)

@property
def file_format(self) -> str:
warnings.warn(f"File.file_format is deprecated. "
f"Use File.format instead.", DeprecationWarning)
return self.format


@dataclass(init=False)
class SequenceFile(File):
Expand Down Expand Up @@ -602,14 +643,20 @@ def from_json(cls, json: JSON) -> Iterable['Link']:
# 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')
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'])
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=protocol['protocol_type'])
yield cls(source_id=process_id,
source_type='process',
destination_id=UUID4(protocol['protocol_id']),
destination_type=lookup(protocol, 'type', 'protocol_type'))


@dataclass(init=False)
Expand Down
15 changes: 10 additions & 5 deletions src/humancellatlas/data/metadata/helpers/dss.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ def download_file(item):
file_version = manifest_entry['version']
logger.debug("Getting file '%s' (%s.%s) from DSS.", file_name, file_uuid, file_version)
# noinspection PyUnresolvedReferences
file_contents = client.get_file(uuid=file_uuid, version=file_version, replica='aws')
file_contents = client.get_file(uuid=file_uuid, version=file_version, replica=replica)

# Work around https://github.com/HumanCellAtlas/data-store/issues/2073
if replica == 'gcp' and isinstance(file_contents, bytes): # pragma: no cover
import json
file_contents = json.loads(file_contents)

if not isinstance(file_contents, dict):
raise TypeError(f'Expecting file {file_uuid}.{file_version} '
f'to contain a JSON object ({dict}), '
Expand All @@ -92,14 +98,13 @@ def download_file(item):
return bundle['version'], manifest, dict(metadata_files)


def dss_client(deployment: Optional[str] = None) -> DSSClient:
def dss_client(deployment: str = 'prod') -> DSSClient:
"""
Return a DSS client to DSS production or the specified DSS deployment.
:param deployment: The name of a DSS deployment like `dev`, `integration` or `staging`. If None, the production
deployment (`prod`) will be used.
:param deployment: The name of a DSS deployment like `dev`, `integration`, `staging` or `prod`.
"""
deployment = deployment + "." if deployment else ""
deployment = "" if deployment == "prod" else deployment + "."
swagger_url = f'https://dss.{deployment}data.humancellatlas.org/v1/swagger.json'
client = DSSClient(swagger_url=swagger_url)
client.timeout_policy = Timeout(connect=10, read=40)
Expand Down
Loading

0 comments on commit 3db22b5

Please sign in to comment.