DataUpdater { ExpressionExperiment addData( ExpressionExperiment ee, ArrayDesign targetPlatform, ExpressionDataDoubleMatrix data ) { if ( data.rows() == 0 ) { throw new IllegalArgumentException( "Data had no rows" ); } Collection<QuantitationType> qts = data.getQuantitationTypes(); if ( qts.size() > 1 ) { throw new IllegalArgumentException( "Only support a single quantitation type" ); } if ( qts.isEmpty() ) { throw new IllegalArgumentException( "Please supply a quantitation type with the data" ); } QuantitationType qt = qts.iterator().next(); if ( qt.getIsPreferred() ) { for ( QuantitationType existingQt : ee.getQuantitationTypes() ) { if ( existingQt.getIsPreferred() ) { if ( this.rawExpressionDataVectorService.findRawAndProcessed( existingQt ).size() > 0 ) { throw new IllegalArgumentException( "You cannot add 'preferred' data to an experiment that already has it. " + "You should first delete the existing data or make it non-preferred." ); } } } } Collection<RawExpressionDataVector> vectors = this.makeNewVectors( ee, targetPlatform, data, qt ); if ( vectors.isEmpty() ) { throw new IllegalStateException( "no vectors!" ); } ee = experimentService.addRawVectors( ee, vectors ); this.audit( ee, "Data vectors added for " + targetPlatform + ", " + qt, false ); experimentService.update( ee ); if ( qt.getIsPreferred() ) { DataUpdater.log.info( "Postprocessing preferred data" ); ee = this.postprocess( ee ); assert ee.getNumberOfDataVectors() != null; } return ee; }  void addAffyDataFromAPTOutput( ExpressionExperiment ee, String pathToAptOutputFile ); void addCountData( ExpressionExperiment ee, ArrayDesign targetArrayDesign,
            DoubleMatrix<String, String> countMatrix, DoubleMatrix<String, String> rpkmMatrix, Integer readLength,
            Boolean isPairedReads, boolean allowMissingSamples ); void log2cpmFromCounts( ExpressionExperiment ee, QuantitationType qt ); @SuppressWarnings("UnusedReturnValue") // Possible external use ExpressionExperiment replaceData( ExpressionExperiment ee, ArrayDesign targetPlatform, QuantitationType qt,
            DoubleMatrix<String, String> data ); void reprocessAffyDataFromCel( ExpressionExperiment ee );  }
@Test public void testAddData() throws Exception { geoService.setGeoDomainObjectGenerator( new GeoDomainObjectGeneratorLocal( this.getTestFileBasePath() ) ); ExpressionExperiment ee; try { Thread.sleep( 1000 ); } catch ( InterruptedException ex ) { Thread.currentThread().interrupt(); } try { Collection<?> results = geoService.fetchAndLoad( "GSE37646", false, true, false ); ee = ( ExpressionExperiment ) results.iterator().next(); } catch ( AlreadyExistsInSystemException e ) { ee = ( ExpressionExperiment ) ( ( List<?> ) e.getData() ).get( 0 ); } ee = experimentService.thawLite( ee ); List<BioAssay> bioAssays = new ArrayList<>( ee.getBioAssays() ); assertEquals( 31, bioAssays.size() ); List<BioMaterial> bms = new ArrayList<>(); for ( BioAssay ba : bioAssays ) { bms.add( ba.getSampleUsed() ); } targetArrayDesign = this.getTestPersistentArrayDesign( 100, true ); DoubleMatrix<CompositeSequence, BioMaterial> rawMatrix = new DenseDoubleMatrix<>( targetArrayDesign.getCompositeSequences().size(), bms.size() ); for ( int i = 0; i < rawMatrix.rows(); i++ ) { for ( int j = 0; j < rawMatrix.columns(); j++ ) { rawMatrix.set( i, j, ( i + 1 ) * ( j + 1 ) * Math.random() / 100.0 ); } } List<CompositeSequence> probes = new ArrayList<>( targetArrayDesign.getCompositeSequences() ); rawMatrix.setRowNames( probes ); rawMatrix.setColumnNames( bms ); QuantitationType qt = this.makeQt( true ); ExpressionDataDoubleMatrix data = new ExpressionDataDoubleMatrix( ee, qt, rawMatrix ); assertNotNull( data.getBestBioAssayDimension() ); assertEquals( rawMatrix.columns(), data.getBestBioAssayDimension().getBioAssays().size() ); assertEquals( probes.size(), data.getMatrix().rows() ); ee = dataUpdater.replaceData( ee, targetArrayDesign, data ); for ( BioAssay ba : ee.getBioAssays() ) { assertEquals( targetArrayDesign, ba.getArrayDesignUsed() ); } ee = experimentService.thaw( ee ); for ( BioAssay ba : ee.getBioAssays() ) { assertEquals( targetArrayDesign, ba.getArrayDesignUsed() ); } assertEquals( 100, ee.getRawExpressionDataVectors().size() ); for ( RawExpressionDataVector v : ee.getRawExpressionDataVectors() ) { assertTrue( v.getQuantitationType().getIsPreferred() ); } assertEquals( 100, ee.getProcessedExpressionDataVectors().size() ); Collection<DoubleVectorValueObject> processedDataArrays = dataVectorService.getProcessedDataArrays( ee ); for ( DoubleVectorValueObject v : processedDataArrays ) { assertEquals( 31, v.getBioAssays().size() ); } qt = this.makeQt( false ); ExpressionDataDoubleMatrix moreData = new ExpressionDataDoubleMatrix( ee, qt, rawMatrix ); ee = dataUpdater.addData( ee, targetArrayDesign, moreData ); ee = experimentService.thaw( ee ); try { dataUpdater.addData( ee, targetArrayDesign, data ); fail( "Should have gotten an exception" ); } catch ( IllegalArgumentException e ) { } dataUpdater.deleteData( ee, qt ); }