
package uk.ac.ebi.atlas.trader.loader;

import uk.ac.ebi.atlas.experimentimport.ExperimentDTO;
import uk.ac.ebi.atlas.model.AssayGroups;
import uk.ac.ebi.atlas.model.ExperimentDesign;
import uk.ac.ebi.atlas.model.baseline.BaselineExperiment;
import uk.ac.ebi.atlas.model.baseline.BaselineExperimentBuilder;
import uk.ac.ebi.atlas.model.baseline.BaselineExperimentConfiguration;
import uk.ac.ebi.atlas.model.baseline.ExperimentalFactors;
import uk.ac.ebi.atlas.trader.ConfigurationTrader;
import uk.ac.ebi.atlas.trader.SpeciesKingdomTrader;

import javax.inject.Inject;
import javax.inject.Named;
import java.io.IOException;

@Named
public class ProteomicsBaselineExperimentsCacheLoader extends BaselineExperimentsCacheLoader {

    @Inject
    public ProteomicsBaselineExperimentsCacheLoader(ProteomicsBaselineExperimentExpressionLevelFile expressionLevelFile,
                                                       ConfigurationTrader configurationTrader, SpeciesKingdomTrader speciesKingdomTrader) {
        super(expressionLevelFile, configurationTrader, speciesKingdomTrader);
    }

    @Override
    public BaselineExperiment load(ExperimentDTO experimentDTO, String experimentDescription,
                                      boolean hasExtraInfoFile, ExperimentDesign experimentDesign) throws IOException {

        String experimentAccession = experimentDTO.getExperimentAccession();

        BaselineExperimentConfiguration factorsConfig = configurationTrader.getBaselineFactorsConfiguration(experimentAccession);

        AssayGroups assayGroups = configurationTrader.getExperimentConfiguration(experimentAccession).getAssayGroups();

        boolean hasRData = configurationTrader.getExperimentConfiguration(experimentAccession).hasRData();

        String kingdom = speciesKingdomTrader.getKingdom(experimentDTO.getSpecies());

        String[] orderedAssayGroupIds = expressionLevelFile.readOrderedAssayGroupIds(experimentAccession);

        ExperimentalFactors experimentalFactors = createExperimentalFactors(experimentAccession, experimentDesign,
                factorsConfig, assayGroups, orderedAssayGroupIds, false);

        return new BaselineExperimentBuilder().forSpecies(experimentDTO.getSpecies())
                .ofKingdom(kingdom)
                .withAccession(experimentAccession)
                .withLastUpdate(experimentDTO.getLastUpdate())
                .withDescription(experimentDescription)
                .withExtraInfo(hasExtraInfoFile)
                .withRData(hasRData)
                .withDisplayName(factorsConfig.getExperimentDisplayName())
                .withSpeciesMapping(factorsConfig.getSpeciesMapping())
                .withPubMedIds(experimentDTO.getPubmedIds())
                .withAssayGroups(assayGroups)
                .withExperimentDesign(experimentDesign)
                .withExperimentalFactors(experimentalFactors)
                .withDataProviderURL(factorsConfig.getDataProviderURL())
                .withDataProviderDescription(factorsConfig.getDataProviderDescription())
                .createProteomics();

    }
}

@@ -1854,10 +1854,481 @@
 ring
-%5B%5D
+ ensemblDB = speciesKingdomTrader.getEnsemblDB(experimentDTO.getSpecies());%0A%0A        String%5B%5D orderedAssayGroupIds;%0A        boolean orderCurated;%0A%0A        if(factorsConfig.getOrderFactor() != null && factorsConfig.getOrderFactor().equals(%22curated%22)) %7B%0A            orderCurated = true;%0A            orderedAssayGroupIds = assayGroups.getAssayGroupIds().toArray(new String%5BassayGroups.getAssayGroupIds().size()%5D);%0A        %7D else %7B%0A            orderCurated = false;%0A           
  ord
@@ -2405,32 +2405,42 @@
 imentAccession);
+%0A        %7D
 %0A%0A        Experi
@@ -2606,21 +2606,28 @@
 oupIds, 
-false
+orderCurated
 );%0A%0A    
@@ -2744,16 +2744,56 @@
 ingdom)%0A
+                .ofEnsemblDB(ensemblDB)%0A
         
@@ -3008,45 +3008,8 @@
 le)%0A
-                .withRData(hasRData)%0A
     
@@ -3444,24 +3444,24 @@
 viderURL())%0A
-
             
@@ -3533,24 +3533,61 @@
 cription())%0A
+                .withRData(hasRData)%0A
             

Copy the extra behaviour from RnaSeq to Proteomics BaselineExperimentsCacheLoader - looks like programmer errors and not intentional differences