/*
 * The Gemma project
 * 
 * Copyright (c) 2007 University of British Columbia
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package ubic.gemma.analysis.preprocess;

import java.util.Collection;

import ubic.gemma.loader.expression.geo.GeoDomainObjectGeneratorLocal;
import ubic.gemma.loader.expression.geo.service.GeoDatasetService;
import ubic.gemma.loader.util.AlreadyExistsInSystemException;
import ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector;
import ubic.gemma.model.expression.experiment.ExpressionExperiment;
import ubic.gemma.model.expression.experiment.ExpressionExperimentService;
import ubic.gemma.testing.AbstractGeoServiceTest;

/**
 * @author pavlidis
 * @version $Id$
 */
public class ProcessedExpressionDataCreateServiceTest extends AbstractGeoServiceTest {
    ExpressionExperimentService eeService;
    GeoDatasetService geoService;
    ExpressionExperiment ee = null;

    protected void onSetUpInTransaction() throws Exception {
        super.onSetUpInTransaction();
        eeService = ( ExpressionExperimentService ) this.getBean( "expressionExperimentService" );
        init();
    }

    protected void onTearDownAfterTransaction() throws Exception {
        super.onTearDownAfterTransaction();
        if ( ee != null ) eeService.delete( ee );
    }

    @SuppressWarnings("unchecked")
    public void testComputeDevRankForExpressionExperimentB() throws Exception {
        endTransaction();
        ProcessedExpressionDataVectorCreateService serv = ( ProcessedExpressionDataVectorCreateService ) this
                .getBean( "processedExpressionDataVectorCreateService" );

        String path = getTestFileBasePath();

        try {
            geoService.setGeoDomainObjectGenerator( new GeoDomainObjectGeneratorLocal( path + GEO_TEST_DATA_ROOT
                    + "gse432Short" ) );
            Collection<ExpressionExperiment> results = geoService.fetchAndLoad( "GSE432", false, true, false, false,
                    false );
            this.ee = results.iterator().next();
        } catch ( AlreadyExistsInSystemException e ) {
            this.ee = ( ExpressionExperiment ) e.getData();
            eeService.thaw( ee );
            eeService.delete( ee );
            this.testComputeDevRankForExpressionExperimentB(); // a little risky, could get stuck...
        }

        eeService.thawLite( ee );
        Collection<ProcessedExpressionDataVector> preferredVectors = serv.computeProcessedExpressionData( ee );

        for ( ProcessedExpressionDataVector d : preferredVectors ) {
            assertTrue( d.getQuantitationType().getIsMaskedPreferred() );
            assertNotNull( d.getRankByMean() );
            assertNotNull( d.getRankByMax() );
        }
    }

    @Override
    protected void init() {
        geoService = ( GeoDatasetService ) this.getBean( "geoDatasetService" );

    }

}

@@ -2347,15 +2347,16 @@
  + %22
-gse432S
+GSE5949s
 hort
@@ -2450,11 +2450,12 @@
 %22GSE
-432
+5949
 %22, f

fix test