From 793b4ef7201d01d9f35857ab5e5405775e96974a Mon Sep 17 00:00:00 2001 From: Lieke Schoenmaker Date: Thu, 8 Aug 2019 16:26:59 +0200 Subject: [PATCH] DEV-759: refactor --- .../hartwig/hmftools/vicc/ViccJsonReader.java | 65 +++++++++++++++---- .../datamodel/MolecularMatchAstRight.java | 8 +-- .../datamodel/MolecularMatchAstRightLeft.java | 18 +++++ .../MolecularMatchAstRightRight.java | 18 +++++ .../datamodel/MolecularMatchMutations.java | 2 +- 5 files changed, 93 insertions(+), 18 deletions(-) create mode 100644 vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/datamodel/MolecularMatchAstRightLeft.java create mode 100644 vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/datamodel/MolecularMatchAstRightRight.java diff --git a/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/ViccJsonReader.java b/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/ViccJsonReader.java index 315d19292c..6db4969abc 100644 --- a/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/ViccJsonReader.java +++ b/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/ViccJsonReader.java @@ -58,6 +58,8 @@ import com.hartwig.hmftools.vicc.datamodel.ImmutableMolecularMatchAst; import com.hartwig.hmftools.vicc.datamodel.ImmutableMolecularMatchAstLeft; import com.hartwig.hmftools.vicc.datamodel.ImmutableMolecularMatchAstRight; +import com.hartwig.hmftools.vicc.datamodel.ImmutableMolecularMatchAstRightLeft; +import com.hartwig.hmftools.vicc.datamodel.ImmutableMolecularMatchAstRightRight; import com.hartwig.hmftools.vicc.datamodel.ImmutableMolecularMatchClassification; import com.hartwig.hmftools.vicc.datamodel.ImmutableMolecularMatchCriteriaUnmet; import com.hartwig.hmftools.vicc.datamodel.ImmutableMolecularMatchFusions; @@ -100,6 +102,8 @@ import com.hartwig.hmftools.vicc.datamodel.MolecularMatchAst; import com.hartwig.hmftools.vicc.datamodel.MolecularMatchAstLeft; import com.hartwig.hmftools.vicc.datamodel.MolecularMatchAstRight; +import com.hartwig.hmftools.vicc.datamodel.MolecularMatchAstRightLeft; +import com.hartwig.hmftools.vicc.datamodel.MolecularMatchAstRightRight; import com.hartwig.hmftools.vicc.datamodel.MolecularMatchClassification; import com.hartwig.hmftools.vicc.datamodel.MolecularMatchCriteriaUnmet; import com.hartwig.hmftools.vicc.datamodel.MolecularMatchFusions; @@ -234,7 +238,10 @@ public final class ViccJsonReader { private static final List EXPECTED_MOLECULARMATCH_ELEMENT_SIZES = Lists.newArrayList(34, 35, 36, 37, 38, 39, 40, 41, 42); private static final List EXPECTED_MOLECULARMATCH_AST_SIZES = Lists.newArrayList(3, 4); private static final List EXPECTED_MOLECULARMATCH_LEFT_SIZES = Lists.newArrayList(3, 4); - private static final List EXPECTED_MOLECULARMATCH_RIGHT_SIZES = Lists.newArrayList(3, 4); + private static final List EXPECTED_MOLECULARMATCH_RIGHT_SIZES = Lists.newArrayList(3,4); + private static final List EXPECTED_MOLECULARMATCH_RIGHT_LEFT_SIZES = Lists.newArrayList(3); + private static final List EXPECTED_MOLECULARMATCH_RIGHT_RIGHT_SIZES = Lists.newArrayList(3); + private static final List EXPECTED_MOLECULARMATCH_CLASSIFICATION_SIZES = Lists.newArrayList(3, 29, 30, 31); private static final List EXPECTED_MOLECULARMATCH_CRITERIA_UNMET_SIZES = Lists.newArrayList(8, 9, 12, 13); private static final List EXPECTED_MOLECULARMATCH_LOCATIONGRCH37_SIZES = Lists.newArrayList(9); @@ -291,7 +298,7 @@ public static List readViccKnowledgebaseJsonFile(@NotNull String json LOGGER.info("Reading VICC knowledgebase from " + jsonPath); while (reader.peek() != JsonToken.END_DOCUMENT) { JsonObject viccEntryObject = parser.parse(reader).getAsJsonObject(); - // LOGGER.info(number); + LOGGER.info(number); number++; if (!EXPECTED_VICC_ENTRY_SIZES.contains(viccEntryObject.size())) { LOGGER.warn("Found " + viccEntryObject.size() + " elements in a vicc entry rather than the expected " @@ -1541,7 +1548,6 @@ private static MolecularMatchAst createAst(@NotNull JsonObject objectAst) { "Found " + keysAst.size() + " in molecular match ast rather than the expected " + EXPECTED_MOLECULARMATCH_AST_SIZES); LOGGER.warn(keysAst); } - return ImmutableMolecularMatchAst.builder() .raw(objectAst.get("raw") == null ? null : objectAst.getAsJsonPrimitive("raw").getAsString()) .value(!objectAst.has("value") ? null : objectAst.getAsJsonPrimitive("value").getAsString()) @@ -1576,18 +1582,47 @@ private static MolecularMatchAstRight createRight(@NotNull JsonObject objectRigh + EXPECTED_MOLECULARMATCH_RIGHT_SIZES); LOGGER.warn(keysRight); } - return ImmutableMolecularMatchAstRight.builder() .operator(!objectRight.has("operator") ? null : objectRight.getAsJsonPrimitive("operator").getAsString()) - .left("") - .right("") - .raw("") - .type("") - .value("") + .left(!objectRight.has("left") ? null : createRightLeft(objectRight.getAsJsonObject("left"))) + .right(!objectRight.has("right") ? null : createRightRight(objectRight.getAsJsonObject("right"))) + .raw(!objectRight.has("raw") ? null : objectRight.getAsJsonPrimitive("raw").getAsString()) + .type(objectRight.getAsJsonPrimitive("type").getAsString()) + .value(!objectRight.has("value") ? null : objectRight.getAsJsonPrimitive("value").getAsString()) .build(); } + @NotNull + private static MolecularMatchAstRightRight createRightRight(@NotNull JsonObject objectRight) { + Set keysRight = objectRight.keySet(); + if (!EXPECTED_MOLECULARMATCH_RIGHT_RIGHT_SIZES.contains(keysRight.size())) { + LOGGER.warn("Found " + keysRight.size() + " in molecular match right right rather than the expected " + + EXPECTED_MOLECULARMATCH_RIGHT_RIGHT_SIZES); + LOGGER.warn(keysRight); + } + return ImmutableMolecularMatchAstRightRight.builder() + .raw(!objectRight.has("raw") ? null : objectRight.getAsJsonPrimitive("raw").getAsString()) + .type(objectRight.getAsJsonPrimitive("type").getAsString()) + .value(!objectRight.has("value") ? null : objectRight.getAsJsonPrimitive("value").getAsString()) + .build(); + } + + @NotNull + private static MolecularMatchAstRightLeft createRightLeft(@NotNull JsonObject objectRight) { + Set keysRight = objectRight.keySet(); + if (!EXPECTED_MOLECULARMATCH_RIGHT_LEFT_SIZES.contains(keysRight.size())) { + LOGGER.warn("Found " + keysRight.size() + " in molecular match right left rather than the expected " + + EXPECTED_MOLECULARMATCH_RIGHT_LEFT_SIZES); + LOGGER.warn(keysRight); + } + return ImmutableMolecularMatchAstRightLeft.builder() + .raw(!objectRight.has("raw") ? null : objectRight.getAsJsonPrimitive("raw").getAsString()) + .type(objectRight.getAsJsonPrimitive("type").getAsString()) + .value(!objectRight.has("value") ? null : objectRight.getAsJsonPrimitive("value").getAsString()) + .build(); + } + @NotNull private static List createSource(@NotNull JsonArray arraySources) { List sourcesList = Lists.newArrayList(); @@ -1726,12 +1761,12 @@ private static List createMutations(@NotNull JsonArray .longestTranscript(!mutation.getAsJsonObject().has("longestTranscript") ? null : mutation.getAsJsonObject().getAsJsonPrimitive("longestTranscript").getAsString()) - .parents("") + .parents(createParents(mutation.getAsJsonObject().getAsJsonArray("parents"))) .wgsaData("") .wgsaMap("") .exonsInfo("") .fusionData("") - .transcriptRecognized("") + .transcriptRecognized(!mutation.getAsJsonObject().has("transcriptRecognized") ? null : mutation.getAsJsonObject().get("transcriptRecognized").getAsString()) .description(mutation.getAsJsonObject().getAsJsonPrimitive("description").getAsString()) .mutationType(jsonArrayToStringList(mutation.getAsJsonObject().getAsJsonArray("mutation_type"))) .src(mutation.getAsJsonObject().getAsJsonPrimitive("_src").getAsString()) @@ -1870,8 +1905,12 @@ private static List createTranscriptConsequ ? null : transcriptConsequence.getAsJsonObject().getAsJsonPrimitive("cdna").getAsString()) .referenceGenome(transcriptConsequence.getAsJsonObject().getAsJsonPrimitive("referenceGenome").getAsString()) - .ref(!transcriptConsequence.getAsJsonObject().has("ref") ? null : transcriptConsequence.getAsJsonObject().getAsJsonPrimitive("ref").getAsString()) - .alt(!transcriptConsequence.getAsJsonObject().has("alt") ? null : transcriptConsequence.getAsJsonObject().getAsJsonPrimitive("alt").getAsString()) + .ref(!transcriptConsequence.getAsJsonObject().has("ref") + ? null + : transcriptConsequence.getAsJsonObject().getAsJsonPrimitive("ref").getAsString()) + .alt(!transcriptConsequence.getAsJsonObject().has("alt") + ? null + : transcriptConsequence.getAsJsonObject().getAsJsonPrimitive("alt").getAsString()) .build()); } return transcriptConsequenceList; diff --git a/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/datamodel/MolecularMatchAstRight.java b/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/datamodel/MolecularMatchAstRight.java index 8645d87317..4bc2ac5a75 100644 --- a/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/datamodel/MolecularMatchAstRight.java +++ b/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/datamodel/MolecularMatchAstRight.java @@ -12,17 +12,17 @@ public abstract class MolecularMatchAstRight { public abstract String operator(); @Nullable - public abstract String right(); + public abstract MolecularMatchAstRightRight right(); @Nullable - public abstract String left(); + public abstract MolecularMatchAstRightLeft left(); - @NotNull + @Nullable public abstract String raw(); @NotNull public abstract String type(); - @NotNull + @Nullable public abstract String value(); } diff --git a/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/datamodel/MolecularMatchAstRightLeft.java b/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/datamodel/MolecularMatchAstRightLeft.java new file mode 100644 index 0000000000..0cd7e5ae66 --- /dev/null +++ b/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/datamodel/MolecularMatchAstRightLeft.java @@ -0,0 +1,18 @@ +package com.hartwig.hmftools.vicc.datamodel; + +import org.immutables.value.Value; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@Value.Immutable +@Value.Style(passAnnotations = { NotNull.class, Nullable.class }) +public abstract class MolecularMatchAstRightLeft { + @Nullable + public abstract String raw(); + + @NotNull + public abstract String type(); + + @Nullable + public abstract String value(); +} diff --git a/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/datamodel/MolecularMatchAstRightRight.java b/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/datamodel/MolecularMatchAstRightRight.java new file mode 100644 index 0000000000..fc5e75945e --- /dev/null +++ b/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/datamodel/MolecularMatchAstRightRight.java @@ -0,0 +1,18 @@ +package com.hartwig.hmftools.vicc.datamodel; + +import org.immutables.value.Value; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@Value.Immutable +@Value.Style(passAnnotations = { NotNull.class, Nullable.class }) +public abstract class MolecularMatchAstRightRight { + @Nullable + public abstract String raw(); + + @NotNull + public abstract String type(); + + @Nullable + public abstract String value(); +} diff --git a/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/datamodel/MolecularMatchMutations.java b/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/datamodel/MolecularMatchMutations.java index ec1b10d211..e96dff4cde 100644 --- a/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/datamodel/MolecularMatchMutations.java +++ b/vicc-knowledgebase-importer/src/main/java/com/hartwig/hmftools/vicc/datamodel/MolecularMatchMutations.java @@ -17,7 +17,7 @@ public abstract class MolecularMatchMutations { public abstract String longestTranscript(); @Nullable - public abstract String parents(); + public abstract List parents(); @Nullable public abstract String wgsaData();