Skip to content

Commit

Permalink
Read count model simulation and viewer for lphy #56
Browse files Browse the repository at this point in the history
  • Loading branch information
zjzxiaohei committed Jun 20, 2024
1 parent ba32d75 commit 74a757a
Show file tree
Hide file tree
Showing 21 changed files with 190 additions and 261 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
version = "0.0.1-SNAPSHOT"//-SNAPSHOT"

dependencies {
implementation(project(":popsizefunc-lphy"))
implementation(project(":phylonco-lphy"))

api("io.github.linguaphylo:lphy-studio:1.5.1-SNAPSHOT") //-SNAPSHOT

Expand Down Expand Up @@ -51,7 +51,7 @@ tasks.jar {
// shared attr in the root build
attributes(
"Main-Class" to maincls,
"Implementation-Title" to "Pop-size function",
"Implementation-Title" to "Phylonco Lphy Studio",
"Implementation-Vendor" to developers,
)
}
Expand All @@ -63,7 +63,7 @@ publishing {
create<MavenPublication>(project.name) {
artifactId = project.base.archivesName.get()
pom {
description.set("The LPhy extension including pop-size functions.")
description.set("The LPhy Studio extension.")
developers {
developer {
name.set(developers)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import readcountmodel.lphystudio.viewer.ReadCountModelViewer;

module popsizefunc.lphy.studio {

requires transitive popsizefunc.lphy;
requires transitive lphystudio;
requires phylonco.lphy;

// Viewer SPI
uses lphystudio.app.graphicalmodelpanel.viewer.Viewer;
// declare what service interface the provider intends to use
provides lphystudio.app.graphicalmodelpanel.viewer.Viewer with popsizefunc.lphystudio.viewer.PopSizeFuncViewer;
provides lphystudio.app.graphicalmodelpanel.viewer.Viewer with ReadCountModelViewer;

// Note: to adapt with the system not using Java module but using class path,
// they need to be declared inside META-INF/services/lphystudio.app.graphicalmodelpanel.viewer.Viewer as well.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package readcountmodel.lphystudio.viewer;

import javax.swing.*;

public class ReadCountModelComponent extends JComponent {

//TODO check AlignmentComponent

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package readcountmodel.lphystudio.viewer;

import lphy.base.evolution.coalescent.PopulationFunction;
import lphy.core.model.Value;
import lphystudio.app.graphicalmodelpanel.viewer.Viewer;
import phylonco.lphy.evolution.readcountmodel.ReadCountData;
import phylonco.lphy.evolution.readcountmodel.ReadCountModel;

import javax.swing.*;

public class ReadCountModelViewer implements Viewer{
public ReadCountModelViewer(){}

@Override
public boolean match(Object value) {
return value instanceof ReadCountData ||
(value instanceof Value && ((Value) value).value() instanceof ReadCountData);

}

@Override
public JComponent getViewer(Object value) {
if (match(value)) {
return new JTextArea(value.toString());
}
String text = ((Value<ReadCountData>) value).value().toString();
return new JTextArea(text);
}

@Override
public String toString() { return "Read Count Viewer"; }
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
# META-INF/services must be under src for Intellij
# Class requires a public no-args constructor

popsizefunc.lphystudio.spi.PopSizeFuncViewerImpl
# popsizefunc.lphystudio.spi.PopSizeFuncViewerImpl
readcountmodel.lphystudio.viewer.ReadCountModelViewer
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
# but extensions need to declare what service interface the provider intends to use for new Viewers.
# for example, lphystudio.app.graphicalmodelpanel.viewer.???Viewer

popsizefunc.lphystudio.viewer.PopSizeFuncViewer
# popsizefunc.lphystudio.viewer.PopSizeFuncViewer
readcountmodel.lphystudio.viewer.ReadCountModelViewer
16 changes: 8 additions & 8 deletions phylonco-lphy/examples/gt16ReadCountModel.lphy
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ l = 5;
rates ~ Dirichlet(conc=[1.0, 2.0, 1.0, 1.0, 2.0, 1.0]);
Q = gt16(freq=π, rates=rates); // construct the GT16 instantaneous rate matrix
A ~ PhyloCTMC(L=l, Q=Q, tree=ψ, dataType=phasedGenotype());
epsilon ~ Beta(alpha=2, beta=18);
delta ~ Beta(alpha=1.5, beta=4.5);
//epsilon = 0.01;
//delta = 0.24;
//epsilon ~ Beta(alpha=2, beta=18);
//delta ~ Beta(alpha=1.5, beta=4.5);
epsilon = 0.01;
delta = 0.24;
// cov = [rep(1, 5), rep(2, 5), rep(3, 5), rep(4, 5)];
meanT = 2.3; // average coverage = lognormal(meanT, sdT)
sdT = 0.1;
Expand All @@ -20,9 +20,9 @@ meanS = 0.04; // cell-specific scaling
sdS = 0.001;
t ~ LogNormal(meanlog= meanT, sdlog= sdT);
v ~ LogNormal(meanlog= meanV, sdlog= sdV);
s ~ LogNormal(meanlog= meanS, sdlog= sdS,repe);
alpha ~ AlphaSimulator(l= l, n=n, delta= delta);
coverage ~ CoverageSimulator(alpha= alpha, t= t, v= v, s= s);
s ~ LogNormal(meanlog= meanS, sdlog= sdS, replicates=n);
alpha ~ Ploidy(l= l, n= n, delta= delta);
cov ~ CoverageModel(alpha= alpha, t= t, v= v, s= s);


r ~ ReadCountModel(D=A, epsilon=epsilon, alpha=alpha, coverage=coverage);
r ~ ReadCountModel(D=A, epsilon=epsilon, alpha=alpha, coverage=cov);
1 change: 1 addition & 0 deletions phylonco-lphy/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module phylonco.lphy {
requires transitive lphy.core;
requires transitive lphy.base;
requires jdk.jfr;

exports phylonco.lphy.evolution.alignment;
exports phylonco.lphy.evolution.datatype;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package phylonco.lphy.evolution.readcountmodel;

import lphy.base.distribution.NegativeBinomial;
import lphy.base.evolution.alignment.Alignment;
import lphy.core.model.GenerativeDistribution;
import lphy.core.model.RandomVariable;
import lphy.core.model.Value;
import lphy.core.model.annotation.GeneratorInfo;
import lphy.core.model.annotation.ParameterInfo;

import java.util.Map;

public class CoverageSimulator implements GenerativeDistribution<Integer[][]> {
public class CoverageModel implements GenerativeDistribution<Integer[][]> {
private NegativeBinomial negativeBinomial;
private Value<Integer[][]> alpha;
private Value<Integer> t;
private Value<Integer> v;
private Value<Integer[]> s;
private Value<Double> t;
private Value<Double> v;
private Value<Double[]> s;
private RandomVariable<Integer[][]> coverage;


Expand All @@ -26,11 +26,11 @@ public class CoverageSimulator implements GenerativeDistribution<Integer[][]> {
public static final String sParamName = "s";


public CoverageSimulator(
public CoverageModel(
@ParameterInfo(name = alphaParamName, description = "alpha, allelic dropout events for each cell at each site.") Value<Integer[][]> alpha,
@ParameterInfo(name = tParamName, description = "t") Value<Integer> t,
@ParameterInfo(name = vParamName, description = "v") Value<Integer> v,
@ParameterInfo(name = sParamName, description = "s") Value<Integer[]> s
@ParameterInfo(name = tParamName, description = "t, mean of allelic coverage.") Value<Double> t,
@ParameterInfo(name = vParamName, description = "v, variance of allelic coverage.") Value<Double> v,
@ParameterInfo(name = sParamName, description = "s, size factor of cell.") Value<Double[]> s

) {
super();
Expand All @@ -42,6 +42,10 @@ public CoverageSimulator(

}


@GeneratorInfo(
name = "CoverageModel",
description = "")
@Override
public RandomVariable<Integer[][]> sample(){
int n = alpha.value().length;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
package phylonco.lphy.evolution.readcountmodel;

import lphy.base.distribution.Multinomial;
import lphy.core.model.GenerativeDistribution;
import lphy.core.model.RandomVariable;
import lphy.core.model.Value;
import lphy.core.model.annotation.GeneratorInfo;
import lphy.core.model.annotation.ParameterInfo;

import java.util.Map;

public class AlphaSimulator implements GenerativeDistribution<Integer[][]> {
public class PloidyModel implements GenerativeDistribution<Integer[][]> {
private Value<Integer> l;
private Value<Integer> n;
private Value<Double> delta;

private RandomVariable<Integer[][]> alpha;



public static final String lParamName = "l";
public static final String nParamName = "n";
public static final String deltaParamName = "delta";




private AlphaSimulator(
@ParameterInfo(name = lParamName, description = "the length of sequencing") Value<Integer> l,
public PloidyModel(
@ParameterInfo(name = lParamName, description = "the length of sequencing.") Value<Integer> l,
@ParameterInfo(name = nParamName, description = "the number of cells.") Value<Integer> n,
@ParameterInfo(name = deltaParamName, description = "allelic dropout error probability.") Value<Double> delta

Expand All @@ -34,9 +31,12 @@ private AlphaSimulator(
this.n = n;
this.delta = delta;

}

@GeneratorInfo(
name = "Ploidy",
description = "Observed ploidy after allelic dropout.")

}

@Override
public RandomVariable<Integer[][]> sample() {
Expand All @@ -46,9 +46,9 @@ public RandomVariable<Integer[][]> sample() {
Value<Integer> numberA = new Value<>("numberA", 1);
multinomialAlpha = new Multinomial(numberA, proA);

Integer[][] alp = new Integer[n.value()][l.value()];
for (int i = 0; i < n.value(); i++) {
for (int j = 0; j < l.value(); j++) {
Integer[][] alp = new Integer[this.n.value()][this.l.value()];
for (int i = 0; i < this.n.value(); i++) {
for (int j = 0; j < this.l.value(); j++) {
Value<Integer[]> alpha1 = multinomialAlpha.sample();
if (alpha1.value()[0] == 1) {
alp[i][j] = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ public int getDimension() {

@Override
public String toString() {
String result = "";
String result = "\n";
int n = getTaxa().getDimension();;
int l = nchar();
for (int i = 0; i < n; i++) {
// n taxa
for (int j = 0; j < l; j++) {
// n sites
int countA = readCountDataMatrix[i][j].getCount("A");
int countC = readCountDataMatrix[i][j].getCount("C");
int countG = readCountDataMatrix[i][j].getCount("G");
int countT = readCountDataMatrix[i][j].getCount("T");
result += String.format("A: %d, C: %d, G: %d, T: %d; \t", countA, countC, countG, countT);
}
result += "\n";
}
return result;
}
Expand Down
Loading

0 comments on commit 74a757a

Please sign in to comment.