Skip to content

Commit

Permalink
Merge pull request #638 from TheJacksonLaboratory/move-html-and-tsv-t…
Browse files Browse the repository at this point in the history
…o-lirical-io

Move the HTML and TSV writers into the I/O module
  • Loading branch information
ielis authored Nov 29, 2023
2 parents ce2b446 + 2b301aa commit 27d210f
Show file tree
Hide file tree
Showing 27 changed files with 67 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import org.monarchinitiative.lirical.core.output.AnalysisResultWriterFactory;
import org.monarchinitiative.lirical.core.output.AnalysisResultsWriter;
import org.monarchinitiative.lirical.core.output.OutputFormat;
import org.monarchinitiative.lirical.core.output.TemplateBasedAnalysisResultsWriter;
import org.monarchinitiative.lirical.io.output.JsonAnalysisResultWriter;
import org.monarchinitiative.lirical.io.output.TemplateBasedAnalysisResultsWriter;
import org.monarchinitiative.phenol.annotations.formats.hpo.HpoDiseases;
import org.monarchinitiative.phenol.ontology.data.Ontology;

Expand Down
4 changes: 0 additions & 4 deletions lirical-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>

<dependency>
<groupId>org.monarchinitiative.phenol</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.monarchinitiative.lirical.core.likelihoodratio;

import org.monarchinitiative.phenol.ontology.data.Ontology;
import org.monarchinitiative.phenol.ontology.data.MinimalOntology;
import org.monarchinitiative.phenol.ontology.data.Term;
import org.monarchinitiative.phenol.ontology.data.TermId;

public class LrWithExplanationFactory {

private final Ontology ontology;
private final MinimalOntology ontology;

public LrWithExplanationFactory(Ontology ontology) {
public LrWithExplanationFactory(MinimalOntology ontology) {
this.ontology = ontology;
}

Expand All @@ -20,8 +21,8 @@ public LrWithExplanation create(TermId queryTerm, TermId matchingTerm, LrMatchTy
}

private String getExplanation(TermId queryTerm, TermId matchingTerm, LrMatchType matchType, double lr) {
String queryTermLabel = String.format("%s[%s]", ontology.getTermMap().get(queryTerm).getName(), queryTerm.getValue());
String matchTermLabel = String.format("%s[%s]", ontology.getTermMap().get(matchingTerm).getName(), matchingTerm.getValue());
String queryTermLabel = String.format("%s[%s]", ontology.termForTermId(queryTerm).map(Term::getName).orElse("UNKNOWN"), queryTerm.getValue());
String matchTermLabel = String.format("%s[%s]", ontology.termForTermId(matchingTerm).map(Term::getName).orElse("UNKNOWN"), matchingTerm.getValue());
double log10LR = Math.log10(lr);
return switch (matchType) {
case EXACT_MATCH -> String.format("E:%s[%.3f]", queryTermLabel, log10LR);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Classes for creating HTML or TSV output files for LIRICAL.
* Base data model for writing out the results of LIRICAL analysis.
*/
package org.monarchinitiative.lirical.core.output;
4 changes: 4 additions & 0 deletions lirical-io/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.monarchinitiative.lirical.core.output;
package org.monarchinitiative.lirical.io.output;

import org.monarchinitiative.lirical.core.likelihoodratio.GenotypeLrWithExplanation;
import org.monarchinitiative.lirical.core.analysis.TestResult;
import org.monarchinitiative.lirical.core.likelihoodratio.GenotypeLrWithExplanation;
import org.monarchinitiative.phenol.annotations.formats.GeneIdentifier;
import org.monarchinitiative.phenol.ontology.data.TermId;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.monarchinitiative.lirical.core.output;
package org.monarchinitiative.lirical.io.output;

import org.monarchinitiative.lirical.core.analysis.TestResult;
import org.monarchinitiative.phenol.ontology.data.TermId;


import java.util.List;
import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.monarchinitiative.lirical.core.output;
package org.monarchinitiative.lirical.io.output;

import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.monarchinitiative.lirical.core.analysis.AnalysisData;
import org.monarchinitiative.lirical.core.analysis.AnalysisResults;
import org.monarchinitiative.lirical.core.likelihoodratio.GenotypeLrWithExplanation;
import org.monarchinitiative.lirical.core.model.Gene2Genotype;
import org.monarchinitiative.lirical.core.output.svg.Lr2Svg;
import org.monarchinitiative.lirical.core.output.*;
import org.monarchinitiative.lirical.io.output.svg.Lr2Svg;
import org.monarchinitiative.phenol.annotations.formats.GeneIdentifier;
import org.monarchinitiative.phenol.annotations.formats.hpo.HpoDisease;
import org.monarchinitiative.phenol.annotations.formats.hpo.HpoDiseases;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.monarchinitiative.lirical.core.output;
package org.monarchinitiative.lirical.io.output;

import java.text.DecimalFormat;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.monarchinitiative.lirical.core.output;
package org.monarchinitiative.lirical.io.output;

import freemarker.template.Configuration;
import freemarker.template.Version;
import org.monarchinitiative.lirical.core.analysis.AnalysisData;
import org.monarchinitiative.lirical.core.exception.LiricalRuntimeException;
import org.monarchinitiative.lirical.core.model.Gene2Genotype;
import org.monarchinitiative.lirical.core.model.LiricalVariant;
import org.monarchinitiative.lirical.core.output.AnalysisResultsMetadata;
import org.monarchinitiative.lirical.core.output.OutputOptions;
import org.monarchinitiative.phenol.ontology.data.Ontology;
import org.monarchinitiative.phenol.ontology.data.Term;
import org.monarchinitiative.phenol.ontology.data.TermId;
Expand Down Expand Up @@ -120,7 +122,7 @@ protected static void mkdirIfNotExist(Path dir) {
}

protected Function<LiricalVariant, VisualizableVariant> toVisualizableVariant() {
return lv -> new VisualizableVariantDefault(analysisData.sampleId(), lv, isPassingPathogenicThreshold(lv));
return lv -> VisualizableVariant.of(analysisData.sampleId(), lv, isPassingPathogenicThreshold(lv));
}

private boolean isPassingPathogenicThreshold(LiricalVariant lv) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.monarchinitiative.lirical.core.output;
package org.monarchinitiative.lirical.io.output;


import org.monarchinitiative.lirical.core.output.svg.Sparkline2Svg;
import org.monarchinitiative.lirical.core.analysis.AnalysisResults;
import org.monarchinitiative.lirical.core.likelihoodratio.GenotypeLrWithExplanation;
import org.monarchinitiative.lirical.core.analysis.TestResult;
import org.monarchinitiative.lirical.core.likelihoodratio.GenotypeLrWithExplanation;
import org.monarchinitiative.lirical.io.output.svg.Sparkline2Svg;
import org.monarchinitiative.phenol.annotations.formats.GeneIdentifier;
import org.monarchinitiative.phenol.annotations.formats.hpo.HpoDisease;
import org.monarchinitiative.phenol.annotations.formats.hpo.HpoDiseases;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.monarchinitiative.lirical.core.output;
package org.monarchinitiative.lirical.io.output;

import org.monarchinitiative.lirical.core.analysis.AnalysisData;
import org.monarchinitiative.lirical.core.analysis.AnalysisResults;
import org.monarchinitiative.lirical.core.output.AnalysisResultsMetadata;
import org.monarchinitiative.lirical.core.output.AnalysisResultsWriter;
import org.monarchinitiative.lirical.core.output.OutputFormat;
import org.monarchinitiative.lirical.core.output.OutputOptions;
import org.monarchinitiative.phenol.annotations.formats.hpo.HpoDiseases;
import org.monarchinitiative.phenol.ontology.data.Ontology;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.monarchinitiative.lirical.core.output;
package org.monarchinitiative.lirical.io.output;

import org.monarchinitiative.lirical.core.analysis.TestResult;
import org.monarchinitiative.lirical.core.model.TranscriptAnnotation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.monarchinitiative.lirical.core.output;
package org.monarchinitiative.lirical.io.output;

import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.monarchinitiative.lirical.core.analysis.AnalysisData;
import org.monarchinitiative.lirical.core.analysis.AnalysisResults;
import org.monarchinitiative.lirical.core.likelihoodratio.GenotypeLrWithExplanation;
import org.monarchinitiative.lirical.core.output.AnalysisResultsMetadata;
import org.monarchinitiative.lirical.core.output.OutputOptions;
import org.monarchinitiative.phenol.annotations.formats.hpo.HpoDisease;
import org.monarchinitiative.phenol.annotations.formats.hpo.HpoDiseases;
import org.monarchinitiative.phenol.ontology.data.Ontology;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.monarchinitiative.lirical.core.output;
package org.monarchinitiative.lirical.io.output;

import org.monarchinitiative.lirical.core.model.LiricalVariant;
import org.monarchinitiative.lirical.core.model.TranscriptAnnotation;

import java.util.List;
Expand All @@ -10,6 +11,10 @@
public interface VisualizableVariant {
// Note: the interface MUST be public, otherwise FreeMarker will not work.

static VisualizableVariant of(String sampleId, LiricalVariant lv, boolean isPassingPathogenicityThreshold) {
return new VisualizableVariantDefault(sampleId, lv, isPassingPathogenicityThreshold);
}

String contigName();

int pos();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.monarchinitiative.lirical.core.output;
package org.monarchinitiative.lirical.io.output;

import org.monarchinitiative.lirical.core.model.*;
import org.monarchinitiative.svart.CoordinateSystem;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Classes for writing out LIRICAL analysis results into HTML, TSV, and JSON files.
*/
package org.monarchinitiative.lirical.io.output;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.monarchinitiative.lirical.core.output.svg;
package org.monarchinitiative.lirical.io.output.svg;

import java.io.IOException;
import java.io.Writer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.monarchinitiative.lirical.core.output.svg;
package org.monarchinitiative.lirical.io.output.svg;


import org.monarchinitiative.lirical.core.likelihoodratio.GenotypeLrWithExplanation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.monarchinitiative.lirical.core.output.svg;
package org.monarchinitiative.lirical.io.output.svg;

import org.monarchinitiative.lirical.core.analysis.AnalysisResults;
import org.monarchinitiative.phenol.annotations.formats.hpo.HpoDisease;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.monarchinitiative.lirical.core.output.svg;
package org.monarchinitiative.lirical.io.output.svg;

import org.monarchinitiative.lirical.core.analysis.AnalysisResults;
import org.monarchinitiative.lirical.core.likelihoodratio.GenotypeLrWithExplanation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** Classes to create an SVG graphic representing the result of likelihood raio analysis of one HPO Case.
* @author <a href="mailto:[email protected]">Peter Robinson</a>
*/
package org.monarchinitiative.lirical.core.output.svg;
package org.monarchinitiative.lirical.io.output.svg;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.monarchinitiative.lirical.core.output;
package org.monarchinitiative.lirical.io.output;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.List;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.monarchinitiative.lirical.core.output.svg;
package org.monarchinitiative.lirical.io.output.svg;


import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.monarchinitiative.lirical.core.TestResources;
import org.mockito.Mockito;
import org.monarchinitiative.lirical.core.analysis.AnalysisResults;
import org.monarchinitiative.lirical.core.analysis.TestResult;
import org.monarchinitiative.lirical.core.likelihoodratio.LrMatchType;
Expand All @@ -12,12 +12,16 @@
import org.monarchinitiative.phenol.annotations.formats.hpo.HpoDisease;
import org.monarchinitiative.phenol.annotations.formats.hpo.HpoDiseaseAnnotation;
import org.monarchinitiative.phenol.annotations.formats.hpo.HpoDiseases;
import org.monarchinitiative.phenol.ontology.data.MinimalOntology;
import org.monarchinitiative.phenol.ontology.data.Term;
import org.monarchinitiative.phenol.ontology.data.TermId;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.when;


public class Posttest2SvgTest {
Expand All @@ -27,13 +31,20 @@ public class Posttest2SvgTest {
private static List<HpoDisease> DISEASES;
private static AnalysisResults RESULTS;

public static MinimalOntology HPO;

@BeforeAll
public static void setup() throws NullPointerException {
TermId some = TermId.of("HP:0000006");

HPO = Mockito.mock(MinimalOntology.class);
when(HPO.termForTermId(some)).thenReturn(Optional.of(Term.of(some, "Some term")));

double PRETEST_PROB = 0.001;
FACTORY = new LrWithExplanationFactory(TestResources.hpo());
FACTORY = new LrWithExplanationFactory(HPO);
List<TestResult> results = new ArrayList<>();
//result 1
TermId some = TermId.of("HP:0000006");

List<LrWithExplanation> reslist = createTestList(some, 1d, 10d, 100d);
List<LrWithExplanation> excluded = List.of();
List<HpoDiseaseAnnotation> annotations = List.of();
Expand Down

0 comments on commit 27d210f

Please sign in to comment.