Exemple #1
0
def _ensure_conv_genome_helper(
    kegg_genome_id: str,
    target_database: str,
    *,
    version: str,
    error_on_missing: bool = False,
) -> Optional[str]:
    """Get the KEGG-external protein map for the given organism/database."""
    name = f"{kegg_genome_id}.tsv"
    try:
        rv = ensure_path(
            KEGG_GENES_PREFIX,
            f"conv_{target_database}",
            url=f"{BASE}/conv/{target_database}/{kegg_genome_id}",
            name=name,
            error_on_missing=error_on_missing,
            version=version,
        )
    except urllib.error.HTTPError:
        path_rv = prefix_directory_join(
            KEGG_GENES_PREFIX,
            f"conv_{target_database}",
            name=name,
            version=version,
        )
        with path_rv.open("w") as file:
            print(file=file)  # noqa: T201
        return path_rv.as_posix()
    except FileNotFoundError:
        return None
    else:
        return rv
Exemple #2
0
def ensure_list_genomes(version: str) -> str:
    """Ensure the KEGG Genome file is downloaded."""
    return ensure_path(
        KEGG_GENOME_PREFIX,
        url=f"{BASE}/list/genome",
        name="genome.tsv",
        version=version,
    )
Exemple #3
0
def ensure_list_genome(kegg_genome_id: str, *, version: str) -> str:
    """Get the list of genes for the given organism."""
    return ensure_path(
        KEGG_GENES_PREFIX,
        "genes",
        url=f"{BASE}/list/{kegg_genome_id}",
        name=f"{kegg_genome_id}.tsv",
        version=version,
    )
Exemple #4
0
def ensure_list_pathway_genome(kegg_genome_id: str,
                               *,
                               version: str,
                               error_on_missing: bool = False) -> str:
    """Get the list of pathways for the given organism.

    :raises: FileNotFoundError
    """
    return ensure_path(
        KEGG_PATHWAY_PREFIX,
        "pathways",
        url=f"{BASE}/list/pathway/{kegg_genome_id}",
        name=f"{kegg_genome_id}.tsv",
        error_on_missing=error_on_missing,
        version=version,
    )
Exemple #5
0
def ensure_link_pathway_genome(kegg_genome_id: str,
                               *,
                               version: str,
                               error_on_missing: bool = False) -> str:
    """Get the protein-pathway links for the given organism.

    :raises: FileNotFoundError
    """
    return ensure_path(
        KEGG_PATHWAY_PREFIX,
        'link_pathway',
        url=f'{BASE}/link/pathway/{kegg_genome_id}',
        name=f'{kegg_genome_id}.tsv',
        error_on_missing=error_on_missing,
        version=version,
    )