-
Notifications
You must be signed in to change notification settings - Fork 0
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 #33 from RIVM-bioinformatics/add_salm_col
Add context to salmonella serotypes
- Loading branch information
Showing
8 changed files
with
183 additions
and
4 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,100 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import logging | ||
from pathlib import Path | ||
|
||
import pandas as pd | ||
|
||
|
||
def df_to_dict(df, column_name): | ||
""" | ||
Convert a dataframe to a dictionary | ||
Parameters | ||
---------- | ||
df : pd.DataFrame | ||
Input dataframe | ||
column_name : str | ||
Column name to use as key | ||
Returns | ||
------- | ||
dict | ||
Dictionary with column values as keys and the rest of the row as values | ||
""" | ||
df = df[df["Column"] == column_name] | ||
dict_ = df.set_index("Value").to_dict(orient="index") | ||
return dict_ | ||
|
||
|
||
def add_context(df_context, value, col_name): | ||
""" | ||
Add context to a value | ||
Parameters | ||
---------- | ||
df_context : pd.DataFrame | ||
Dataframe with context for e.g. specific serotypes | ||
value : str | ||
Value to check, e.g. serotype name | ||
col_name : str | ||
Column name to check, e.g. "Predicted serotype" | ||
Returns | ||
------- | ||
str | ||
Context for the value | ||
""" | ||
logging.info(f"Checking context for {col_name}={value}") | ||
context = None | ||
dict_context = df_to_dict(df_context, col_name) | ||
if value in dict_context: | ||
logging.info(f"Found context for {col_name}={value}") | ||
context_partial = dict_context[value]["Context"] | ||
context = f"{col_name}={value}: {context_partial}" | ||
return context | ||
|
||
|
||
def main(args): | ||
logging.info(f"Reading {args.input} and {args.context}") | ||
df = pd.read_csv(args.input, sep="\t") | ||
df_context = pd.read_csv(args.context, sep="\t") | ||
notes = [] | ||
|
||
logging.info(f"Check if this is a single sample report") | ||
if df.shape[0] > 1: | ||
raise ValueError("This script only works for single sample reports") | ||
|
||
# Add context to O antigen | ||
O_gene = df["O antigen prediction"].values[0] | ||
notes.append(add_context(df_context, O_gene, "O antigen prediction")) | ||
|
||
# Add context to serotype | ||
serotype = df["Predicted serotype"].values[0] | ||
notes.append(add_context(df_context, serotype, "Predicted serotype")) | ||
|
||
# Combine all notes | ||
note_str = "|".join([note for note in notes if note is not None]) | ||
df["RIVM-specific notes"] = note_str | ||
|
||
# Write to output | ||
logging.info(f"Writing to {args.output}") | ||
df.to_csv(args.output, sep="\t", index=False) | ||
|
||
|
||
if __name__ == "__main__": | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser("Add context to SeqSero report") | ||
|
||
parser.add_argument("-i", "--input", required=True, type=Path) | ||
parser.add_argument("-o", "--output", required=True, type=Path) | ||
parser.add_argument("-c", "--context", required=True, type=Path) | ||
parser.add_argument("--verbose", action="store_true") | ||
|
||
args = parser.parse_args() | ||
|
||
if args.verbose: | ||
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(message)s") | ||
|
||
main(args) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
channels: | ||
- conda-forge | ||
dependencies: | ||
- pandas=2.1.* |
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,38 @@ | ||
Column Value Context Source | ||
Predicted serotype Virginia Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Muenchen Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Yovokome Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Manhattan Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Bardo Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Newport Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Ferruch Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Kottbus Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Bargny Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Takoradi Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Haardt Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Blockley Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Pakistan Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Litchfield Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Hindmarsh Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Bovismorbificans Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Brikama Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Goldcoast Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Albany Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Duesseldorf Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Paris Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Mapo Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Istanbul Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Hadar Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Chomedey Phenotypic confirmation of O6 antigen required | ||
Predicted serotype Glostrup Phenotypic confirmation of O6 antigen required | ||
Predicted serotype 4,[5],12:i:- Confirm with PCR according to SOP IDS_BAC_M321 Validation report | ||
Predicted serotype Miami Confirm with growth on Simmons citrate (should be +) Validation report | ||
Predicted serotype Sendai Confirm with growth on Simmons citrate (should be -) Validation report | ||
Predicted serotype Typhimurium Confirm with PCR according to SOP IDS_BAC_M321 Validation report | ||
Predicted serotype Senftenberg Phenotypic confirmation required https://doi.org/10.1128%2FAEM.02265-19 | ||
Predicted serotype Dessau Phenotypic confirmation required https://doi.org/10.1128%2FAEM.02265-19 | ||
Predicted serotype Indiana Phenotypic confirmation required https://doi.org/10.1128%2FAEM.02265-19 | ||
Predicted serotype 4,12:z:1,7 Phenotypic confirmation required https://doi.org/10.1128%2FAEM.02265-19 | ||
O antigen prediction 6,14 Confirm with O24/O25 antisera Validation report | ||
O antigen prediction 3,10 Phenotypic confirmation required | ||
O antigen prediction 1,3,19 Phenotypic confirmation required |
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