Search in sources :

Example 31 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.

the class TwoChannelMissingValuesTest method testMissingValue.

@Test
public void testMissingValue() throws Exception {
    ExpressionExperiment old = eeService.findByShortName("GSE2221");
    if (old != null)
        eeService.remove(old);
    InputStream is = new GZIPInputStream(this.getClass().getResourceAsStream("/data/loader/expression/geo/shortGenePix/GSE2221_family.soft.gz"));
    GeoFamilyParser parser = new GeoFamilyParser();
    parser.parse(is);
    GeoSeries series = ((GeoParseResult) parser.getResults().iterator().next()).getSeriesMap().get("GSE2221");
    DatasetCombiner datasetCombiner = new DatasetCombiner();
    GeoSampleCorrespondence correspondence = datasetCombiner.findGSECorrespondence(series);
    series.setSampleCorrespondence(correspondence);
    Object result = this.gc.convert(series);
    assertNotNull(result);
    ExpressionExperiment expExp = (ExpressionExperiment) ((Collection<?>) result).iterator().next();
    expExp = persisterHelper.persist(expExp, persisterHelper.prepare(expExp));
    Collection<RawExpressionDataVector> calls = tcmv.computeMissingValues(expExp, 2.0, new ArrayList<Double>());
    assertEquals(500, calls.size());
    BioAssayDimension dim = calls.iterator().next().getBioAssayDimension();
    // Spot check the results. For sample ME-TMZ, ID #27 should be 'true' and 26 should be false.
    ByteArrayConverter bac = new ByteArrayConverter();
    boolean foundA = false;
    boolean foundB = false;
    for (DesignElementDataVector vector : calls) {
        if (vector.getDesignElement().getName().equals("26")) {
            byte[] dat = vector.getData();
            boolean[] row = bac.byteArrayToBooleans(dat);
            int i = 0;
            for (BioAssay bas : dim.getBioAssays()) {
                if (bas.getName().equals("expression array ME-TMZ")) {
                    assertTrue(!row[i]);
                    foundA = true;
                }
                i++;
            }
        }
        if (vector.getDesignElement().getName().equals("27")) {
            byte[] dat = vector.getData();
            boolean[] row = bac.byteArrayToBooleans(dat);
            int i = 0;
            for (BioAssay bas : dim.getBioAssays()) {
                if (bas.getName().equals("expression array ME-TMZ")) {
                    assertTrue(row[i]);
                    foundB = true;
                }
                i++;
            }
        }
    }
    assertTrue(foundA && foundB);
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) GeoSeries(ubic.gemma.core.loader.expression.geo.model.GeoSeries) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) GZIPInputStream(java.util.zip.GZIPInputStream) BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) Collection(java.util.Collection) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Example 32 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.

the class DifferentialExpressionAnalyzerServiceTest method setup.

@Before
public void setup() throws Exception {
    ee = expressionExperimentService.findByShortName("GSE1611");
    if (ee == null) {
        geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGeneratorLocal(this.getTestFileBasePath("gds994Short")));
        Collection<?> results = geoService.fetchAndLoad("GSE1611", false, true, false);
        ee = (ExpressionExperiment) results.iterator().next();
    }
    processedDataVectorService.createProcessedDataVectors(ee);
    ee = expressionExperimentService.findByShortName("GSE1611");
    ee = expressionExperimentService.thawLite(ee);
    differentialExpressionAnalyzerService.deleteAnalyses(ee);
    assertEquals(2, ee.getExperimentalDesign().getExperimentalFactors().size());
    for (BioAssay ba : ee.getBioAssays()) {
        BioMaterial bm = ba.getSampleUsed();
        assertEquals(bm + " " + ba, 2, bm.getFactorValues().size());
    }
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) GeoDomainObjectGeneratorLocal(ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal) Before(org.junit.Before)

Example 33 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.

the class GeoConverterTest method testConvertMultiSeriesPerSample.

/*
     * Case where the same sample can be in multiple series, we had problems with it.
     */
@Test
public void testConvertMultiSeriesPerSample() throws Exception {
    InputStream is = new GZIPInputStream(this.getClass().getResourceAsStream("/data/loader/expression/geo/GSE3193Short/GSE3193_family.soft.gz"));
    GeoFamilyParser parser = new GeoFamilyParser();
    parser.parse(is);
    GeoSeries series = ((GeoParseResult) parser.getResults().iterator().next()).getSeriesMap().get("GSE3193");
    DatasetCombiner datasetCombiner = new DatasetCombiner(false);
    GeoSampleCorrespondence correspondence = datasetCombiner.findGSECorrespondence(series);
    series.setSampleCorrespondence(correspondence);
    Object result = this.gc.convert(series);
    assertNotNull(result);
    ExpressionExperiment ee = (ExpressionExperiment) ((Collection<?>) result).iterator().next();
    // assertEquals( 85, ee.getBioAssays().size() );
    Map<ArrayDesign, Integer> ads = new HashMap<>();
    for (BioAssay b : ee.getBioAssays()) {
        if (ads.containsKey(b.getArrayDesignUsed())) {
            ads.put(b.getArrayDesignUsed(), ads.get(b.getArrayDesignUsed()) + 1);
        } else {
            ads.put(b.getArrayDesignUsed(), 1);
        }
    }
    assertEquals(4, ads.size());
    for (ArrayDesign ad : ads.keySet()) {
        Integer count = ads.get(ad);
        switch(ad.getName()) {
            case "SHAC":
                // ok
                assertEquals(8, count.intValue());
                break;
            case "SVJ":
                // ok
                assertEquals(1, count.intValue());
                break;
            case "SVL_SVM_SVN_SVO":
                assertEquals(32, count.intValue());
                break;
            case "SVC":
                assertEquals(44, count.intValue());
                break;
            default:
                fail("Name was " + ad.getName());
                break;
        }
    }
}
Also used : GeoSeries(ubic.gemma.core.loader.expression.geo.model.GeoSeries) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) GZIPInputStream(java.util.zip.GZIPInputStream) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Example 34 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.

the class ExpressionDataMatrixColumnSortTest method testOrderByExperimentalDesignB.

@Test
public void testOrderByExperimentalDesignB() {
    BioAssayDimension bad = BioAssayDimension.Factory.newInstance();
    /*
         * Five factors. Factor4 is a measurmeent.
         */
    Collection<ExperimentalFactor> factors = new HashSet<>();
    for (int i = 0; i < 5; i++) {
        ExperimentalFactor ef = ExperimentalFactor.Factory.newInstance();
        ef.setType(FactorType.CATEGORICAL);
        ef.setName("factor" + i);
        if (i == 4) {
            ef.setName("mfact" + i);
        }
        ef.setId((long) i);
        for (int j = 0; j < 3; j++) {
            FactorValue fv = FactorValue.Factory.newInstance();
            fv.setValue("fv" + (j + 1) * (i + 1));
            fv.setId((long) (j + 1) * (i + 1));
            fv.setExperimentalFactor(ef);
            ef.getFactorValues().add(fv);
            if (j == 2 && i != 4) {
                fv.setValue("control_group");
            }
            if (i == 4) {
                ef.setType(FactorType.CONTINUOUS);
                Measurement m = Measurement.Factory.newInstance();
                m.setId((long) j * (i + 1));
                m.setValue(j + ".00");
                m.setRepresentation(PrimitiveType.DOUBLE);
                fv.setMeasurement(m);
            }
        }
        factors.add(ef);
    }
    Random random = new Random();
    for (int i = 0; i < 100; i++) {
        BioAssay ba = BioAssay.Factory.newInstance();
        ba.setName("ba" + i);
        ba.setId((long) i);
        bad.getBioAssays().add(ba);
        BioMaterial bm = BioMaterial.Factory.newInstance();
        bm.setId((long) i);
        bm.setName("bm" + i);
        ba.setSampleUsed(bm);
        for (ExperimentalFactor ef : factors) {
            /*
                 * Note: if we use 4, then some of the biomaterials will not have a factorvalue for each factor. This is
                 * realistic. Use 3 to fill it in completely.
                 */
            int k = random.nextInt(4);
            int m = 0;
            FactorValue toUse = null;
            for (FactorValue fv : ef.getFactorValues()) {
                if (m == k) {
                    toUse = fv;
                    break;
                }
                m++;
            }
            if (toUse != null)
                bm.getFactorValues().add(toUse);
        // log.info( ba + " -> " + bm + " -> " + ef + " -> " + toUse );
        }
    }
    EmptyExpressionMatrix mat = new EmptyExpressionMatrix(bad);
    assertEquals(100, mat.columns());
    List<BioMaterial> ordered = ExpressionDataMatrixColumnSort.orderByExperimentalDesign(mat);
    assertEquals(100, ordered.size());
// for ( BioMaterial bioMaterial : ordered ) {
// log.info( bioMaterial + " .... " + StringUtils.join( bioMaterial.getFactorValues(), "  --- " ) );
// }
}
Also used : Measurement(ubic.gemma.model.common.measurement.Measurement) BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) Random(java.util.Random) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) HashSet(java.util.HashSet) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Example 35 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.

the class ExpressionDataDoubleMatrixUtil method subtractMatrices.

/**
 * Subtract two matrices. Ideally, they matrices are conformant, but if they are not (as some rows are sometimes
 * missing for some quantitation types), this method attempts to handle it anyway (see below). The rows and columns
 * do not have to be in the same order, but they do have to have the same column keys and row keys (with the
 * exception of missing rows). The result is stored in a. (a - b).
 * If the number of rows are not the same, and/or the rows have different keys in the two matrices, some rows will
 * simply not get subtracted and a warning will be issued.
 *
 * @param a matrix a
 * @param b matrix b
 * @throws IllegalArgumentException if the matrices are not column-conformant.
 */
public static void subtractMatrices(ExpressionDataDoubleMatrix a, ExpressionDataDoubleMatrix b) {
    // checkConformant( a, b );
    if (a.columns() != b.columns())
        throw new IllegalArgumentException("Unequal column counts: " + a.columns() + " != " + b.columns());
    int columns = a.columns();
    for (ExpressionDataMatrixRowElement el : a.getRowElements()) {
        int rowNum = el.getIndex();
        CompositeSequence del = el.getDesignElement();
        if (b.getRow(del) == null) {
            ExpressionDataDoubleMatrixUtil.log.warn("Matrix 'b' is missing a row for " + del + ", it will not be subtracted");
            continue;
        }
        for (int i = 0; i < columns; i++) {
            BioAssay assay = a.getBioAssaysForColumn(i).iterator().next();
            double valA = a.get(del, assay);
            double valB = b.get(del, assay);
            a.set(rowNum, i, valA - valB);
        }
    }
}
Also used : CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Aggregations

BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)144 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)67 Test (org.junit.Test)29 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)29 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)24 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)20 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)18 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)16 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)15 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)14 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)14 InputStream (java.io.InputStream)11 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)10 HashSet (java.util.HashSet)9 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)8 DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)8 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)7