Skip to content

Commit

Permalink
🐛 specify fields as parameter
Browse files Browse the repository at this point in the history
- output should be tsv due to how pandas return is constructed for now
  • Loading branch information
enryH committed Dec 9, 2024
1 parent 9d7c5f2 commit dba2000
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions acore/io/uniprot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@


# function for outside usage
def fetch_annotations(ids: pd.Index | list) -> pd.DataFrame:
def fetch_annotations(
ids: pd.Index | list,
fields: str = "accession,go_p,go_c,go_f",
) -> pd.DataFrame:
"""Fetch annotations for UniProt IDs. Combines several calls to the API of UniProt's
knowledgebase (KB).
Expand All @@ -30,13 +33,14 @@ def fetch_annotations(ids: pd.Index | list) -> pd.DataFrame:
DataFrame with annotations of the UniProt IDs.
"""
job_id = submit_id_mapping(from_db="UniProtKB_AC-ID", to_db="UniProtKB", ids=ids)

# tsv used here to return a DataFrame. Maybe other formats are availale at some points
_format = "tsv"
if check_id_mapping_results_ready(job_id):
link = get_id_mapping_results_link(job_id)
# add fields to the link to get more information
# From and Entry (accession) are the same for UniProt IDs.
results = get_id_mapping_results_search(
link + "?fields=accession,go_p,go_c,go_f&format=tsv"
link + f"?fields={fields}&format={_format}"
)
header = results.pop(0).split("\t")
results = [line.split("\t") for line in results]
Expand Down

0 comments on commit dba2000

Please sign in to comment.