Skip to content

Commit

Permalink
Prevent failures when:
Browse files Browse the repository at this point in the history
optional biosample/sra columns are empty
bs-description is not present
  • Loading branch information
erikwolfsohn committed Aug 16, 2024
1 parent d2a65d9 commit fe7f44f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ docker-compose-*.yaml

# ignore folders
**/.Rproj.user
**/test_data/*
**/gisaid_cli/*
12 changes: 12 additions & 0 deletions tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from datetime import datetime, timedelta
from cerberus import Validator
import re
import shutil

from config.seqsender.seqsender_schema import schema as seqsender_schema
from settings import SCHEMA_EXCLUSIONS, BIOSAMPLE_REGEX, SRA_REGEX, GISAID_REGEX, GENBANK_REGEX, GENBANK_REGEX_CMT, GENBANK_REGEX_SRC
Expand Down Expand Up @@ -132,6 +133,17 @@ def parse_hold_date(config_dict: Dict[str, Any]):
def get_metadata(database: List[str], organism: str, metadata_file: str, config_dict: Dict[str, Any], skip_validation: bool = False) -> pd.DataFrame:
# Read in metadata file
metadata = file_handler.load_csv(metadata_file)
# Adding some default handling for bs-description here - it's not mandatory for biosample submission, but is required in the workflow
if 'bs-description' not in metadata.columns:
# Create 'bs-description' by joining 'organism', 'bs-host', and 'bs-host_disease' columns
metadata['bs-description'] = metadata[['organism', 'bs-host', 'bs-host_disease']].apply(
lambda row: ' '.join(row.dropna().astype(str)), axis=1
)
# If there are empty biosample or sra columns in the metadata sheet, assume they are unused optional columns and drop them before pandera attempts to validate
columns_to_drop = [col for col in metadata.columns if (col.startswith('bs-') or col.startswith('sra-')) and metadata[col].replace('', pd.NA).apply(lambda x: x.strip() if isinstance(x, str) else x).isna().all()]
metadata = metadata.drop(columns=columns_to_drop)
shutil.copy(metadata_file, metadata_file + ".bak")
file_handler.save_csv(metadata, metadata_file)
# Update seqsender base schema to include needed checks
if "BioSample" in database or "SRA" in database:
seqsender_schema.update_columns({"bioproject":{"checks":Check.str_matches(r"^(?!\s*$).+"),"nullable":False,"required":True}})
Expand Down

0 comments on commit fe7f44f

Please sign in to comment.