Search in sources :

Example 71 with DoubleMatrix2D

use of cern.colt.matrix.DoubleMatrix2D in project Gemma by PavlidisLab.

the class ComBatTest method test3NoCovariate.

/*
     * Case where we only have batch, no other covariates
     *
     */
@Test
public void test3NoCovariate() throws Exception {
    DoubleMatrixReader f = new DoubleMatrixReader();
    DoubleMatrix<String, String> testMatrix = f.read(this.getClass().getResourceAsStream("/data/analysis/preprocess/batcheffects/example.madata.small.txt"));
    StringMatrixReader of = new StringMatrixReader();
    StringMatrix<String, String> sampleInfo = of.read(this.getClass().getResourceAsStream("/data/analysis/preprocess/batcheffects/example.metadata.nocov.small.txt"));
    @SuppressWarnings({ "unchecked", "rawtypes" }) ComBat<String, String> comBat = new ComBat(testMatrix, sampleInfo);
    DoubleMatrix2D X = comBat.getDesignMatrix();
    assertEquals(1, X.get(0, 0), 0.001);
    assertEquals(0, X.get(3, 0), 0.001);
    DoubleMatrix2D y = new DenseDoubleMatrix2D(testMatrix.asArray());
    DoubleMatrix2D sdata = comBat.standardize(y, X);
    assertEquals(-0.57397393, sdata.get(17, 1), 0.0001);
    assertEquals(1.10827459, sdata.get(8, 2), 0.001);
    assertEquals(0.45359207, sdata.get(0, 8), 0.001);
    assertEquals(0.15470664, sdata.get(3, 7), 0.001);
    DoubleMatrix2D finalResult = comBat.run();
    assertEquals(10.678412, finalResult.get(7, 0), 0.0001);
    assertEquals(11.677158, finalResult.get(7, 7), 0.0001);
    assertEquals(6.735682, finalResult.get(10, 7), 0.0001);
// log.info( finalResult );
// X08.1 X54.1 X36.1 X23.1 X17.1 X40.1 X45.1 X55.1 X11.1
// 1553129_at 3.862883 3.666102 3.891911 3.968716 3.920277 3.854683 3.879281 3.837050 3.858994
// 213447_at 6.233228 5.393208 5.601587 6.008113 6.456638 6.170673 5.312780 4.707229 6.568215
// 242039_at 8.164096 8.502608 7.550607 7.146657 7.549429 7.914666 8.128463 8.437540 7.919430
// 223394_at 7.785804 8.172181 8.258501 8.286628 7.847273 8.259993 8.611244 8.164748 7.386591
// 227758_at 3.816278 3.475673 3.642967 3.670807 3.694009 3.641609 3.641609 3.633687 3.958491
// 207696_at 3.580712 3.527869 3.565008 3.518815 3.510254 3.589519 3.624747 3.666631 3.601962
// 241107_at 6.256698 5.922966 5.679003 5.749597 6.179683 5.589234 5.529333 5.900868 6.405107
// 228980_at 10.678412 11.107177 10.773365 10.974208 10.592659 11.793201 10.935671 11.677158 10.572522
// 204452_s_at 6.021874 5.366750 5.931940 6.337327 5.712018 5.260514 5.650047 5.355390 5.562588
// 1562443_at 4.609301 3.964679 4.663442 4.516068 4.818594 4.140485 4.232574 4.084472 4.684495
// 232018_at 6.226565 6.878310 6.097034 5.956156 5.989567 6.497420 6.929095 6.735682 5.721358
// 1561877_at 3.789971 3.749341 3.728529 3.867675 4.058129 3.659954 3.473056 3.856079 3.879270
// 221183_at 6.790431 5.543900 6.253127 6.541754 6.737387 5.703031 6.065498 5.210347 7.035212
// 206162_x_at 5.294347 5.257304 5.090348 4.979353 5.118390 5.544392 5.553653 5.884388 5.542866
// 214502_at 4.047479 3.865124 3.805045 3.963706 3.906569 4.478499 3.972879 4.154100 3.752158
// 234099_at 7.596681 6.861572 7.109911 6.946028 7.208003 6.455995 6.641884 6.761660 7.703987
// 237400_at 4.437312 5.820944 5.026344 4.825555 5.319276 5.731938 4.582957 4.979099 4.860988
// 240254_at 4.106446 3.903017 4.238474 4.121097 4.000663 6.213980 4.057623 3.815918 4.484964
// 209053_s_at 5.979671 6.378071 6.241459 6.440983 5.946471 6.685171 6.452771 6.374475 5.986512
}
Also used : StringMatrixReader(ubic.basecode.io.reader.StringMatrixReader) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) DoubleMatrixReader(ubic.basecode.io.reader.DoubleMatrixReader) Test(org.junit.Test)

Example 72 with DoubleMatrix2D

use of cern.colt.matrix.DoubleMatrix2D in project Gemma by PavlidisLab.

the class ComBatTest method test1.

@Test
public void test1() throws Exception {
    DoubleMatrixReader f = new DoubleMatrixReader();
    DoubleMatrix<String, String> testMatrix = f.read(this.getClass().getResourceAsStream("/data/analysis/preprocess/batcheffects/example.madata.small.txt"));
    StringMatrixReader of = new StringMatrixReader();
    StringMatrix<String, String> sampleInfo = of.read(this.getClass().getResourceAsStream("/data/analysis/preprocess/batcheffects/example.metadata.small.txt"));
    @SuppressWarnings({ "unchecked", "rawtypes" }) ComBat<String, String> comBat = new ComBat(testMatrix, sampleInfo);
    DoubleMatrix2D X = comBat.getDesignMatrix();
    assertEquals(1, X.get(0, 0), 0.001);
    assertEquals(0, X.get(3, 0), 0.001);
    assertEquals(1, X.get(4, 2), 0.001);
    DoubleMatrix2D y = new DenseDoubleMatrix2D(testMatrix.asArray());
    DoubleMatrix2D sdata = comBat.standardize(y, X);
    assertEquals(-0.25074, sdata.get(17, 1), 0.0001);
    assertEquals(0.54122, sdata.get(8, 2), 0.001);
    assertEquals(0.22358, sdata.get(0, 8), 0.001);
    assertEquals(0.25211, sdata.get(3, 7), 0.001);
    DoubleMatrix2D finalResult = comBat.run();
    assertEquals(10.67558, finalResult.get(7, 0), 0.0001);
    assertEquals(11.68505, finalResult.get(7, 7), 0.0001);
    assertEquals(6.769583, finalResult.get(10, 7), 0.0001);
}
Also used : StringMatrixReader(ubic.basecode.io.reader.StringMatrixReader) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) DoubleMatrixReader(ubic.basecode.io.reader.DoubleMatrixReader) Test(org.junit.Test)

Example 73 with DoubleMatrix2D

use of cern.colt.matrix.DoubleMatrix2D in project Gemma by PavlidisLab.

the class ExpressionExperimentQCController method visualizeMeanVariance.

/**
 * @param id   of experiment
 * @param size Multiplier on the cell size. 1 or null for standard small size.
 * @param text if true, output a tabbed file instead of a png
 * @param os   response output stream
 * @return ModelAndView object if text is true, otherwise null
 */
@RequestMapping("/expressionExperiment/visualizeMeanVariance.html")
public ModelAndView visualizeMeanVariance(Long id, Double size, Boolean text, OutputStream os) throws Exception {
    if (id == null) {
        log.warn("No id!");
        return null;
    }
    ExpressionExperiment ee = expressionExperimentService.load(id);
    if (ee == null) {
        log.warn("Could not load experiment with id " + id);
        return null;
    }
    MeanVarianceRelation mvr = meanVarianceService.find(ee);
    if (mvr == null) {
        return null;
    }
    if (text != null && text) {
        final ByteArrayConverter bac = new ByteArrayConverter();
        double[] means = bac.byteArrayToDoubles(mvr.getMeans());
        double[] variances = bac.byteArrayToDoubles(mvr.getVariances());
        DoubleMatrix2D matrix = new DenseDoubleMatrix2D(means.length, 2);
        matrix.viewColumn(0).assign(means);
        matrix.viewColumn(1).assign(variances);
        String matrixString = new Formatter("%1.2G").toTitleString(matrix, null, new String[] { "mean", "variance" }, null, null, null, null);
        ModelAndView mav = new ModelAndView(new TextView());
        mav.addObject(TextView.TEXT_PARAM, matrixString);
        return mav;
    }
    this.writeMeanVariance(os, mvr, size);
    return null;
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) Formatter(cern.colt.matrix.doublealgo.Formatter) ModelAndView(org.springframework.web.servlet.ModelAndView) MeanVarianceRelation(ubic.gemma.model.expression.bioAssayData.MeanVarianceRelation) TextView(ubic.gemma.web.view.TextView) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 74 with DoubleMatrix2D

use of cern.colt.matrix.DoubleMatrix2D in project tdq-studio-se by Talend.

the class Formatter method demo4.

/**
 * Demonstrates how to use this class.
 */
public static void demo4() {
    // parameters
    double[][] values = { { 3, 0, -3.4, 0 }, { 5.1, 0, +3.0123456789, 0 }, { 16.37, 0.0, 2.5, 0 }, { -16.3, 0, -3.012345678E-4, -1 }, { 1236.3456789, 0, 7, -1.2 } };
    /*
double[][] values = {
	{3,     1,      },
	{5.1   ,16.37,  }
};
*/
    // String[] columnNames = { "he",   "",  "he", "four" };
    // String[] rowNames = { "hello", "du", null, "abcdef", "five" };
    String[] columnNames = { "0.1", "0.3", "0.5", "0.7" };
    String[] rowNames = { "SunJDK1.2.2 classic", "IBMJDK1.1.8", "SunJDK1.3 Hotspot", "other1", "other2" };
    // String[] columnNames = { "0.1", "0.3" };
    // String[] rowNames = { "SunJDK1.2.2 classic", "IBMJDK1.1.8"};
    DoubleMatrix2D matrix = cern.colt.matrix.DoubleFactory2D.dense.make(values);
    System.out.println("\n\n" + new Formatter("%G").toTitleString(matrix, rowNames, columnNames, "rowAxis", "colAxis", "VM Performance: Provider vs. matrix density"));
}
Also used : DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) AbstractFormatter(cern.colt.matrix.impl.AbstractFormatter)

Example 75 with DoubleMatrix2D

use of cern.colt.matrix.DoubleMatrix2D in project tdq-studio-se by Talend.

the class Formatter method demo3.

/**
 * Demonstrates how to use this class.
 */
public static void demo3(int size, double value) {
    cern.colt.Timer timer = new cern.colt.Timer();
    String s;
    StringBuffer buf;
    DoubleMatrix2D matrix = cern.colt.matrix.DoubleFactory2D.dense.make(size, size, value);
    timer.reset().start();
    buf = new StringBuffer();
    for (int i = size; --i >= 0; ) {
        for (int j = size; --j >= 0; ) {
            buf.append(matrix.getQuick(i, j));
        }
    }
    buf = null;
    timer.stop().display();
    timer.reset().start();
    cern.colt.matrix.impl.Former format = new cern.colt.matrix.impl.FormerFactory().create("%G");
    buf = new StringBuffer();
    for (int i = size; --i >= 0; ) {
        for (int j = size; --j >= 0; ) {
            buf.append(format.form(matrix.getQuick(i, j)));
        }
    }
    buf = null;
    timer.stop().display();
    timer.reset().start();
    s = new Formatter(null).toString(matrix);
    // System.out.println(s);
    s = null;
    timer.stop().display();
    timer.reset().start();
    s = new Formatter("%G").toString(matrix);
    // System.out.println(s);
    s = null;
    timer.stop().display();
}
Also used : DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) AbstractFormatter(cern.colt.matrix.impl.AbstractFormatter) Former(cern.colt.matrix.impl.Former)

Aggregations

DoubleMatrix2D (cern.colt.matrix.DoubleMatrix2D)136 DenseDoubleMatrix2D (cern.colt.matrix.impl.DenseDoubleMatrix2D)38 DoubleMatrix1D (cern.colt.matrix.DoubleMatrix1D)36 Algebra (cern.colt.matrix.linalg.Algebra)16 DoubleFactory2D (cern.colt.matrix.DoubleFactory2D)13 DenseDoubleMatrix1D (cern.colt.matrix.impl.DenseDoubleMatrix1D)13 Node (edu.cmu.tetrad.graph.Node)11 Graph (edu.cmu.tetrad.graph.Graph)8 Test (org.junit.Test)6 DoubleMatrixReader (ubic.basecode.io.reader.DoubleMatrixReader)6 StringMatrixReader (ubic.basecode.io.reader.StringMatrixReader)6 DataSet (edu.cmu.tetrad.data.DataSet)5 DoubleArrayList (cern.colt.list.DoubleArrayList)4 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)4 DenseDoubleMatrix (ubic.basecode.dataStructure.matrix.DenseDoubleMatrix)4 AbstractFormatter (cern.colt.matrix.impl.AbstractFormatter)3 Endpoint (edu.cmu.tetrad.graph.Endpoint)3 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)3 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)3 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)3