Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Commit

Permalink
Release beta 32
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes-ucsc committed Sep 2, 2021
2 parents c6db04c + 4bae169 commit ada7017
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 11 deletions.
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.0b31",
version="1.0b32",
license='MIT',
install_requires=[
"dataclasses >= 0.6;python_version<'3.7'"
Expand Down
48 changes: 44 additions & 4 deletions src/humancellatlas/data/metadata/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,18 +280,26 @@ def contact_name(self) -> str:
return self.name


@dataclass(eq=True, frozen=True)
class Accession:
domain: str
value: str


@dataclass(init=False)
class Project(Entity):
project_short_name: str
project_title: str
project_description: Optional[str] # optional up to core/project/5.2.2/project_core
publications: Set[ProjectPublication]
contributors: Set[ProjectContact]
accessions: Set[Accession]
insdc_project_accessions: Set[str]
geo_series_accessions: Set[str]
array_express_accessions: Set[str]
insdc_study_accessions: Set[str]
supplementary_links: Set[str]
estimated_cell_count: Optional[int]

def __init__(self,
json: JSON,
Expand All @@ -306,11 +314,43 @@ def __init__(self,
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', []))
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(domain=prefix, value=v) for v in value)
self.accessions = accessions

def _accessions(self, domain: str) -> Set[str]:
return {a.value for a in self.accessions if a.domain == domain}

@property
def insdc_project_accessions(self) -> Set[str]:
warnings.warn("Project.insdc_project_accessions is deprecated. "
"Use Project.accessions instead.", DeprecationWarning)
return self._accessions('insdc_project')

@property
def geo_series_accessions(self) -> Set[str]:
warnings.warn("Project.geo_series_accessions is deprecated. "
"Use Project.accessions instead.", DeprecationWarning)
return self._accessions('geo_series')

@property
def array_express_accessions(self) -> Set[str]:
warnings.warn("Project.array_express_accessions is deprecated. "
"Use Project.accessions instead.", DeprecationWarning)
return self._accessions('array_express')

@property
def insdc_study_accessions(self) -> Set[str]:
warnings.warn("Project.insdc_study_accessions is deprecated. "
"Use Project.accessions instead.", DeprecationWarning)
return self._accessions('insdc_study')

@property
def laboratory_names(self) -> set:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@
}
],
"insdc_project_accessions": [
"SRP000000"
"SRP000000",
"SRP000001"
],
"geo_series_accessions": [
"GSE00000"
Expand Down
21 changes: 16 additions & 5 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from more_itertools import one

from humancellatlas.data.metadata.api import (
Accession,
AgeRange,
AnalysisFile,
AnalysisProtocol,
Expand Down Expand Up @@ -313,10 +314,17 @@ def test_accessions_fields(self):
project_roles={'principal investigator'},
age_range=AgeRange(630720000.0, 630720000.0),
library_construction_methods={'10X v2 sequencing'},
insdc_project_accessions={'SRP000000'},
insdc_project_accessions={'SRP000000', 'SRP000001'},
geo_series_accessions={'GSE00000'},
array_express_accessions={'E-AAAA-00'},
insdc_study_accessions={'PRJNA000000'})
insdc_study_accessions={'PRJNA000000'},
accessions={
Accession('insdc_project', 'SRP000000'),
Accession('insdc_project', 'SRP000001'),
Accession('geo_series', 'GSE00000'),
Accession('array_express', 'E-AAAA-00'),
Accession('insdc_study', 'PRJNA000000')
})

def test_imaging_bundle(self):
self._test_bundle(uuid='94f2ba52-30c8-4de0-a78e-f95a3f8deb9c',
Expand Down Expand Up @@ -396,6 +404,7 @@ def _assert_bundle(self, uuid, version, manifest, metadata_files,
preservation_methods=frozenset({None}),
library_construction_methods=frozenset(),
selected_cell_types=frozenset(),
accessions=frozenset(),
insdc_project_accessions=frozenset(),
geo_series_accessions=frozenset(),
array_express_accessions=frozenset(),
Expand Down Expand Up @@ -450,6 +459,7 @@ def _assert_bundle(self, uuid, version, manifest, metadata_files,
self.assertEqual(geo_series_accessions, project.geo_series_accessions)
self.assertEqual(array_express_accessions, project.array_express_accessions)
self.assertEqual(insdc_study_accessions, project.insdc_study_accessions)
self.assertEqual(accessions, project.accessions)

root_entities = bundle.root_entities().values()
root_entity_types = {type(e) for e in root_entities}
Expand Down Expand Up @@ -520,7 +530,7 @@ def _assert_bundle(self, uuid, version, manifest, metadata_files,
return bundle

def test_canned_staging_area(self):
ref = 'de355cad77ea7988040b6f1f5f2eafae58f686a8'
ref = '55628953e4b3a24a7d7798569b6082032bd07a6b'
url = f'https://github.com/HumanCellAtlas/schema-test-data/tree/{ref}/tests'
factory = GitHubStagingAreaFactory.from_url(url)
staging_area = factory.load_staging_area()
Expand All @@ -529,8 +539,9 @@ def test_canned_staging_area(self):
with self.subTest(link_id=link_id):
version, manifest, metadata_files = staging_area.get_bundle(link_id)
bundle = Bundle(link_id, version, manifest, metadata_files)
bundle_json = as_json(bundle)
self.assertEqual(link_id, bundle_json['uuid'])
self.assertEqual(bundle.uuid, UUID(link_id))
project = bundle.projects[UUID('90bf705c-d891-5ce2-aa54-094488b445c6')]
self.assertEqual(project.estimated_cell_count, 10000)

def test_analysis_protocol(self):
uuid = 'ffee7f29-5c38-461a-8771-a68e20ec4a2e'
Expand Down

0 comments on commit ada7017

Please sign in to comment.