-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b336daa
commit cdf77ef
Showing
5 changed files
with
157 additions
and
92 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,22 @@ | ||
<PROJECT_SET> | ||
<PROJECT center_name="{{ Institution }}" alias="{{ group_accession }}:{{ organism }}:{{ unique_id }}"> | ||
<NAME>{{ ncbi_virus_name }}</NAME> | ||
<TITLE>{{ ncbi_virus_name }} Genome sequencing</TITLE> | ||
<DESCRIPTION>Automated upload of {{ ncbi_virus_name }} sequences submitted by {{ Institution }} from {{ db }}.</DESCRIPTION> | ||
<SUBMISSION_PROJECT> | ||
<SEQUENCING_PROJECT/> | ||
<ORGANISM> | ||
<TAXON_ID>{{ taxon_id }}</TAXON_ID> | ||
<SCIENTIFIC_NAME>{{ ncbi_virus_name }}</SCIENTIFIC_NAME> | ||
</ORGANISM> | ||
</SUBMISSION_PROJECT> | ||
<PROJECT_LINKS> | ||
<PROJECT_LINK> | ||
<XREF_LINK> | ||
<DB>{{ db }}</DB> | ||
<ID>{{ group_accession }}</ID> | ||
</XREF_LINK> | ||
</PROJECT_LINK> | ||
</PROJECT_LINKS> | ||
</PROJECT> | ||
</PROJECT_SET> |
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 |
---|---|---|
@@ -1,32 +1,92 @@ | ||
group_accession = "group1" | ||
Institution = "bla" | ||
db = "Pathoplexus" | ||
organism = "ebola-zaire" | ||
ncbi_virus_name = "Zaire ebolavirus" | ||
taxon_id = 186538 | ||
unique_id = "pathoplexus.org" # tbd | ||
|
||
final_project_xml = f""" | ||
<PROJECT_SET> | ||
<PROJECT center_name="{Institution}" alias="{group_accession}:{organism}:{unique_id}"> | ||
<NAME>{ncbi_virus_name}</NAME> | ||
<TITLE>{ncbi_virus_name} Genome sequencing</TITLE> | ||
<DESCRIPTION>Automated upload of {ncbi_virus_name} sequences submitted by {Institution} from {db}.</DESCRIPTION> | ||
<SUBMISSION_PROJECT> | ||
<SEQUENCING_PROJECT/> | ||
<ORGANISM> | ||
<TAXON_ID>{taxon_id}</TAXON_ID> | ||
<SCIENTIFIC_NAME>{ncbi_virus_name}</SCIENTIFIC_NAME> | ||
</ORGANISM> | ||
</SUBMISSION_PROJECT> | ||
<PROJECT_LINKS> | ||
<PROJECT_LINK> | ||
<XREF_LINK> | ||
<DB>{db}</DB> | ||
<ID>{group_accession}</ID> | ||
</XREF_LINK> | ||
</PROJECT_LINK> | ||
</PROJECT_LINKS> | ||
</PROJECT> | ||
</PROJECT_SET> | ||
""" | ||
import json | ||
import logging | ||
import string | ||
from dataclasses import dataclass | ||
from typing import Dict, List | ||
|
||
import click | ||
import yaml | ||
from submission_db import get_db_config, in_submission_table | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
logging.basicConfig( | ||
encoding="utf-8", | ||
level=logging.INFO, | ||
format="%(asctime)s %(levelname)8s (%(filename)20s:%(lineno)4d) - %(message)s ", | ||
datefmt="%H:%M:%S", | ||
) | ||
|
||
|
||
@dataclass | ||
class Config: | ||
organisms: List[Dict[str, str]] | ||
organism: str | ||
backend_url: str | ||
keycloak_token_url: str | ||
keycloak_client_id: str | ||
username: str | ||
password: str | ||
ena_specific_metadata: List[str] | ||
db_username: str | ||
db_password: str | ||
db_host: str | ||
|
||
|
||
def get_project_xml( | ||
group_accession="group1", | ||
Institution="bla", | ||
db="Pathoplexus", | ||
organism="ebola-zaire", | ||
ncbi_virus_name="Zaire ebolavirus", | ||
taxon_id=186538, | ||
unique_id="pathoplexus.org", | ||
): | ||
# Read the template file | ||
with open("resources/project_template.xml", "r") as file: | ||
template = string.Template(file.read()) | ||
|
||
# Create a dictionary with the values to substitute | ||
values = { | ||
"group_accession": group_accession, | ||
"Institution": Institution, | ||
"db": db, | ||
"organism": organism, | ||
"ncbi_virus_name": ncbi_virus_name, | ||
"taxon_id": taxon_id, | ||
"unique_id": unique_id, | ||
} | ||
|
||
# Substitute the placeholders with actual values | ||
return template.safe_substitute(values) | ||
|
||
|
||
@click.command() | ||
@click.option( | ||
"--log-level", | ||
default="INFO", | ||
type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]), | ||
) | ||
@click.option( | ||
"--config-file", | ||
required=True, | ||
type=click.Path(exists=True), | ||
) | ||
@click.option( | ||
"--input-file", | ||
required=True, | ||
type=click.Path(), | ||
) | ||
def create_project_xml(log_level, config_file, input_file): | ||
logger.setLevel(log_level) | ||
logging.getLogger("requests").setLevel(logging.WARNING) | ||
|
||
with open(config_file) as file: | ||
full_config = yaml.safe_load(file) | ||
relevant_config = {key: full_config.get(key, []) for key in Config.__annotations__} | ||
config = Config(**relevant_config) | ||
logger.info(f"Config: {config}") | ||
|
||
db_config = get_db_config(config.db_password, config.db_username, config.db_host) | ||
|
||
sequences_to_upload = json.load(open(input_file, encoding="utf-8")) |
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