diff --git a/config/schema.yaml b/config/schema.yaml index 2fabb1a..b56635c 100644 --- a/config/schema.yaml +++ b/config/schema.yaml @@ -384,6 +384,41 @@ variant biomarker for treatment: data_source: str Tier: str +biomarker_for_treatment_level_IA: + is_a: variant biomarker for treatment + represented_as: edge + input_label: biomarker_for_treatment_level_IA + +biomarker_for_treatment_level_IC: + is_a: variant biomarker for treatment + represented_as: edge + input_label: biomarker_for_treatment_level_IC + +biomarker_for_treatment_level_II: + is_a: variant biomarker for treatment + represented_as: edge + input_label: biomarker_for_treatment_level_II + +biomarker_for_treatment_level_IIIA: + is_a: variant biomarker for treatment + represented_as: edge + input_label: biomarker_for_treatment_level_IIIA + +biomarker_for_treatment_level_IIIB: + is_a: variant biomarker for treatment + represented_as: edge + input_label: biomarker_for_treatment_level_IIIB + +biomarker_for_treatment_level_IVA: + is_a: variant biomarker for treatment + represented_as: edge + input_label: biomarker_for_treatment_level_IVA + +biomarker_for_treatment_level_IVB: + is_a: variant biomarker for treatment + represented_as: edge + input_label: biomarker_for_treatment_level_IVB + ## METADATA patient has chronic illness: diff --git a/make.sh b/make.sh index b400ae2..56429d1 100755 --- a/make.sh +++ b/make.sh @@ -4,30 +4,30 @@ work_dir=$(pwd) CONFIG="config/neo4j.yaml" if [[ -z "$1" ]] ; then - echo "ERROR, usage: $0 [config] [debug|sub-sample_percentage]" >&2 + echo "ERROR, usage: $0 [config] [debug|xdebug|sub-sample_percentage]" >&2 echo " config defaults to: $CONFIG" >&2 exit 2 fi if [[ -z "$2" ]] ; then echo "Selecting Neo4j output configuration." >&2 -elif [[ "$2" == "debug" ]] ; then - echo "ERROR, if DEBUG MODE, usage: $0 debug" >&2 +elif [[ "$2" == "debug" || "$2" == "xdebug" ]] ; then + echo "ERROR, if DEBUG MODE, usage: $0 " >&2 exit 2 else echo "Selecting output configuration: $2" >&2 CONFIG="$2" fi -set -e -set -o pipefail +# set -e +# set -o pipefail decider_dir="$(realpath $1)" data_dir="$(realpath $1/..)" sub_sample="" if [[ -n "$3" ]] ; then - if [[ "$3" == "debug" ]] ; then + if [[ "$3" == "debug" || "$3" == "xdebug" ]] ; then echo "DEBUG MODE" >&2 data_dir="$(realpath $decider_dir/../../data_debug)" decider_dir="$(realpath $decider_dir/../../data_debug/DECIDER_debug)" @@ -62,13 +62,14 @@ else NEO_USER="" fi -# py_args="-O" # Optimize = remove asserts and optimize bytecode. -py_args="" # Optimize = remove asserts and optimize bytecode. # HERE +py_args="-O" # Optimize = remove asserts and optimize bytecode. weave_args="-v INFO" # Default, for having clean progress bars. if [[ "$3" == "debug" ]] ; then + py_args="" + weave_args="--debug -v INFO" +elif [[ "$3" == "xdebug" ]] ; then py_args="" weave_args="--debug -v DEBUG" - # weave_args="--debug -v INFO" fi @@ -84,9 +85,9 @@ echo "Weave data..." >&2 cmd="uv run python3 ${py_args} $script_dir/weave.py --config $CONFIG - --structural-variants-2 $decider_dir/structural_variants_2.csv --clinical $decider_dir/clinical_export.xlsx --short-mutations-local $decider_dir/short_mutations_local.csv + --structural-variants-2 $decider_dir/structural_variants_2.csv --short-mutations-external $decider_dir/short_mutations_external.csv --copy-number-amplifications-local $decider_dir/cnas_local.csv --copy-number-amplifications-external $decider_dir/cnas_external.csv @@ -99,14 +100,17 @@ cmd="uv run python3 ${py_args} $script_dir/weave.py --oncokb-gene-status $decider_dir/oncokb_gene_status_info.csv ${sub_sample} ${weave_args}" - echo "Weaving command:" >&2 echo "$cmd" >&2 $cmd > last_biocypher_import.sh +if [[ -z "$(cat last_biocypher_import.sh)" ]] ; then + echo "ERROR: The weave command returned nothing." >&2 + exit 1 +fi -if [[ "$CONFIG" == "config/neo4j.yaml" ]] ; then +if [[ "$CONFIG" == *"neo4j"* ]] ; then echo "Stop Neo4j server..." >&2 neo_version=$(neo4j-admin --version | cut -d. -f 1) if [[ "$neo_version" -eq 4 ]]; then @@ -120,6 +124,12 @@ if [[ "$CONFIG" == "config/neo4j.yaml" ]] ; then chmod a+x $(cat last_biocypher_import.sh) ${NEO_USER} $SHELL $(cat last_biocypher_import.sh) + err=$? + if [[ $err -gt 0 ]] ; then + echo "Import in Neo4j failed on error: $err" + exit $err + fi + echo "Restart Neo4j..." >&2 $server start sleep 5 diff --git a/oncodashkb/adapters/clinical.yaml b/oncodashkb/adapters/clinical.yaml index 0034d94..a8380f8 100644 --- a/oncodashkb/adapters/clinical.yaml +++ b/oncodashkb/adapters/clinical.yaml @@ -320,3 +320,5 @@ transformers: # to_object: disease # via_relation: patient_has_chronic_illness +metadata: + - data_source: DECIDER_clinical diff --git a/oncodashkb/adapters/oncokb.yaml b/oncodashkb/adapters/oncokb.yaml index 3e61f37..7be1b54 100644 --- a/oncodashkb/adapters/oncokb.yaml +++ b/oncodashkb/adapters/oncokb.yaml @@ -9,20 +9,23 @@ row: - CNA: to_subject: copy_number_amplification transformers: - - replace: - column: treatment - to_object: treatment - via_relation: variant_biomarker_for_treatment - forbidden: ';' - substitute: ' + ' - - split_translate: - column: treatment - to_object: drug - via_relation: variant_biomarker_for_treatment - separator: ";" - translations_file: ./data/OT/drug_molecule/part-00000-871f412e-aec4-4d33-a50d-feee532ddcd2-c000.snappy.parquet - translate_from: name - translate_to: id + # - replace: + # # replaced by user-defined transformer with escat level included in the name of the relation + # column: treatment + # to_object: treatment + # via_relation: variant_biomarker_for_treatment + # forbidden: ';' + # substitute: ' + ' + # + # - split_translate: + # # Not used anymore + # column: treatment + # to_object: drug + # via_relation: variant_biomarker_for_treatment + # separator: ";" + # translations_file: ./data/OT/drug_molecule/part-00000-871f412e-aec4-4d33-a50d-feee532ddcd2-c000.snappy.parquet + # translate_from: name + # translate_to: id - split_translate: column: treatment from_subject: treatment @@ -44,20 +47,36 @@ transformers: # translate_from: name # translate_to: id ## Variant biomarker for treatment - - map: - column: level_of_evidence - to_property: level_of_evidence - for_object: variant_biomarker_for_treatment + # - map: + # # Replaced by escat_tier_transformer + # column: level_of_evidence + # to_property: level_of_evidence + # for_object: variant_biomarker_for_treatment + - escat_tier_transformer - replace: column: citations to_property: citations - for_object: variant_biomarker_for_treatment + for_object: + - variant_biomarker_for_treatment_level_IA + - variant_biomarker_for_treatment_level_IC + - variant_biomarker_for_treatment_level_II + - variant_biomarker_for_treatment_level_IIIA + - variant_biomarker_for_treatment_level_IIIB + - variant_biomarker_for_treatment_level_IVA + - variant_biomarker_for_treatment_level_IVB forbidden: ';' substitute: ',' - map: column: tumorType to_property: tumorType - for_object: variant_biomarker_for_treatment + for_object: + - variant_biomarker_for_treatment_level_IA + - variant_biomarker_for_treatment_level_IC + - variant_biomarker_for_treatment_level_II + - variant_biomarker_for_treatment_level_IIIA + - variant_biomarker_for_treatment_level_IIIB + - variant_biomarker_for_treatment_level_IVA + - variant_biomarker_for_treatment_level_IVB metadata: - data_source: oncokb_annotation @@ -105,4 +124,4 @@ validate: dtype: str nullable: true checks: - str_matches: ^[ABCD]\([^\d]+\)$ \ No newline at end of file + str_matches: ^[ABCD]\([^\d]+\)$ diff --git a/oncodashkb/adapters/template__copy_number_amplifications_external.yaml b/oncodashkb/adapters/template__copy_number_amplifications_external.yaml index f8ecc36..68dec4f 100644 --- a/oncodashkb/adapters/template__copy_number_amplifications_external.yaml +++ b/oncodashkb/adapters/template__copy_number_amplifications_external.yaml @@ -6,6 +6,7 @@ row: translate_from: Patient card::Patient cohort code_Patient Card translate_to: Patient card::Publication code index_col: 0 + on_unknown_value: skip usecols: [0,1,2] transformers: # Nodes @@ -45,7 +46,7 @@ transformers: Loss-of-function: LoF Likely Loss-of-function: LoF Gain-of-function: GoF - Likely Gain-of-function: LoF + Likely Gain-of-function: GoF Act: GoF Inconclusive: Inconclusive ambiguous: ambiguous @@ -82,7 +83,7 @@ transformers: Loss-of-function: LoF Likely Loss-of-function: LoF Gain-of-function: GoF - Likely Gain-of-function: LoF + Likely Gain-of-function: GoF Act: GoF Inconclusive: Inconclusive ambiguous: ambiguous @@ -91,11 +92,12 @@ transformers: columns: gene_role to_property: gene_role for_object: variant_causes_gene_status + on_unknown_value: skip translations: Loss-of-function: LoF Likely Loss-of-function: LoF Gain-of-function: GoF - Likely Gain-of-function: LoF + Likely Gain-of-function: GoF Act: GoF Inconclusive: Inconclusive ambiguous: ambiguous @@ -170,4 +172,4 @@ transformers: - gene_status_affects_gene metadata: - - data_source: copy_number_amplifications_external + - data_source: DECIDER_copy_number_amplifications_external diff --git a/oncodashkb/adapters/template__copy_number_amplifications_local.yaml b/oncodashkb/adapters/template__copy_number_amplifications_local.yaml index 071220a..a85fe96 100644 --- a/oncodashkb/adapters/template__copy_number_amplifications_local.yaml +++ b/oncodashkb/adapters/template__copy_number_amplifications_local.yaml @@ -6,6 +6,7 @@ row: translate_from: Patient card::Patient cohort code_Patient Card translate_to: Patient card::Publication code index_col: 0 + on_unknown_value: skip usecols: [0,1,2] transformers: - translate_sample_ids : @@ -51,4 +52,4 @@ transformers: for_object: sample_carries_variant metadata: - - data_source: copy_number_amplifications_local + - data_source: DECIDER_copy_number_amplifications_local diff --git a/oncodashkb/adapters/template__short_mutations_external.yaml b/oncodashkb/adapters/template__short_mutations_external.yaml index 16ab08d..243606c 100644 --- a/oncodashkb/adapters/template__short_mutations_external.yaml +++ b/oncodashkb/adapters/template__short_mutations_external.yaml @@ -6,6 +6,7 @@ row: translate_from: Patient card::Patient cohort code_Patient Card translate_to: Patient card::Publication code index_col: 0 + on_unknown_value: skip usecols: [0,1,2] transformers: # Nodes @@ -42,7 +43,7 @@ transformers: Loss-of-function: LoF Likely Loss-of-function: LoF Gain-of-function: GoF - Likely Gain-of-function: LoF + Likely Gain-of-function: GoF Inconclusive: Inconclusive Unknown: Unknown Likely Neutral: Likely Neutral @@ -64,13 +65,13 @@ transformers: for_object: gene_status to_property: ensembl_id_gene_status format_string: "{ensembl_id}:{gene_role}" - column_to_translate: + column_to_translate: - gene_role translations: Loss-of-function: LoF Likely Loss-of-function: LoF Gain-of-function: GoF - Likely Gain-of-function: LoF + Likely Gain-of-function: GoF Inconclusive: Inconclusive Unknown: Unknown Likely Neutral: Likely Neutral @@ -78,11 +79,12 @@ transformers: columns: gene_role to_property: gene_role for_object: gene_status + on_unknown_value: skip translations: Loss-of-function: LoF Likely Loss-of-function: LoF Gain-of-function: GoF - Likely Gain-of-function: LoF + Likely Gain-of-function: GoF Inconclusive: Inconclusive Unknown: Unknown Likely Neutral: Likely Neutral @@ -158,4 +160,4 @@ transformers: - variant_causes_gene_status - gene_status_affects_gene metadata: - - data_source: short_mutations_external + - data_source: DECIDER_short_mutations_external diff --git a/oncodashkb/adapters/template__short_mutations_local.yaml b/oncodashkb/adapters/template__short_mutations_local.yaml index 8fc96f3..123e926 100644 --- a/oncodashkb/adapters/template__short_mutations_local.yaml +++ b/oncodashkb/adapters/template__short_mutations_local.yaml @@ -6,6 +6,7 @@ row: translate_from: Patient card::Patient cohort code_Patient Card translate_to: Patient card::Publication code index_col: 0 + on_unknown_value: skip usecols: [0,1,2] transformers: - translate_sample_ids : @@ -97,4 +98,4 @@ transformers: - patient_carries_sample - sample_carries_variant metadata: - - data_source: short_mutations_local + - data_source: DECIDER_short_mutations_local diff --git a/oncodashkb/adapters/template__structural_variants.yaml b/oncodashkb/adapters/template__structural_variants.yaml index 72daf59..d92b4b3 100644 --- a/oncodashkb/adapters/template__structural_variants.yaml +++ b/oncodashkb/adapters/template__structural_variants.yaml @@ -6,6 +6,7 @@ row: translate_from: Patient card::Patient cohort code_Patient Card translate_to: Patient card::Publication code index_col: 0 + on_unknown_value: skip usecols: [0,1,2] transformers: # Nodes @@ -67,6 +68,7 @@ transformers: translations_file: data/HGNC/hgnc_complete_set.txt translate_from: symbol translate_to: ensembl_gene_id + on_unknown_value: skip sep: "\t" # Properties ## Sample @@ -112,6 +114,7 @@ transformers: columns: Gene_type to_property: gene_role for_object: gene_status + on_unknown_value: skip translations: gain: GoF loss: LoF @@ -163,4 +166,4 @@ transformers: - gene_status_affects_gene metadata: - - data_source: structural_variants_placeholder + - data_source: DECIDER_structural_variants_placeholder diff --git a/oncodashkb/adapters/template__structural_variants_2.yaml b/oncodashkb/adapters/template__structural_variants_2.yaml index 535f860..c9f590e 100644 --- a/oncodashkb/adapters/template__structural_variants_2.yaml +++ b/oncodashkb/adapters/template__structural_variants_2.yaml @@ -117,5 +117,5 @@ transformers: - gene_status_affects_gene metadata: - - data_source: structural_variants + - data_source: DECIDER_structural_variants diff --git a/oncodashkb/transformers/escat_tier_transformer.py b/oncodashkb/transformers/escat_tier_transformer.py new file mode 100644 index 0000000..77e9b33 --- /dev/null +++ b/oncodashkb/transformers/escat_tier_transformer.py @@ -0,0 +1,80 @@ +import logging +import ontoweaver +from ontoweaver import types as owtypes + +class escat_tier_transformer(ontoweaver.base.Transformer): + + def is_type_of_cancer_in(type, list_of_types): + for t in list_of_types: + if t in type: + return True + return False + + # def description_contains_drugs(descr, list_of_drugs): + # for d in list_of_drugs: + # if d in descr: + # return True + # return False + + def __init__(self, **kwargs): + super().__init__(**kwargs) +# self.declare = ontoweaver.base.Declare(raise_errors = kwargs["raise_errors"]) + self.declare_types.make_node_class("alteration") + self.declare_types.make_node_class("treatment") + self.declare_types.make_edge_class("biomarker_for_treatment_level_IA", getattr(owtypes, "alteration"), getattr(owtypes, "treatment")) + self.declare_types.make_edge_class("biomarker_for_treatment_level_IC", getattr(owtypes, "alteration"), getattr(owtypes, "treatment")) + self.declare_types.make_edge_class("biomarker_for_treatment_level_II", getattr(owtypes, "alteration"), getattr(owtypes, "treatment")) + self.declare_types.make_edge_class("biomarker_for_treatment_level_IIIA", getattr(owtypes, "alteration"), getattr(owtypes, "treatment")) + self.declare_types.make_edge_class("biomarker_for_treatment_level_IIIB", getattr(owtypes, "alteration"), getattr(owtypes, "treatment")) + self.declare_types.make_edge_class("biomarker_for_treatment_level_IVA", getattr(owtypes, "alteration"), getattr(owtypes, "treatment")) + self.declare_types.make_edge_class("biomarker_for_treatment_level_IVB", getattr(owtypes, "alteration"), getattr(owtypes, "treatment")) + + def __call__(self, row, i): + treatment = str(row["treatment"]) + fda_level = str(row["level_of_evidence"]) + cancer_type = str(row["tumorType"]) + + approved_drugs = ["Zenocutuzumab", "Selitrectinib"] + # approved = description_contains_drugs(str(row["decription"], approved_drugs) and fda_level in ["1", "2"] + approved = treatment in approved_drugs and fda_level in ["1", "2"] + + # Tier IA + if fda_level in ["LEVEL_1", "LEVEL_2"] and cancer_type in ["Ovarian", "ovarian"]: + tier = "IA" + + # Tier IC + elif fda_level in ["LEVEL_1", "LEVEL_2"] and cancer_type in ["Solid", "solid"]: + tier = "IC" + + # Tier II: + elif fda_level in ["LEVEL_3A"] and \ + cancer_type in ["Solid", "solid", "Ovarian", "ovarian"] and \ + not row["treatment"].contains("Trastuzumab Deruxtecan") and \ + approved: + tier = "II" + + # Tier IVA + elif fda_level in ["LEVEL_3A"] and \ + not "Trastuzumab Deruxtecan" in treatment and \ + cancer_type in ["Ovarian", "ovarian", "Solid", "solid"]: + tier = "IVA" + + # Tier IIIA + # FIXME NB rule => fda 1 ou 2 mais code de Taru = fda 1, 2 ou 3 et approved a verifier + elif fda_level in ["LEVEL_1", "LEVEL_2", "LEVEL_3A"] and \ + approved : + # and cancer_type not in ["ovarian", "ovarian", "Solid", "solid"] + tier = "IIIA" + + # FIXME Tier IIIB ne concerne pas oncokb, donc pas applicable dans le transformer. + + # FIXME Tier IVA deuxieme regle a verifier: est-ce qu'on prend que level 4 ou R1 et R2 aussi ? + elif fda_level in ["LEVEL_4"]: + tier = "IVA" + + # Tier IVB + else: + tier = "IVB" + + yield treatment, getattr(owtypes, "biomarker_for_treatment_level_"+tier), getattr(owtypes, "treatment"), None + diff --git a/prepare.sh b/prepare.sh index 5b3d331..b7a59d9 100755 --- a/prepare.sh +++ b/prepare.sh @@ -19,7 +19,7 @@ set -e root_dir=$(pwd) data_dir="data" decider_dir="$(realpath $1)" -decider_snapshot_dir="$(realpath $data_dir/$2)" +decider_snapshot_dir="$data_dir/$2" log_file="prepare.log" echo "" > $log_file @@ -247,7 +247,7 @@ cd $root_dir # ## 2.3 - Debugging data echo "Create a smaller debuging data set in data_debug/..." >&2 -lines=100 +lines=10 echo " │ DECIDER..." >&2 mkdir -p data_debug mkdir -p data_debug/DECIDER_debug/ diff --git a/weave.py b/weave.py index 94dabda..2d6d1ba 100755 --- a/weave.py +++ b/weave.py @@ -38,6 +38,10 @@ ontoweaver.transformer.register(translate_sample_ids) ontoweaver.transformer.register(translate_cat_format) +# Importing custom transformer for tanslating FDA levels to ESCAT Tiers +from oncodashkb.transformers.escat_tier_transformer import escat_tier_transformer +ontoweaver.transformer.register(escat_tier_transformer) + # Importing OpenTargets custom transformer and registering it. from oncodashkb.transformers.ot_transformers import access_proteins, urls_to_prop ontoweaver.transformer.register(access_proteins) @@ -752,9 +756,9 @@ def process_OT(directory, name): logging.info(f"Write the final SKG into files...") if nodes: - bc.write_nodes(n.as_tuple() for n in nodes) + bc.write_nodes(f_nodes) if edges: - bc.write_edges(e.as_tuple() for e in edges) + bc.write_edges(f_edges) #bc.summary() import_file = bc.write_import_call() logging.info(f"OK, wrote files.")