-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1217 from virtualcell/PublicationFixes
Fix remaining issues preventing / hindering publishing VCell models on BSTS
- Loading branch information
Showing
10 changed files
with
176 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import os | ||
from pathlib import Path | ||
from typing import Optional | ||
from download_vcell_omex import ExportStatus | ||
|
||
import requests | ||
from pydantic import BaseModel | ||
|
||
from vcutils.common.api_utils import download_file | ||
from vcutils.vcell_pipeline.citation import getCitation, CitationInfo, getSuggestedProjectName | ||
from vcutils.vcell_pipeline.datamodels import Publication | ||
|
||
VERIFY_SSL = False | ||
|
||
|
||
def rename_published_omex(api_base_url: str, subject_dir: Path) -> None: | ||
response = requests.get(f"{api_base_url}/publication", headers={'Accept': 'application/json'}, verify=VERIFY_SSL) | ||
publication_json = response.json() | ||
id_to_name_mapping: dict[str, str] = {} | ||
files_to_check = os.listdir(subject_dir) | ||
starting_count = len(files_to_check) | ||
changes_count = 0 | ||
|
||
for pub in [Publication(**jsonDict) for jsonDict in publication_json]: | ||
if len(pub.biomodelReferences) == 0: | ||
continue | ||
print(f"Processing {pub.pubKey}, title: {pub.title}, year: {pub.year}, bimodels: {pub.biomodelReferences}") | ||
bmKey = pub.biomodelReferences[0].bmKey | ||
pubmedId: Optional[str] = pub.pubmedid | ||
citationInfo: Optional[CitationInfo] = None | ||
try: | ||
citationInfo = getCitation(pubmedId) | ||
except Exception as e: | ||
print(f"Error getting citation for {pubmedId}: {e}") | ||
|
||
for bioModelKey in [bmr.bmKey for bmr in pub.biomodelReferences]: | ||
suggested_project_name = getSuggestedProjectName(bm_key=bmKey, pub_info=pub, citation_info=citationInfo) | ||
id_to_name_mapping[bioModelKey] = suggested_project_name | ||
|
||
for file in files_to_check: | ||
file_key = file[9:-5] | ||
if not file_key.isdigit(): | ||
continue | ||
if file_key in id_to_name_mapping: | ||
changes_count += 1 | ||
os.rename(os.path.join(subject_dir, file), os.path.join(subject_dir, id_to_name_mapping[file_key])) | ||
else: | ||
print(" > No corresponding file to rename with key: {}".format(file_key)) | ||
|
||
ending_count = len(os.listdir(subject_dir)) | ||
print(f"\t> Starting files: {starting_count}\n\t> Changes Made: {changes_count}\n\t> Finished files: {ending_count}") | ||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
rename_published_omex( | ||
api_base_url="https://vcellapi-beta.cam.uchc.edu:8080", | ||
subject_dir=Path("/home/ldrescher/Documents/convertedFiles") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
vcell-cli/src/main/java/org/vcell/cli/run/hdf5/HDF5ExecutionResults.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.vcell.cli.run.hdf5; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.jlibsedml.SedML; | ||
|
||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
|
||
public class HDF5ExecutionResults implements Iterable<SedML>{ | ||
private final static Logger logger = LogManager.getLogger(HDF5ExecutionResults.class); | ||
private final Map<SedML, Hdf5DataContainer> executionResultsMapping; | ||
public boolean isBioSimHdf5; | ||
|
||
public HDF5ExecutionResults(boolean isBioSimHdf5){ | ||
this.executionResultsMapping = new HashMap<>(); | ||
this.isBioSimHdf5 = isBioSimHdf5; | ||
} | ||
|
||
public void addResults(SedML sedml, Hdf5DataContainer dataContainer){ | ||
if (this.executionResultsMapping.containsKey(sedml)) logger.warn("Overwriting Results..."); | ||
this.executionResultsMapping.put(sedml, dataContainer); | ||
} | ||
|
||
public Hdf5DataContainer getData(SedML sedml){ | ||
if (!this.executionResultsMapping.containsKey(sedml)) throw new RuntimeException("No data for requested SED-ML!"); | ||
return this.executionResultsMapping.get(sedml); | ||
} | ||
|
||
@Override | ||
public Iterator<SedML> iterator() { | ||
return this.executionResultsMapping.keySet().iterator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.