Skip to content

Commit

Permalink
Change ingest code to include new DOI Class
Browse files Browse the repository at this point in the history
  • Loading branch information
marySalvi committed Nov 29, 2023
1 parent 070a874 commit e249491
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 42 deletions.
2 changes: 1 addition & 1 deletion nmdc_server/ingest/doi.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def upsert_doi(db: Session, doi: str, doi_type: DOIType):
return
info = {}

statement = insert(DOIInfo.__table__).values(id=doi, info=info, doi_type=doi_type)
statement = insert(DOIInfo.__table__).values(id=doi, info=info, doi_type=DOIType(doi_type))
statement = statement.on_conflict_do_update(constraint="pk_doi_info", set_=dict(info=info))
db.execute(statement)
db.flush()
31 changes: 11 additions & 20 deletions nmdc_server/ingest/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,18 @@ def load(db: Session, cursor: Cursor):
obj["principal_investigator_id"] = get_or_create_pi(db, pi_name, pi_url, pi_orcid)
obj["principal_investigator_websites"] = obj.pop("websites", [])
obj["image"] = get_study_image_data(obj.pop("study_image", []))
dois=obj.pop("associated_dois", None)
if dois:
for doi in dois:
doi["doi_value"] = transform_doi(doi.pop("doi_value"))

publication_dois = [transform_doi(d) for d in obj.pop("publications", [])] + [
transform_doi(d) for d in obj.pop("publication_dois", [])
]
award_dois = [transform_doi(doi) for doi in obj.pop("award_dois", [])] + [
transform_doi(d) for d in obj.pop("emsl_project_dois", [])
]
dataset_dois = [transform_doi(doi) for doi in obj.pop("dataset_dois", [])]
for doi in dois:
upsert_doi(db, doi["doi_value"], doi["doi_category"])

for doi in publication_dois:
upsert_doi(db, doi, DOIType.PUBLICATION)

for doi in award_dois:
upsert_doi(db, doi, DOIType.AWARD)

for doi in dataset_dois:
upsert_doi(db, doi, DOIType.DATASET)

new_study = create_study(db, Study(**obj))

for doi_id in publication_dois + award_dois + dataset_dois:
doi_object = get_doi(db, doi_id)
if doi_object:
new_study.dois.append(doi_object) # type: ignore
if dois:
for doi in dois:
doi_object = get_doi(db, doi["doi_value"])
if doi_object:
new_study.dois.append(doi_object) # type: ignore
18 changes: 3 additions & 15 deletions nmdc_server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ class PrincipalInvestigator(Base):


class DOIType(enum.Enum):
AWARD = "award"
DATASET = "dataset"
PUBLICATION = "publication"
AWARD = 'award_doi'
DATASET = 'dataset_doi'
PUBLICATION = 'publication_doi'


study_doi_association = Table(
Expand Down Expand Up @@ -273,18 +273,6 @@ def open_in_gold(self) -> Optional[str]:
self.gold_study_identifiers, # type: ignore
)

@property
def award_dois(self) -> list[DOIInfo]:
return [d for d in self.dois if d.doi_type == DOIType.AWARD] # type: ignore

@property
def publication_dois(self) -> list[DOIInfo]:
return [d for d in self.dois if d.doi_type == DOIType.PUBLICATION] # type: ignore

@property
def dataset_dois(self) -> list[DOIInfo]:
return [d for d in self.dois if d.doi_type == DOIType.DATASET] # type: ignore

@property
def doi_map(self) -> Dict[str, Any]:
doi_info = {}
Expand Down
8 changes: 2 additions & 6 deletions nmdc_server/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ class CreditAssociation(BaseModel):
class DOIInfo(BaseModel):
id: str
info: dict
doi_type: models.DOIType
doi_category: models.DOIType
doi_provider:str

class Config:
orm_mode = True
Expand All @@ -232,8 +233,6 @@ class StudyBase(AnnotatedBase):
has_credit_associations: Optional[List[CreditAssociation]]
relevant_protocols: Optional[List[str]]
funding_sources: Optional[List[str]]
ess_dive_datasets: Optional[List[str]]
massive_study_identifiers: Optional[List[str]]
gold_study_identifiers: Optional[List[str]]

@validator("principal_investigator_websites", pre=True, each_item=True)
Expand Down Expand Up @@ -269,9 +268,6 @@ class Study(StudyBase):
doi_map: Dict[str, Any] = {}
multiomics: int

award_dois: Optional[List[DOIInfo]]
publication_dois: Optional[List[DOIInfo]]
dataset_dois: Optional[List[DOIInfo]]

class Config:
orm_mode = True
Expand Down

0 comments on commit e249491

Please sign in to comment.