diff --git a/biodata-models/src/main/java/org/opencb/biodata/models/clinical/interpretation/Software.java b/biodata-models/src/main/java/org/opencb/biodata/models/clinical/interpretation/Software.java index 9fb51d4d6..419ddfad9 100644 --- a/biodata-models/src/main/java/org/opencb/biodata/models/clinical/interpretation/Software.java +++ b/biodata-models/src/main/java/org/opencb/biodata/models/clinical/interpretation/Software.java @@ -22,6 +22,7 @@ import org.opencb.biodata.models.constants.FieldConstants; import org.opencb.commons.annotations.DataField; +import java.util.HashMap; import java.util.Map; public class Software { @@ -51,15 +52,7 @@ public class Software { private Map params; public Software() { - } - - @Deprecated - public Software(String name, String version, String commit, String website, Map params) { - this.name = name; - this.version = version; - this.commit = commit; - this.website = website; - this.params = params; + this("", "", "", "", "", new HashMap<>()); } public Software(String name, String version, String repository, String commit, String website, Map params) { diff --git a/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/InferredSex.java b/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/InferredSex.java new file mode 100644 index 000000000..c74e7a55b --- /dev/null +++ b/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/InferredSex.java @@ -0,0 +1,145 @@ +/* + * + * + */ + +package org.opencb.biodata.models.clinical.qc; + +import org.opencb.biodata.models.clinical.interpretation.Software; +import org.opencb.biodata.models.common.Image; +import org.opencb.biodata.models.constants.FieldConstants; +import org.opencb.commons.annotations.DataField; +import org.opencb.commons.datastore.core.ObjectMap; + +import java.util.ArrayList; +import java.util.List; + +public class InferredSex { + + @DataField(id = "method", description = FieldConstants.INFERRED_SEX_METHOD_DESCRIPTION) + private String method; + + @DataField(id = "sampleId", description = FieldConstants.INFERRED_SEX_SAMPLE_DESCRIPTION) + private String sampleId; + + @DataField(id = "software", description = FieldConstants.INFERRED_SEX_SOFTWARE_DESCRIPTION) + private Software software; + + @DataField(id = "inferredKaryotypicSex", description = FieldConstants.INFERRED_SEX_INFERRED_KARYOTYPIC_SEX_DESCRIPTION) + private String inferredKaryotypicSex; + + @DataField(id = "values", description = FieldConstants.INFERRED_SEX_VALUES_DESCRIPTION) + private ObjectMap values; + + @DataField(id = "images", description = FieldConstants.INFERRED_SEX_IMAGES_DESCRIPTION) + private List images; + + @DataField(id = "attributes", description = FieldConstants.INFERRED_SEX_ATTRIBUTES_DESCRIPTION) + private ObjectMap attributes; + + public InferredSex() { + this("","", new Software(), "", new ObjectMap(), new ArrayList<>(), new ObjectMap()); + } + + public InferredSex(String method, String sampleId, Software software, String inferredKaryotypicSex, ObjectMap values, + List images, ObjectMap attributes) { + this.method = method; + this.sampleId = sampleId; + this.software = software; + this.inferredKaryotypicSex = inferredKaryotypicSex; + this.values = values; + this.images = images; + this.attributes = attributes; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("InferredSex{"); + sb.append("method='").append(method).append('\''); + sb.append(", sampleId='").append(sampleId).append('\''); + sb.append(", software=").append(software); + sb.append(", inferredKaryotypicSex='").append(inferredKaryotypicSex).append('\''); + sb.append(", values=").append(values); + sb.append(", images=").append(images); + sb.append(", attributes=").append(attributes); + sb.append('}'); + return sb.toString(); + } + + public String getMethod() { + return method; + } + + public InferredSex setMethod(String method) { + this.method = method; + return this; + } + + public String getSampleId() { + return sampleId; + } + + public InferredSex setSampleId(String sampleId) { + this.sampleId = sampleId; + return this; + } + + public Software getSoftware() { + return software; + } + + public InferredSex setSoftware(Software software) { + this.software = software; + return this; + } + + public String getInferredKaryotypicSex() { + return inferredKaryotypicSex; + } + + public InferredSex setInferredKaryotypicSex(String inferredKaryotypicSex) { + this.inferredKaryotypicSex = inferredKaryotypicSex; + return this; + } + + public ObjectMap getValues() { + return values; + } + + public InferredSex setValues(ObjectMap values) { + this.values = values; + return this; + } + + public List getImages() { + return images; + } + + public InferredSex setImages(List images) { + this.images = images; + return this; + } + + public ObjectMap getAttributes() { + return attributes; + } + + public InferredSex setAttributes(ObjectMap attributes) { + this.attributes = attributes; + return this; + } +} diff --git a/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/InferredSexReport.java b/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/InferredSexReport.java deleted file mode 100644 index a00c3ca74..000000000 --- a/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/InferredSexReport.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * - * - */ - -package org.opencb.biodata.models.clinical.qc; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -public class InferredSexReport { - - private String method; - private String sampleId; - private String inferredKaryotypicSex; - private Map values; - private List files; - - public InferredSexReport() { - this("","CoverageRatio", "", new LinkedHashMap<>(), new ArrayList<>()); - } - - public InferredSexReport(String sampleId,String method, String inferredKaryotypicSex, Map values, List files) { - this.sampleId = sampleId; - this.method = method; - this.inferredKaryotypicSex = inferredKaryotypicSex; - this.values = values; - this.files = files; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("InferredSexReport{"); - sb.append("method='").append(method).append('\''); - sb.append(", sampleId='").append(sampleId).append('\''); - sb.append(", inferredKaryotypicSex='").append(inferredKaryotypicSex).append('\''); - sb.append(", values=").append(values); - sb.append(", files=").append(files); - sb.append('}'); - return sb.toString(); - } - - public String getMethod() { - return method; - } - - public InferredSexReport setMethod(String method) { - this.method = method; - return this; - } - - public String getInferredKaryotypicSex() { - return inferredKaryotypicSex; - } - - public InferredSexReport setInferredKaryotypicSex(String inferredKaryotypicSex) { - this.inferredKaryotypicSex = inferredKaryotypicSex; - return this; - } - - public Map getValues() { - return values; - } - - public InferredSexReport setValues(Map values) { - this.values = values; - return this; - } - - public List getFiles() { - return files; - } - - public InferredSexReport setFiles(List files) { - this.files = files; - return this; - } - - public String getSampleId() { - return sampleId; - } - - public InferredSexReport setSampleId(String sampleId) { - this.sampleId = sampleId; - return this; - } -} diff --git a/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/MendelianErrorReport.java b/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/MendelianError.java similarity index 72% rename from biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/MendelianErrorReport.java rename to biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/MendelianError.java index 904af3c96..0ede4d64f 100644 --- a/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/MendelianErrorReport.java +++ b/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/MendelianError.java @@ -19,6 +19,11 @@ package org.opencb.biodata.models.clinical.qc; +import org.opencb.biodata.models.common.Image; +import org.opencb.biodata.models.constants.FieldConstants; +import org.opencb.commons.annotations.DataField; +import org.opencb.commons.datastore.core.ObjectMap; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -27,13 +32,21 @@ // M E N D E L I A N E R R O R S R E P O R T //------------------------------------------------------------------------- -public class MendelianErrorReport { +public class MendelianError { - // Number total of errors for that family + @DataField(id = "numErrors", description = FieldConstants.MENDELIAN_ERROR_NUM_ERRORS_DESCRIPTION) private int numErrors; + @DataField(id = "sampleAggregation", description = FieldConstants.MENDELIAN_ERROR_SAMPLE_AGGREGATION_DESCRIPTION) private List sampleAggregation; + @DataField(id = "images", description = FieldConstants.MENDELIAN_ERROR_IMAGES_DESCRIPTION) + private List images; + + @DataField(id = "attributes", description = FieldConstants.MENDELIAN_ERROR_ATTRIBUTES_DESCRIPTION) + private ObjectMap attributes; + + //------------------------------------------------------------------------- // S A M P L E A G G R E G A T I O N //------------------------------------------------------------------------- @@ -153,21 +166,33 @@ public ChromosomeAggregation setErrorCodeAggregation(Map errorC } } - public MendelianErrorReport() { - this.numErrors = 0; - this.sampleAggregation = new ArrayList<>(); + public MendelianError() { + this(0, new ArrayList<>(), new ArrayList<>(), new ObjectMap()); } - public MendelianErrorReport(int numErrors, List sampleAggregation) { + public MendelianError(int numErrors, List sampleAggregation, List images, ObjectMap attributes) { this.numErrors = numErrors; this.sampleAggregation = sampleAggregation; + this.images = images; + this.attributes = attributes; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("MendelianError{"); + sb.append("numErrors=").append(numErrors); + sb.append(", sampleAggregation=").append(sampleAggregation); + sb.append(", images=").append(images); + sb.append(", attributes=").append(attributes); + sb.append('}'); + return sb.toString(); } public int getNumErrors() { return numErrors; } - public MendelianErrorReport setNumErrors(int numErrors) { + public MendelianError setNumErrors(int numErrors) { this.numErrors = numErrors; return this; } @@ -176,8 +201,26 @@ public List getSampleAggregation() { return sampleAggregation; } - public MendelianErrorReport setSampleAggregation(List sampleAggregation) { + public MendelianError setSampleAggregation(List sampleAggregation) { this.sampleAggregation = sampleAggregation; return this; } + + public List getImages() { + return images; + } + + public MendelianError setImages(List images) { + this.images = images; + return this; + } + + public ObjectMap getAttributes() { + return attributes; + } + + public MendelianError setAttributes(ObjectMap attributes) { + this.attributes = attributes; + return this; + } } diff --git a/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/Relatedness.java b/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/Relatedness.java new file mode 100644 index 000000000..307364f00 --- /dev/null +++ b/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/Relatedness.java @@ -0,0 +1,116 @@ +/* + * + * + */ + +package org.opencb.biodata.models.clinical.qc; + +import org.opencb.biodata.models.clinical.interpretation.Software; +import org.opencb.biodata.models.common.Image; +import org.opencb.biodata.models.constants.FieldConstants; +import org.opencb.commons.annotations.DataField; +import org.opencb.commons.datastore.core.ObjectMap; + +import java.util.ArrayList; +import java.util.List; + +public class Relatedness { + + @DataField(id = "method", description = FieldConstants.RELATEDNESS_METHOD_DESCRIPTION) + private String method; + + @DataField(id = "software", description = FieldConstants.RELATEDNESS_SOFTWARE_DESCRIPTION) + private Software software; + + @DataField(id = "scores", uncommentedClasses = {"RelatednessScore"}, description = FieldConstants.RELATEDNESS_SCORES_DESCRIPTION) + private List scores; + + @DataField(id = "images", description = FieldConstants.RELATEDNESS_IMAGES_DESCRIPTION) + private List images; + + @DataField(id = "attributes", description = FieldConstants.RELATEDNESS_ATTRIBUTES_DESCRIPTION) + private ObjectMap attributes; + + public Relatedness() { + this("", new Software(), new ArrayList<>(), new ArrayList<>(), new ObjectMap()); + } + + public Relatedness(String method, Software software, List scores, List images, ObjectMap attributes) { + this.method = method; + this.software = software; + this.scores = scores; + this.images = images; + this.attributes = attributes; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("Relatedness{"); + sb.append("method='").append(method).append('\''); + sb.append(", software=").append(software); + sb.append(", scores=").append(scores); + sb.append(", images=").append(images); + sb.append(", attributes=").append(attributes); + sb.append('}'); + return sb.toString(); + } + + public String getMethod() { + return method; + } + + public Relatedness setMethod(String method) { + this.method = method; + return this; + } + + public Software getSoftware() { + return software; + } + + public Relatedness setSoftware(Software software) { + this.software = software; + return this; + } + + public List getScores() { + return scores; + } + + public Relatedness setScores(List scores) { + this.scores = scores; + return this; + } + + public List getImages() { + return images; + } + + public Relatedness setImages(List images) { + this.images = images; + return this; + } + + public ObjectMap getAttributes() { + return attributes; + } + + public Relatedness setAttributes(ObjectMap attributes) { + this.attributes = attributes; + return this; + } +} diff --git a/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/RelatednessReport.java b/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/RelatednessReport.java deleted file mode 100644 index 404546c34..000000000 --- a/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/RelatednessReport.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * - * - */ - -package org.opencb.biodata.models.clinical.qc; - -import org.opencb.biodata.models.constants.FieldConstants; -import org.opencb.commons.annotations.DataField; - -import java.util.ArrayList; -import java.util.List; - -public class RelatednessReport { - - // Method., e.g.: Plink/IBD - @DataField(id = "method", - description = FieldConstants.RELATEDNESS_REPORT_METHOD_DESCRIPTION) - private String method; - - // Minor allele frequency to filter variants, e.g.: 1000G:EUR>0.35, cohort:ALL>0.05") - @DataField(id = "maf", - description = FieldConstants.RELATEDNESS_REPORT_MAF_DESCRIPTION) - private String maf; - - // Relatedness scores for pair of samples - @DataField(id = "scores", uncommentedClasses = {"RelatednessScore"}, - description = FieldConstants.RELATEDNESS_REPORT_SCORES_DESCRIPTION) - private List scores; - - @DataField(id = "files", - description = FieldConstants.RELATEDNESS_REPORT_FILES_DESCRIPTION) - private List files; - - public RelatednessReport() { - this("PLINK/IBD", "cohort:ALL>0.05", new ArrayList<>(), new ArrayList<>()); - } - - public RelatednessReport(String method, String maf, List scores, List files) { - this.method = method; - this.maf = maf; - this.scores = scores; - this.files = files; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("RelatednessReport{"); - sb.append("method='").append(method).append('\''); - sb.append(", maf='").append(maf).append('\''); - sb.append(", scores=").append(scores); - sb.append(", files=").append(files); - sb.append('}'); - return sb.toString(); - } - - public String getMethod() { - return method; - } - - public RelatednessReport setMethod(String method) { - this.method = method; - return this; - } - - public String getMaf() { - return maf; - } - - public RelatednessReport setMaf(String maf) { - this.maf = maf; - return this; - } - - public List getScores() { - return scores; - } - - public RelatednessReport setScores(List scores) { - this.scores = scores; - return this; - } - - public List getFiles() { - return files; - } - - public RelatednessReport setFiles(List files) { - this.files = files; - return this; - } -} diff --git a/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/RelatednessScore.java b/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/RelatednessScore.java index 6658f43be..9db540453 100644 --- a/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/RelatednessScore.java +++ b/biodata-models/src/main/java/org/opencb/biodata/models/clinical/qc/RelatednessScore.java @@ -1,9 +1,9 @@ package org.opencb.biodata.models.clinical.qc; -import java.util.LinkedHashMap; -import java.util.Map; +import org.opencb.commons.datastore.core.ObjectMap; public class RelatednessScore { + // Pair of samples private String sampleId1; private String sampleId2; @@ -18,19 +18,14 @@ public class RelatednessScore { private String validation; // Scores depending on the relatedness method - private Map values; + private ObjectMap values; public RelatednessScore() { - this("", "", "", "", "", new LinkedHashMap<>()); - } - - @Deprecated - public RelatednessScore(String sampleId1, String sampleId2, String inferredRelationship, Map values) { - this(sampleId1, sampleId2, "", inferredRelationship, "", values); + this("", "", "", "", "", new ObjectMap()); } public RelatednessScore(String sampleId1, String sampleId2, String reportedRelationship, String inferredRelationship, String validation, - Map values) { + ObjectMap values) { this.sampleId1 = sampleId1; this.sampleId2 = sampleId2; this.reportedRelationship = reportedRelationship; @@ -97,11 +92,11 @@ public RelatednessScore setValidation(String validation) { return this; } - public Map getValues() { + public ObjectMap getValues() { return values; } - public RelatednessScore setValues(Map values) { + public RelatednessScore setValues(ObjectMap values) { this.values = values; return this; } diff --git a/biodata-models/src/main/java/org/opencb/biodata/models/common/Image.java b/biodata-models/src/main/java/org/opencb/biodata/models/common/Image.java index ffaf28252..95f310f53 100644 --- a/biodata-models/src/main/java/org/opencb/biodata/models/common/Image.java +++ b/biodata-models/src/main/java/org/opencb/biodata/models/common/Image.java @@ -26,6 +26,7 @@ public class Image { private String description; public Image() { + this("", "", ""); } public Image(String name, String base64, String description) { diff --git a/biodata-models/src/main/java/org/opencb/biodata/models/constants/FieldConstants.java b/biodata-models/src/main/java/org/opencb/biodata/models/constants/FieldConstants.java index 4171448f5..00bfd8d9d 100644 --- a/biodata-models/src/main/java/org/opencb/biodata/models/constants/FieldConstants.java +++ b/biodata-models/src/main/java/org/opencb/biodata/models/constants/FieldConstants.java @@ -50,14 +50,31 @@ public class FieldConstants { public static final String CLINICAL_COMMENT_MESSAGE_DESCRIPTION = "Clinical comment message"; public static final String CLINICAL_COMMENT_TAGS_DESCRIPTION = "List of tags for the clinical comment"; public static final String CLINICAL_COMMENT_DATE_DESCRIPTION = "Date of the clinical comment"; - public static final String RELATEDNESS_REPORT_METHOD_DESCRIPTION = "Method of the relatedness report"; public static final String CLINICAL_CONFIDENCE_AUTHOR_DESCRIPTION = "Clinical confidence author"; public static final String CLINICAL_CONFIDENCE_DATE_DESCRIPTION = "Date of the clinical confidence"; public static final String CLINICAL_CONFIDENCE_VALUE_DESCRIPTION = "Date of the clinical confidence"; - public static final String RELATEDNESS_REPORT_MAF_DESCRIPTION = "Minor allele frequency to filter variants, e.g.: 1kg_phase3:CEU>0.35, cohort:ALL>0.05"; - public static final String RELATEDNESS_REPORT_SCORES_DESCRIPTION = "Relatedness scores for pair of samples"; - public static final String RELATEDNESS_REPORT_FILES_DESCRIPTION = "List of files of Relatedness Report"; + // Relatedness + public static final String RELATEDNESS_METHOD_DESCRIPTION = "Method of the relatedness analysis"; + public static final String RELATEDNESS_SOFTWARE_DESCRIPTION = "Software based-on to perform the relatedness analysis"; + public static final String RELATEDNESS_SCORES_DESCRIPTION = "Relatedness scores for pairs of samples"; + public static final String RELATEDNESS_IMAGES_DESCRIPTION = "List of images related to the relatedness analysis"; + public static final String RELATEDNESS_ATTRIBUTES_DESCRIPTION = "Relatedness attributes, e.g.: query, cli, files,..."; + + // Inferred sex + public static final String INFERRED_SEX_METHOD_DESCRIPTION = "Method of the inferred sex analysis"; + public static final String INFERRED_SEX_SAMPLE_DESCRIPTION = "Sample ID"; + public static final String INFERRED_SEX_SOFTWARE_DESCRIPTION = "Software based-on to perform the inferred sex analysis"; + public static final String INFERRED_SEX_INFERRED_KARYOTYPIC_SEX_DESCRIPTION = "Inferred karyotypic sex"; + public static final String INFERRED_SEX_VALUES_DESCRIPTION = "Inferred sex values"; + public static final String INFERRED_SEX_IMAGES_DESCRIPTION = "List of images related to the inferred sex analysis"; + public static final String INFERRED_SEX_ATTRIBUTES_DESCRIPTION = "Inferred sex attributes, e.g.: query, cli, files,..."; + + // Inferred sex + public static final String MENDELIAN_ERROR_NUM_ERRORS_DESCRIPTION = "Total number of errors"; + public static final String MENDELIAN_ERROR_SAMPLE_AGGREGATION_DESCRIPTION = "Number of errors per sample (i.e., error aggregation)"; + public static final String MENDELIAN_ERROR_IMAGES_DESCRIPTION = "List of images related to the mendelian error analysis"; + public static final String MENDELIAN_ERROR_ATTRIBUTES_DESCRIPTION = "Mendelian error attributes, e.g.: query, cli, files,..."; public static final String CLINICAL_ANALYST_ROLE_DESCRIPTION = "Analyst role"; public static final String CLINICAL_ANALYST_ATTRIBUTES_DESCRIPTION = "Analyst attributes"; diff --git a/biodata-models/src/test/java/org/opencb/biodata/models/clinical/qc/RelatednessTest.java b/biodata-models/src/test/java/org/opencb/biodata/models/clinical/qc/RelatednessTest.java new file mode 100644 index 000000000..25d480587 --- /dev/null +++ b/biodata-models/src/test/java/org/opencb/biodata/models/clinical/qc/RelatednessTest.java @@ -0,0 +1,43 @@ +package org.opencb.biodata.models.clinical.qc; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Assert; +import org.junit.Test; +import org.opencb.biodata.models.common.Image; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.HashMap; + +public class RelatednessTest { + + @Test + public void writeModel() throws IOException { + Relatedness relatedness = new Relatedness(); + relatedness.setScores(Collections.singletonList(new RelatednessScore())); + relatedness.setImages(Collections.singletonList(new Image())); + ObjectMapper objectMapper = new ObjectMapper(); + + File file = Paths.get("/tmp/relatedness.json").toFile(); + objectMapper.writerFor(Relatedness.class).writeValue(file, relatedness); + Assert.assertTrue(file.exists()); + + InferredSex inferredSex = new InferredSex(); + inferredSex.setImages(Collections.singletonList(new Image())); + file = Paths.get("/tmp/inferredSex.json").toFile(); + objectMapper.writerFor(InferredSex.class).writeValue(file, inferredSex); + Assert.assertTrue(file.exists()); + + MendelianError mendelianError = new MendelianError(); + mendelianError.setSampleAggregation(Collections.singletonList( + new MendelianError.SampleAggregation().setSample("").setChromAggregation(Collections.singletonList( + new MendelianError.SampleAggregation.ChromosomeAggregation().setChromosome("").setErrorCodeAggregation( + new HashMap<>()))))); + mendelianError.setImages(Collections.singletonList(new Image())); + file = Paths.get("/tmp/mendelianError.json").toFile(); + objectMapper.writerFor(MendelianError.class).writeValue(file, mendelianError); + Assert.assertTrue(file.exists()); + } +} \ No newline at end of file