-
Notifications
You must be signed in to change notification settings - Fork 3
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 #14 from YeChen-IDM/analyzer_pipeline
Add analyzers to snakemake pipeline, download work item and suite features
- Loading branch information
Showing
11 changed files
with
486 additions
and
157 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from COMPS.Data import Experiment | ||
from idmtools.core.platform_factory import Platform | ||
from idmtools.entities import Suite | ||
from simulations.load_inputs import load_sites | ||
import simulations.manifest as manifest | ||
from simulations.helpers import get_comps_id_filename | ||
|
||
|
||
def add_suite(sites: list, suite_name: str = 'Malaria Model Validation Suite') -> object: | ||
""" | ||
Add all experiments to the suite of the 1st experiment, if the 1st experiment doesn't belong to any suite, add them | ||
to a new suite. | ||
Args: | ||
sites (): list of site names | ||
suite_name (): str for suite name | ||
Returns: | ||
suite_id | ||
""" | ||
platform = Platform(manifest.platform_name) | ||
first_exp_found = True | ||
for site in sites: | ||
exp_id_file = get_comps_id_filename(site, level=0) | ||
with open(exp_id_file, "r") as f: | ||
exp_id = f.readline().rstrip() | ||
exp = Experiment.get(exp_id) | ||
if first_exp_found: | ||
first_exp_found = False | ||
if exp.suite_id: | ||
suite_id = exp.suite_id | ||
print(f"Found existing suite {suite_id} for the 1st experiment, will save to this suite instead.") | ||
continue | ||
else: | ||
suite = Suite(name=suite_name) | ||
suite.update_tags({'name': suite_name}) | ||
platform.create_items([suite]) | ||
suite_id = suite.id | ||
print(f"Try to add all experiments to suite.id={suite_id}:") | ||
exp.suite_id = suite_id | ||
exp.save() | ||
with open(manifest.suite_id_file, "w") as file: | ||
file.write(str(suite_id)) | ||
return suite_id | ||
|
||
|
||
if __name__ == '__main__': | ||
all_sites, _, _ = load_sites() | ||
add_suite(all_sites) |
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,56 @@ | ||
import argparse | ||
import simulations.params as params | ||
import simulations.manifest as manifest | ||
from simulations.helpers import get_comps_id_filename, get_suite_id | ||
|
||
from idmtools.core.platform_factory import Platform | ||
from idmtools_platform_comps.utils.download.download import DownloadWorkItem | ||
from idmtools.core import ItemType | ||
|
||
|
||
def download_output(site: str, platform: Platform = None) -> bool: | ||
""" | ||
Download output csv files to output folder from analyzer work item for given site. | ||
Args: | ||
site (): | ||
platform (): | ||
Returns: status of download work item | ||
""" | ||
if not platform: | ||
platform = Platform(manifest.platform_name) | ||
analyzer_id_file = get_comps_id_filename(site, level=2) | ||
with open(analyzer_id_file, 'r') as id_file: | ||
wi_id = id_file.readline() | ||
wi_id = platform.get_item(wi_id, item_type=ItemType.WORKFLOW_ITEM) | ||
dl_wi = DownloadWorkItem( | ||
output_path="output", | ||
delete_after_download=False, | ||
extract_after_download=True, | ||
zip_name=f"{site}.zip", | ||
file_patterns=[f"{site}/**"] | ||
) | ||
dl_wi.related_work_items = [wi_id] | ||
suite_id = get_suite_id() | ||
dl_wi.tags['Suite'] = suite_id | ||
dl_wi.run(wait_until_done=True, platform=platform) | ||
|
||
# Check result | ||
if not dl_wi.succeeded: | ||
print(f"Download work item {dl_wi.uid} failed.\n") | ||
else: | ||
print(f"Download work item {dl_wi.uid} succeeded.") | ||
download_id_file = get_comps_id_filename(site, level=3) | ||
with open(download_id_file, 'w') as id_file: | ||
id_file.write(dl_wi.uid.hex) | ||
|
||
return dl_wi.succeeded | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser(description='Process site name') | ||
parser.add_argument('--site', '-s', type=str, help='site name', | ||
default=params.sites[0]) # not sure if we want to make this required argument | ||
args = parser.parse_args() | ||
download_output(args.site) |
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
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.