Changeset 374


Ignore:
Timestamp:
Aug 8, 2007, 12:22:46 PM (14 years ago)
Author:
dominic
Message:
 
Location:
trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/AnnotationTypeCvImporter.java

    r362 r374  
    3434import net.sf.basedb.util.parser.FlatFileParser;
    3535import net.sf.basedb.util.parser.Mapper;
    36 import uk.ac.ebi.nugo.plugins.util.Values;
     36import net.sf.basedb.util.Values;
    3737
    3838
     
    419419  private ItemResultList<AnnotationTypeCategory> categories;
    420420  private ItemQuery<AnnotationTypeCategory> categoryQuery;
    421   private boolean updateExisting, enumeration,found;
     421  private boolean updateExisting, enumeration;
    422422  private String separator;
    423423  private int numInserted;
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/Tab2MageImporter.java

    r362 r374  
    88import java.io.IOException;
    99import java.io.InputStream;
    10 import java.net.InetAddress;
    1110import java.util.ArrayList;
    1211import java.util.Arrays;
    13 import java.util.Calendar;
    1412import java.util.Collections;
    15 import java.util.Date;
    1613import java.util.List;
    1714import java.util.Set;
     
    1916import java.util.zip.ZipInputStream;
    2017
    21 import uk.ac.ebi.nugo.plugins.tab2mageimport.io.AnnotationTypesWriter;
    22 import uk.ac.ebi.nugo.plugins.tab2mageimport.io.Tab2MageDataImportFactory;
    23 import uk.ac.ebi.nugo.plugins.tab2mageimport.io.Tab2MageExperimentWriter;
    24 import uk.ac.ebi.nugo.plugins.tab2mageimport.io.Tab2MageWriterFactory;
    25 import uk.ac.ebi.nugo.plugins.tab2mageimport.validation.Tab2MageValidationFactory;
    26 import uk.ac.ebi.nugo.plugins.tidy.RollBack;
    27 import uk.ac.ebi.nugo.plugins.util.NutribasePluginException;
    28 import uk.ac.ebi.nugo.plugins.util.Tab2MageHelper;
    29 import uk.ac.ebi.nugo.plugins.util.ZipUnpacker;
     18import org.apache.log4j.Logger;
    3019
    3120import net.sf.basedb.core.BaseException;
    32 import net.sf.basedb.core.BooleanParameterType;
    33 import net.sf.basedb.core.DateParameterType;
    3421import net.sf.basedb.core.DbControl;
    3522import net.sf.basedb.core.Directory;
     
    3926import net.sf.basedb.core.Item;
    4027import net.sf.basedb.core.ItemParameterType;
    41 import net.sf.basedb.core.Path;
    42 import net.sf.basedb.core.PathParameterType;
    4328import net.sf.basedb.core.PluginParameter;
    4429import net.sf.basedb.core.ProgressReporter;
    45 import net.sf.basedb.core.RawBioAssay;
    4630import net.sf.basedb.core.RawDataType;
    4731import net.sf.basedb.core.RequestInformation;
    48 import net.sf.basedb.core.SessionControl;
    4932import net.sf.basedb.core.StringParameterType;
    5033import net.sf.basedb.core.User;
     
    5841import net.sf.basedb.core.plugin.Request;
    5942import net.sf.basedb.core.plugin.Response;
     43import uk.ac.ebi.nugo.plugins.tab2mageimport.io.AnnotationTypesWriter;
     44import uk.ac.ebi.nugo.plugins.tab2mageimport.io.Tab2MageDataImportFactory;
     45import uk.ac.ebi.nugo.plugins.tab2mageimport.io.Tab2MageExperimentWriter;
     46import uk.ac.ebi.nugo.plugins.tab2mageimport.io.Tab2MageWriterFactory;
    6047import uk.ac.ebi.nugo.plugins.tab2mageimport.mail.Tab2MageEMessaging;
    61 import uk.ac.ebi.nugo.plugins.tab2mageimport.ExperimentPlatformsLibrary;
     48import uk.ac.ebi.nugo.plugins.tab2mageimport.validation.Tab2MageValidationFactory;
     49import uk.ac.ebi.nugo.plugins.util.Tab2MageHelper;
     50import uk.ac.ebi.nugo.plugins.util.ZipUnpacker;
    6251
    6352/**
     
    8372  //  the gui email server parameter
    8473  private PluginParameter<String> emailHostParameter;
     74  // logger
     75  private static Logger log = Logger.getLogger(Tab2MageImporter.class);
    8576 
    8677  private static final About about =
     
    179170    {
    180171      response.setError(ex.getMessage(), Arrays.asList(ex));
    181       ex.printStackTrace();
    182172    }
    183173   
     
    202192  {
    203193    String message = null;
    204     if (context.equals(experimentItemGuiContext))
    205     {
    206       if (item == null)
    207       {
    208         message = "The object is null";
    209       }
    210       else if (!(item instanceof Experiment))
    211       {
    212         message = "The object is not an Experiment: " + item;
    213       }
     194    if (item == null)
     195    {
     196      message = "The object is null";
     197     
     198    }
     199    else if (!(item instanceof Experiment))
     200    {
     201      message = "The object is not an Experiment: " + item;
     202    }
     203    else
     204    {
     205      Experiment exp = (Experiment)item;
     206      RawDataType rawDataType = exp.getRawDataType();
     207      if (!Tab2MageHelper.supportedPlatforms(rawDataType.getId().toLowerCase()))
     208      {
     209        message="This importer only supports Affymetrix, Agilent and Genepix Platforms. Your experiment's platform is :" + rawDataType.getId().toLowerCase();
     210      }
    214211    }
    215212    return message;
     
    250247    {
    251248      //who is using this plugin
    252       //[ DC MESSAGE : dc 1 is created ]
     249      //[ DC MESSAGE : Manager dc is created ]
    253250      dc= sc.newDbControl();
    254251      User user= User.getById(dc, sc.getLoggedInUserId());
     
    267264      RawDataType rdt= experiment.getRawDataType(); // experiment platform
    268265           
    269       boolean supported = Tab2MageHelper.supportedPlatforms(rdt.getId().toLowerCase());
    270       if (!supported)
    271       {
    272         response.setError("IMPORT FAILS: This importer only supports Affymetrix, Agilent and Genepix Platforms" ,Arrays.asList(new Throwable()));
    273         return;
    274       }
    275266      /*
    276267        create the roll back object here for testing
     
    279270     
    280271      /*
    281         unzip the files into user directory
    282        */
    283       Tab2MageHelper.write("The zipfile name is "+ file.getName());
    284       ZipUnpacker importUnpacker = new ZipUnpacker(file, user, dc);
    285       importUnpacker.unpack();
    286      
    287       // if unzip is sucessfull. (to check this return boolean value, we need to reimplement the util.ZipUnpacker, will affect the affyArrayDesignBatchImporter)
    288      
    289       //[ DC MESSAGE : dc 1 is closed ]
    290      
    291       // check that provided files conform to platform / experiment's platform, exit if not
    292      
    293       //    [ DC MESSAGE : dc 2 is created ]
    294      
     272        FILE UNZIP MODULE: unzip the files into user directory
     273       */
     274      ZipUnpacker importUnpacker = new ZipUnpacker(file, user, sc);
     275      importUnpacker.unpack(); // may change the the util.ZipUnpacker to return a boolean will affect affyArrayDesignBatchImporter too
     276      Directory dir= importUnpacker.getUnzippedFilesDirectory(); // this may return the id of the unzipped file directory instead
     277      if (dir==null)
     278      {
     279        response.setError("IMPORT FAILS: The directory containing the unzipped files could not be found. You may NOT have sufficient Disk Space" ,Arrays.asList(new Throwable()));
     280        return;
     281      }
     282     
     283      // -- end of file unzip module
     284     
     285      /*
     286        VALIDATION MODULE
     287       */
     288        //[ DC MESSAGE : if the manager dc is no longer available creates a new one.  It should be]
    295289      if (dc == null || !dc.isConnected()) dc = sc.newDbControl();
    296       Directory dir= importUnpacker.getUnzippedFilesDirectory(); // this may return the id of the unzipped file direcotyr instead
    297       if (dir==null)
    298       {
    299         response.setError("IMPORT FAILS: The directory containing the unzipped files could not be found. You may NOT have sufficient Disk Space" ,Arrays.asList(new Throwable()));
    300         return;
    301       }
    302      
    303       Tab2MageHelper.write("The directory containing the unzippped files is: "+ dir.getPath());
    304          
     290     
     291        // validate files supplied to platform
    305292      validPlatform=Tab2MageHelper.validatePlatform(dir, dc, rdt);
    306293      if (!validPlatform)
     
    310297            }
    311298     
    312       // validate image file
     299        // validate image file
    313300      List<File> imageFiles=Tab2MageHelper.getImageFiles(dir, dc) ;
    314       if (imageFiles.isEmpty() || imageFiles!=null) Tab2MageHelper.write("No image file supplied"); // remove or log this later message
    315      
    316301      if (!imageFiles.isEmpty()|| imageFiles==null)
    317302      {
     
    324309      }
    325310     
    326       // validate the tab2mage file (do initialisation here too)
    327       Tab2MageValidationFactory validator = new Tab2MageValidationFactory(tab2MageFileName, dc, dir, rdt.getId());
     311        // validate the tab2mage file (do initialisation here too)
     312      Tab2MageValidationFactory validator = new Tab2MageValidationFactory(tab2MageFileName, sc, dir, rdt.getId());
    328313      validTab2mageFile=validator.getValidated();
    329314      if (!validTab2mageFile)
     
    332317        return;
    333318      }
    334      
    335       //  [ DC MESSAGE : dc 2 is closed ]
    336      
    337       //  Do import() of the tab2mage file.
    338      
    339       // Call and initiate the roll back routines
    340      
    341       //create annotation types
     319      // -- end of validation module
     320     
     321      /*
     322        TAB2MAGE FILE IMPORT MODULE.
     323       */
     324          //  create annotation types
    342325      AnnotationTypesWriter atWriter= new AnnotationTypesWriter (sc, validator.getAtFile(),progress);
    343326      boolean writtenAT =atWriter.write(); // note if this action failed the transaction is completely rolled back
     
    348331      }
    349332      /*
    350         A new db control object necessary here to help with roll back
    351        */
    352         //write protocols and hybs
     333        A new db control object may be necessary here to help with roll back
     334       */
     335        // write protocols and hybs
    353336      Tab2MageWriterFactory hibernateItemsWriter = new Tab2MageWriterFactory
    354337                          (sc,Tab2MageValidationFactory.getCatchedProtocol(),
    355                             Tab2MageValidationFactory.getCatchedHybs(),rdt );
    356      
    357       //  [ DC MESSAGE : dc 3 is created ]
    358       if (dc == null || !dc.isConnected()|| dc.isClosed()) dc = sc.newDbControl();
    359      
    360       // get raw data file before closing dc is closed
    361       List<File> rawDataFiles= Tab2MageHelper.getRawDataFiles(dir, dc, rdt.getId(), tab2MageFileName);
    362      
    363       //NOTE: THIS IS ANOTHER DB TRANSACTION
    364       // if the protocol type is not found, write it into the database.
    365       // alternative is to fail at validation instead of a warning, if the protocol type
    366       // provided in tab2mage file is not in Base2 database. May may have to rework this.
    367       hibernateItemsWriter.writeProtocolTypes(dc); // dc is closed here
    368      
    369       // dc 3 is closed
     338                            Tab2MageValidationFactory.getCatchedHybs(),rdt,
     339                            Tab2MageValidationFactory.getSampleExtractMap(),
     340                            Tab2MageValidationFactory.getBioSourceSampleMap(),
     341                            Tab2MageValidationFactory.getExtractLabeledExtractMap());
     342     
     343        // if the protocol type is not found, write it into the database.
     344        // alternative is to fail at validation instead of a warning, if the protocol type
     345        // provided in tab2mage file is not in Base2 database. May may have to rework this.
     346     
     347      hibernateItemsWriter.writeProtocolTypes(sc);
    370348     
    371349      boolean writtenHibItems = hibernateItemsWriter.write();
     
    375353        return;
    376354      }
    377       for(String  fact : hibernateItemsWriter.getExpFactors())
    378       {
    379         Tab2MageHelper.write("\nThe factor values obtained : "+ fact);
    380         //TODO need to clear the memory holding expfactor
    381       }
    382       /*
    383         Do Data Import
    384         A new db control object necessary here to help with roll back
    385        */
    386      
     355     
     356      // -- end of Tab2Mage file import module
     357     
     358      /*
     359        RAW DATA IMPORT MODULE
     360       
     361       */
     362        //[ DC MESSAGE : if the manager dc is no longer available creates a new one.  It should be]
     363      if (dc == null || !dc.isConnected()|| dc.isClosed()) dc = sc.newDbControl();
     364     
     365        // get raw data files
     366      List<File> rawDataFiles= Tab2MageHelper.getRawDataFiles(dir, dc, rdt.getId(), tab2MageFileName);
     367       
     368        // do data import
    387369      Tab2MageDataImportFactory dataImport = new Tab2MageDataImportFactory(sc,rdt.getId(),rawDataFiles,
    388370                        hibernateItemsWriter.getRbas(), progress);
     
    393375        return;
    394376      }
    395      
    396       /*
    397         Configure and load the experiment
    398         A new dc is created here for another roll back point.
     377      // -- end of raw data import module
     378     
     379      /*
     380        EXPERIMENT CONFIGURATION AND LOADING MODULE
     381       
    399382       */     
     383        //write experiment, attaching raw bio-assays
    400384      Tab2MageExperimentWriter expWriter= new Tab2MageExperimentWriter(hibernateItemsWriter.getRbas(),sc,
    401385                                      experiment,hibernateItemsWriter.getExpFactors(),
    402386                                      validator.getTExperiment());
    403387      boolean writtenExp= expWriter.LoadExperiment();
    404       //  send an email to the user on the success of the experiment (if email server name and email address are provided)
    405       if (hostName!="" && hostName.length()>=5)
    406       {
    407         if (user.getEmail()!="" && user.getEmail()!=null )
     388      // -- end of experiment configuration and loading module
     389     
     390      /*
     391        MESSAGING MODULE
     392       */
     393        //  send an email to the user on the success of the experiment (if email server name and email address are provided)
     394      if (hostName!= null && hostName.length()>=5)
     395      {
     396        if (!user.getEmail().equals("") && user.getEmail()!=null )
    408397        {
    409398          Tab2MageEMessaging message= new Tab2MageEMessaging(writtenExp,"", user.getEmail(),tab2MageFileName, user.getName(), experiment.getName(),hostName );
     
    411400        }
    412401      }
    413      
    414       //  release object from memory and do clean up.
    415       if (!dir.isRemoved()) dir.setRemoved(true);
     402      // -- end of messaging module
     403     
    416404      response.setDone("Import plugin ended successfully");
    417405    }
     
    419407    {
    420408      response.setError(tr.getMessage(), Arrays.asList(tr));
    421         tr.printStackTrace();
    422     }
     409      }
    423410    finally
    424411    {
     
    448435      catch (Exception e)
    449436      {
    450         Tab2MageHelper.write("File is not a zip file and cannot be imported by this plugin.");
    451         e.printStackTrace();
     437        log.error("File is not a zip file and cannot be imported by this plugin.");
    452438        return false;
    453439      }
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/io/AnnotationTypeFileWriter.java

    r362 r374  
    4747    catch(Throwable t )
    4848    {
    49       t.printStackTrace();
     49      throw new NutribasePluginException(t.getMessage());
    5050    }
    5151  }
     
    7878    catch (IOException ioe)
    7979    {
    80       ioe.printStackTrace();
    8180      throw new NutribasePluginException(ioe.getMessage());
    8281    }
     
    9594        if (at==null)
    9695        {
    97           System.out.println("\nAT is null\n");
    9896          return;
    9997        }
     
    115113    catch (IOException ioe)
    116114    {
    117       ioe.printStackTrace();
    118115      throw new NutribasePluginException(ioe.getMessage());
    119116    }
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/io/AnnotationTypesWriter.java

    r362 r374  
    6969  public AnnotationTypesWriter(SessionControl sc, File expFile, ProgressReporter progress)
    7070  {
    71     System.out.println("Annotation Type Writer Object Created");
    7271    this.sc= sc;
    7372    this.exampleFile= expFile;
     
    8887      return written=false;
    8988    }
    90     System.out.println("PluginConfiguration importConfig = " + importConfig);
     89    log.info("PluginConfiguration importConfig = " + importConfig);
    9190    Job job = null;
    9291   
    9392    SimpleProgressReporter spr = new    SimpleProgressReporter(progress);
    9493    if (dc ==null)        dc = sc.newDbControl();
    95     System.out.println("+++Begin to execute job+++");
     94    log.info("+++Begin to execute job+++");
    9695    importConfig = PluginConfiguration.getById(dc, importConfig.getId());
    9796    job = Job.getNew(dc, importConfig.getPluginDefinition(), importConfig);
     
    111110        {
    112111          written= false;
    113           e.printStackTrace();
     112          log.error(e.getMessage());
    114113        }
    115114   
    116         System.out.println("Executing job: " + job.getName());
     115        log.info("Executing job: " + job.getName());
    117116       
    118117        PluginExecutionRequest request = job.execute(spr, localhost);
     
    128127          throw new BaseException(response.getMessage(), response.getErrorList().get(0));
    129128        }
    130         System.out.println("Job ended successfully: " + response.getMessage());
     129        log.info("Job ended successfully: " + response.getMessage());
    131130        return written;
    132131    }
     
    134133      {
    135134      dc.close();
    136       e.printStackTrace();
     135      log.error(e.getMessage());
    137136      return false;
    138       //throw new Exception(e);
    139137      }
    140138      finally
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/io/Base2Tab2MageFileReader.java

    r362 r374  
    332332  }
    333333 
    334   private void createAnnotationTypeFile() throws TAB2MAGEException
    335   {
    336     String filename= "anntype.txt";
    337     try
    338     {
    339       // create a file named: anntype.txt into the subdirectory (temp) created above
    340       atFile =  File.getFile(dc, subDir, filename, true);
    341       atFile.setMimeType(file.getMimeType());
    342       if (file.getFileType()!=null)
    343       {
    344         atFile.setFileType(file.getFileType());
    345       }
    346       // if the new file exist in the database, 
    347       if (atFile.isInDatabase())
    348       {
    349         throw new ItemAlreadyExistsException("Another file with the same name already exists");
    350        
    351       }
    352       else // save the file to the database.
    353       {
    354         dc.saveItem(atFile);
    355       }
    356     }
    357     catch (Throwable e)
    358     {
    359       log.error("Error: " + e.getMessage());
    360       throw new TAB2MAGEException(e.getMessage());
    361     }
    362   }
    363  
    364334  private void createExperimentFile() throws TAB2MAGEException
    365335  {
     
    697667              {
    698668                protocol.set( key, rowValues.get(j) );
    699                 //System.out.println("This protocol row value thing is : "+rowValues.get(j).toString());
    700669              }
    701670              catch(IndexOutOfBoundsException e)
    702671              {
    703672                protocol.set( key, "" );
    704                 //System.out.println("This protocol row value thing is null and changed to empty string");
    705673              }
    706674              continue cont;
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/io/RawDataImport.java

    r362 r374  
    2626
    2727import org.apache.log4j.Logger;
    28 
    29 import uk.ac.ebi.nugo.plugins.util.Tab2MageHelper;
    3028/**
    3129  This class writes raw data for multi - channel experiments.
     
    8987    public boolean importRawData() throws Exception
    9088    {
    91       System.out.println("++++ Importing raw data from file: " + file.getName());
    92       //DbControl dc =null;
    93     boolean written = true;
     89      log.info("++++ Importing raw data from file: " + file.getName());
     90      boolean written = true;
    9491    try
    9592    {
    9693      Job job = null;
    9794      SimpleProgressReporter spr = new    SimpleProgressReporter(progress);
    98       Tab2MageHelper.write("+++Begin to execute job+++");
     95      log.info("+++Begin to execute job+++");
    9996      importConfig = PluginConfiguration.getById(dc, importConfig.getId());
    10097      job = Job.getNew(dc, importConfig.getPluginDefinition(), importConfig);
     
    120117      {
    121118        written= false;
    122         e.printStackTrace();
     119        log.error(e.getMessage());
    123120      }
    124121     
    125       Tab2MageHelper.write("Executing job: " + job.getName());
     122      log.info("Executing job: " + job.getName());
    126123     
    127124      PluginExecutionRequest request = job.execute(spr, localhost);
     
    137134        throw new BaseException(response.getMessage(), response.getErrorList().get(0));
    138135      }
    139       System.out.println("Job ended successfully: " + response.getMessage());
     136      log.info("Job ended successfully: " + response.getMessage());
    140137      return written;
    141138    }
     
    144141      dc.close();
    145142      log.error("The raw data plugin could not load raw data");
    146       e.printStackTrace();
    147143      return false;
    148144      }
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/io/Tab2MageDataImportFactory.java

    r362 r374  
    109109      this.file =file;
    110110    }
    111     //System.out.println("++Raw Data File already set is : "+ file.getName());
     111    log.info("++Raw Data File already set is : "+ file.getName());
    112112  }
    113113 
     
    119119  public boolean importData()
    120120  {
    121     Tab2MageHelper.write("\n++++Begin Data Import\n");
     121    log.info("\n++++Begin Data Import\n");
    122122    DbControl dc =null;
    123123    boolean success= true;
     
    127127      //  :) extra validation is good for all
    128128      checkFiles();
    129       //System.out.println("file check is successful");
    130129      if (platform.equalsIgnoreCase("affymetrix"))
    131130      {
    132131        if (dc ==null)
    133132          dc = sc.newDbControl();
    134         //System.out.println("adding cel files to raw bioassays");
     133        log.info("adding cel files to raw bioassays");
    135134            for (RawBioAssay rbas  :rawBioAssays )
    136135            {
     
    140139              if (file!=null)
    141140              {
    142                Tab2MageHelper.write("The file is: " + file.getName() );
    143141               // need to attach the cel file to the bioassay object
    144142               Affymetrix.setCelFile(rba, file);
     
    149147      else if (!platform.equalsIgnoreCase("affymetrix"))// 2. import 2-channel -- include checkpoints and rollback points
    150148      {
    151         Tab2MageHelper.write(".......beginning ["+platform + "] data loading");
     149        log.info(".......beginning ["+platform + "] data loading");
    152150        if (dc ==null)
    153151          dc = sc.newDbControl();
     
    167165            dc = sc.newDbControl();
    168166          RawBioAssay rba = RawBioAssay.getById(dc,rbas.getId());
    169           //System.out.println("rba = " + rba.getName());
     167         
    170168          // get the file using file name. the file name is the raw bioassay name
    171169          File file = getFile(rba.getName(), dc);
    172170          if (file!=null)
    173171          {
    174             Tab2MageHelper.write("The name of the import configuration being used: "+ importConfig.getName());
     172            log.info("The name of the import configuration being used: "+ importConfig.getName());
    175173            RawDataImport rawDataImport = new RawDataImport(dc, importConfig, progress, file, rba);
    176174            boolean writtenRawData = rawDataImport.importRawData(); // Problem: closes the db control
     
    184182    {
    185183      success= false;
    186       t.printStackTrace();
    187184      log.error("DataImport: writing raw data failed");
    188185      dc.close();
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/io/Tab2MageExperimentWriter.java

    r362 r374  
    1919import org.embl.cg.bloader.models.Tab2MAGEExperiment;
    2020
    21 import uk.ac.ebi.nugo.plugins.util.Tab2MageHelper;
     21import uk.ac.ebi.nugo.plugins.util.ValueFormatter;
    2222/**
    2323  This class writes an experiment into the BASE 2 / Nutribase Database
     
    8686    {
    8787      //write experiment
    88       Tab2MageHelper.write("Loading experiment " + experiment);
     88      log.info("Loading experiment " + experiment);
    8989      int expID = experiment.getId();
    9090      Experiment exp = Experiment.getById(dc, expID);
     
    9393      {
    9494        rba = RawBioAssay.getById(dc, rba.getId());
    95         Tab2MageHelper.write("adding raw bioassay to experiment : " + rba);
     95        log.info("adding raw bioassay to experiment : " + rba);
    9696        exp.addRawBioAssay(rba);
    9797        }
     
    101101        AnnotationType at= getAnnotationTypeByName(factor);
    102102        ats.add(at);
    103         //Tab2MageHelper.write("The expr factor to add is : "+ at.toString());
    104103      }
    105104      if (!ats.isEmpty())
     
    122121      exp.setPublication(publication);
    123122      exp.setPublicationDate(Values.getDate(tab2mageExperiment.getPublication_date()));
    124       //Tab2MageHelper.write("The pub med id is : "+ Values.getEmptyStringIfNull(tab2mageExperiment.getPubmed_id()));
    125       exp.setPubMedId((String)Values.getEmptyStringIfNull(tab2mageExperiment.getPubmed_id()));
     123      exp.setPubMedId((String)ValueFormatter.getEmptyStringIfNull(tab2mageExperiment.getPubmed_id()));
    126124      exp.setTitle(tab2mageExperiment.getPublication_title());
    127125      dc.commit();
     
    129127    catch (Exception e)
    130128    {
    131       e.printStackTrace();
    132129      done= false;
    133130      dc.close(); // rollback if any problem arises
     
    144141  }
    145142 
    146   //remove getAnnotationType and use the common one in the Tab2MageHelper class.
    147143 
    148144  /**
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/io/Tab2MageHybWriter.java

    r362 r374  
    3636import net.sf.basedb.core.Scan;
    3737import net.sf.basedb.core.Type;
    38 
     38import net.sf.basedb.core.BioMaterial;
    3939
    4040import org.apache.log4j.Logger;
     
    109109  {
    110110    boolean done = true;
    111     Tab2MageHelper.write ("\n++++ Writing Hybridizations ++++\n");
     111    log.info ("\n++++ Writing Hybridizations ++++\n");
    112112    // declare protocols and parameter temporary catche
    113113    Map<String, String> protocolCatche = new HashMap<String, String>();
     
    129129        for (Tab2MAGEHybridization hyb : hybs)
    130130        {   
    131           Tab2MageHelper.write("\n------Handling Hybridization :" + hyb.getName()+"------\n");
     131          log.info("\n------Handling Hybridization :" + hyb.getName()+"------\n");
    132132          List<LabeledExtract> labeledExtracts = new ArrayList<LabeledExtract>();
    133133          i++;
     
    163163                for (Map.Entry<String, String> fact : factorMap.entrySet())
    164164                {
    165                   //System.out.println(" Factor Value is " + fact.getKey()+ ":" +fact.getValue());
    166165                  expFactors.add(fact.getKey());
    167166                }
     
    191190                return done=false;
    192191              }
    193               //System.out.println("The array Design is : " + arrayDesign.getName());
    194192              dc.reattachItem(arrayDesign);
    195193             
     
    205203             
    206204              //write Scan
    207                 Scan scan = createScan(hyb.getScanner(), newHyb, parameterCatche, protocolCatche);
     205                Scan scan = createScan( newHyb, parameterCatche, protocolCatche);
    208206             
    209207              //write Raw Bio Assay
    210208                RawBioAssay rba = createRawBioAssay(hyb.getFileRaw(), rdt, scan, arrayDesign, parameterCatche, protocolCatche, factorValueCatche);
    211209                rbaCatche.add(rba);
    212                 //System.out.println("Raw Bio Assay"+ rba.getName()+ "is added to catch");
     210               
    213211        }// end of each Hyb
    214212      }
    215213      catch(Throwable tr)
    216214      {
    217         tr.printStackTrace();
     215        log.warn(tr.getMessage());
    218216        return done=false;
    219217      }
     
    242240  {
    243241    BioSource bio;
    244     Tab2MageHelper.write("--Creating biosource: " + name + "\n");
     242    log.info("--Creating biosource: " + name + "\n");
    245243    if (!bioSources.isEmpty() &&  bioSources.containsKey(name))
    246244    {
    247245      bio= (BioSource)bioSources.get(name);
    248       System.out.println("--The biosource obtained is :" + bio.getName());
    249246    }
    250247    else
     
    260257        {
    261258          log.warn("Annotation for BioMaterial Characteristics cannot be set. Check the allowed values for the annotation type");
    262           //roll back done in the write method
    263259        }
    264260        dc.saveItem(bio);
    265261        bioSources.put(bio.getName(),bio);
    266         System.out.println("--The biosource created is :" + bio.getName());
     262        log.info("--The biosource created is :" + bio.getName());
    267263    }
    268264    return bio;
     
    281277  {
    282278    Sample sample;
    283     Tab2MageHelper.write("--Creating sample: " + name + "\n");
     279    log.info("--Creating sample: " + name + "\n");
    284280    if (!samples.isEmpty() &&  samples.containsKey(name))
    285281    {
    286282      sample= (Sample)samples.get(name);
    287       Tab2MageHelper.write("--The sample obtained is :" + sample.getName());
     283      log.info("--The sample obtained is :" + sample.getName());
    288284    }
    289285    else
     
    307303        {
    308304          log.warn("Annotation for Sampling Protocol cannot be set. Check the allowed values for the annotation type");
    309           //roll back done in the write method
    310305        }
    311306       
     
    313308        dc.saveItem(sample);
    314309        samples.put(sample.getName(),sample);
    315         Tab2MageHelper.write("--The sample created is :" + sample.getName()+"\n");
     310        log.info("--The sample created is :" + sample.getName()+"\n");
    316311    }
    317312    return sample;
     
    328323  private Extract createExtract(String name,Sample sample, Map<String, BasicItem> extracts, Map<String, String> param, Map<String, String> protMap )
    329324  {
    330     Tab2MageHelper.write("--Creating extract: " + name + "\n");
     325    log.info("--Creating extract: " + name + "\n");
    331326    Extract extract;
    332327    if (!extracts.isEmpty() &&  extracts.containsKey(name))
    333328    {
    334329      extract= (Extract)extracts.get(name);
    335       Tab2MageHelper.write("--The extract obtained is :" + extract.getName());
     330      log.info("--The extract obtained is :" + extract.getName());
    336331    }
    337332    else
     
    352347        {
    353348          log.warn("Annotation for Extraction Protocol cannot be set.Check the allowed values for the annotation type");
    354           //roll back done in the write method
    355349        }
    356350        // add the extract annotations for MAG- TAB sample characteristics
    357351        dc.saveItem(extract);
    358352        extracts.put(extract.getName(),extract);
    359         Tab2MageHelper.write("--The extract created is :" + extract.getName()+"\n");
     353        log.info("--The extract created is :" + extract.getName()+"\n");
    360354    }
    361355    return extract;
     
    374368  private LabeledExtract createLabeledExtract(String name, String dye, Label lb, Extract extract, Map<String, BasicItem> lExtracts, Map<String, String> param, Map<String, String> protMap)
    375369  {
    376     Tab2MageHelper.write("--Creating labeled extract: " + name + "\n");
     370    log.info("--Creating labeled extract: " + name + "\n");
    377371    LabeledExtract lextract;
    378372    if (!lExtracts.isEmpty() &&  lExtracts.containsKey(name))
    379373    {
    380374      lextract= (LabeledExtract)lExtracts.get(name);
    381       Tab2MageHelper.write("--The extract obtained is :" + extract.getName());
     375      log.info("--The extract obtained is :" + extract.getName());
    382376    }
    383377    else
     
    397391      {
    398392        log.warn("Annotation for Labeling Protocol cannot be set. Check the allowed values for the annotation type");
    399         //roll back done in the write method
    400393      }
    401394      //     add the labeled extract annotations for MAG- TAB sample characteristics
    402395      dc.saveItem(lextract);
    403396      lExtracts.put(lextract.getName(),lextract);
    404       Tab2MageHelper.write("--The labeled extract created is :" + lextract.getName()+"\n");
     397      log.info("--The labeled extract created is :" + lextract.getName()+"\n");
    405398    }
    406399    return lextract;
     
    418411      Map<String, String> parCatche, Map<String,String> proCatche )
    419412  {
    420     Tab2MageHelper.write("--Creating hybridization: " + name + "\n");
    421     //     used dc.commitif labelled extract is saved.
     413    log.info("--Creating hybridization: " + name + "\n");
    422414    Hybridization newHyb = Hybridization.getNew(dc);
    423415    newHyb.setName(name);
     
    430422    }
    431423    String accessionNo = getProtocolAccesion(proCatche,"hybridization"); //
    432     // temp comment this out and test......
    433     //BioMaterialEvent newHybEvent=newHyb.getCreationEvent();
    434424    bioMaterialEvent.setProtocol(getProtocol(accessionNo));
    435425    // add the  annotation for protocol parameters
     
    441431    {
    442432      log.warn("Annotation for Hybridization Protocol cannot be set. Check that");
    443       //roll back done in the write method
    444433    }
    445434    dc.saveItem(newHyb);
    446     Tab2MageHelper.write("--The Hybridization created is :" + newHyb.getName()+"\n");
     435    log.info("--The Hybridization created is :" + newHyb.getName()+"\n");
    447436    return newHyb;
    448437  }
     
    455444    @return
    456445   */
    457   private Scan createScan(String name, Hybridization hyb, Map<String, String> parCatche, Map<String, String> proCatche)
    458   {
    459     //Scan scan= hyb.newScan();
    460     Tab2MageHelper.write("--Creating scan: " + name + "\n");
     446  private Scan createScan(Hybridization hyb, Map<String, String> parCatche, Map<String, String> proCatche)
     447  {
     448    log.info("--Creating scan: " +hyb.getName()+ "\n");
    461449    Scan scan = Scan.getNew(dc, hyb);
    462     if (name!="" && name!= null)
    463       scan.setName(name);
    464     else
    465       scan.setName("scan"+hyb.getName());  //to make scan unique per Hyb add hyb name to the scan name
     450    scan.setName("scan"+hyb.getName());  //to make scan unique per Hyb add hyb name to the scan name
    466451    String accessionNo = getProtocolAccesion(proCatche,"scanning"); //
    467452    scan.setProtocol(getProtocol(accessionNo));
     
    474459    {
    475460      log.warn("Annotation for Scanning Protocol cannot be set. Check that");
    476       //roll back done in the write method
    477461    }
    478462    dc.saveItem(scan);
    479     Tab2MageHelper.write("--The scan created is :" + scan.getName()+"\n");
     463    log.info("--The scan created is :" + scan.getName()+"\n");
    480464    return scan;
    481465  }
     
    494478      Map<String,String> parCatche, Map<String,String> protCatche, Map<String, String>factCatche)
    495479  {
    496     Tab2MageHelper.write("--Creating raw bioassay: " + name +"\n");
     480    log.info("--Creating raw bioassay: " + name +"\n");
    497481      RawBioAssay rba = RawBioAssay.getNew(dc, rawDataType);
    498482      rba.setName(name);
     
    510494    {
    511495      log.warn("Annotation for Feature Extraction Protocol cannot be set. Check the allowed values for the annotation type");
    512       //roll back done in the write method
    513496    }
    514497    //  add the raw bioassay  annotations for implementing factor value annotation.
    515498    //  This is a work around, avoiding the inherited annotation problem: i.e items to inherit factor value
    516     //  from are not available in tab2mage file neither si there an association.
     499    //  from are not available in tab2mage file neither is there an association.
    517500   
    518     //Tab2MageHelper.write(" \n+++++++ Checking out the Content of the Factor Vaue Map +++++\n");
    519     //for (Map.Entry<String, String> fact : factorValueCatche.entrySet())
    520     //{
    521     //  Tab2MageHelper.write(" Factor Val is " + fact.getKey()+ ":" +fact.getValue());
    522     //}
    523501    try
    524502    {
     
    531509    }
    532510    dc.saveItem(rba);
    533     Tab2MageHelper.write("--The raw bio assay created is :" + rba.getName()+"\n");   
     511    log.info("--The raw bio assay created is :" + rba.getName()+"\n");   
    534512    return rba;
    535513  }
     
    549527      as.setName(arrayDesign.getName()+ "-Slide#" +i);
    550528      dc.saveItem(as);
    551       //Tab2MageHelper.write("The new array  slide is :" + as.getName());
     529      log.info("The new array  slide is :" + as.getName());
    552530    }
    553531    return as;
     
    580558  private String getProtocolAccesion(Map<String, String> protMap, String type)
    581559  {
    582     //Tab2MageHelper.write(" \n+++++++ Checking out the Hyb Protocols +++++\n");
    583560    String accession="";
    584561    for (Map.Entry<String, String> prot: protMap.entrySet())
    585562    {
    586       //Tab2MageHelper.write(" Hyb Protocol is " + prot.getKey()+ ":" +prot.getValue());
    587563      if (prot.getKey().equals(type.toUpperCase()))
    588564      {
     
    599575  private Protocol getProtocol(String protocolAccesion)
    600576  {
    601     //Tab2MageHelper.write(" \n+++++++ Getting Protocols +++++\n");
    602577    Protocol protocol=null;
    603578    for (Map.Entry<String, Protocol> prot: protocolAccessionMap.entrySet())
    604579    {
    605       //Tab2MageHelper.write(" Protocol Accession Map is: " + prot.getKey()+ ":" +prot.getValue());
    606580      if (prot.getKey().equalsIgnoreCase(protocolAccesion))
    607581      {
     
    637611      for (Map.Entry<AnnotationType, String> annt : annotationTypes.entrySet())
    638612      {
    639         //Tab2MageHelper.write("Annotation type - Value mapping is " + annt.getKey().toString()+ ":" +annt.getValue());
    640          
    641         // remove annotations if the annotatable item has annotations already
    642         // this is because, we consider the annotatable item as a new item  that
    643         // should not reference an already existing annotation  of an item with
    644         //the same name, even if the item has been deleted.
    645         //if (annotatable.isAnnotated()) annotatable.removeAnnotations();
    646613        if (annotatable instanceof  RawBioAssay)
    647614        {
    648           //Tab2MageHelper.write("YES, IT IS AN INSTANCE OF RAWBIOASSAY");
    649615          AnnotationType t = annt.getKey();
    650616          if (t.isEnabledForItem(Item.RAWBIOASSAY)) // if the annotation type is enable for raw bioassay item, set annotations
     
    652618            AnnotationSet as = annotatable.getAnnotationSet();
    653619            String values= annt.getValue();
    654             Tab2MageHelper.write("Inserting: "+ annt.getValue()+" annotation for: "+ annotatable.toString());
     620            log.info("Inserting: "+ annt.getValue()+" annotation for: "+ annotatable.toString());
    655621           
    656622            if (t.getValueType().equals(Type.FLOAT))
    657623            {
    658               Tab2MageHelper.write("YES, the annotation value type is float");
    659624              Float v = new Float(Float.parseFloat(values));
    660625              as.getAnnotation(annt.getKey()).setValue(v);
     
    671636        {
    672637          AnnotationSet as = annotatable.getAnnotationSet();
    673           //Tab2MageHelper.write("Inserting: "+ annt.getValue()+" annotation for: "+ annotatable.toString());
     638          //log.info("Inserting: "+ annt.getValue()+" annotation for: "+ annotatable.toString());
    674639          as.getAnnotation(annt.getKey()).setValue(annt.getValue());
    675640        }
     
    689654    for (Map.Entry<String, String> an : annotationMap.entrySet())
    690655    {
    691       //Tab2MageHelper.write(" Annotation type [BioMat,Param] Value is " + an.getKey()+ ":" +an.getValue());
    692656      AnnotationType at =Tab2MageHelper.getAnnotationTypeByName(an.getKey(),dc);
    693657      if (at!=null)
     
    705669          {
    706670            AnnotationSet as = annotatable.getAnnotationSet();
    707             //Tab2MageHelper.write("Inserting: "+ anv.getValue()+" annotation for: "+ annotatable.toString());
     671            log.info("Inserting: "+ anv.getValue()+" annotation for: "+ annotatable.toString());
    708672            as.getAnnotation(anv.getKey()).setValue(anv.getValue());
    709673          }
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/io/Tab2MageProtocolWriter.java

    r362 r374  
    6565      {
    6666        boolean exist= checkIfProtocolExist(protocol, dc);
    67         Tab2MageHelper.write(exist? "Protocol Exist " : "Protocol DoNot Exist");
     67        log.info(exist? "Protocol Exist " : "Protocol DoNot Exist");
    6868        if (!exist) // if protocol is not found in the protocol table  in BASE 2
    6969        {         
     
    8484          for (String res : result)
    8585          {
    86             Tab2MageHelper.write("The protocol parameter to convert to annotation type is : "+ res);
     86            log.info("The protocol parameter to convert to annotation type is : "+ res);
    8787            AnnotationType annotationType= getAnnotationTypeFromProtocolParameter(res.trim(), dc);
    8888            try
     
    9191              {
    9292                newProtocol.addParameter(annotationType);
    93                 System.out.printf("The annotation type: %s is added to protocol\n", annotationType.getName());
    9493              }
    9594            }
     
    104103         
    105104          dc.saveItem(newProtocol);
    106           Tab2MageHelper.write("The protocol name to write is : " + newProtocol.getName());
     105          log.info("The protocol name to write is : " + newProtocol.getName());
    107106        }
    108107      }
     
    134133    if (names.contains(prot.getName().toLowerCase()))
    135134    {
    136       System.out.printf("The protocol: %s is found in the database\n", prot.getName().toString());
    137135      found = true;
    138136    }
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/io/Tab2MageWriterFactory.java

    r362 r374  
    2121import net.sf.basedb.core.ArraySlide;
    2222import net.sf.basedb.core.BasicItem;
     23import net.sf.basedb.core.BioMaterial;
    2324import net.sf.basedb.core.BioMaterialEvent;
    2425import net.sf.basedb.core.BioSource;
     
    3334import net.sf.basedb.core.Label;
    3435import net.sf.basedb.core.LabeledExtract;
     36import net.sf.basedb.core.MeasuredBioMaterial;
    3537import net.sf.basedb.core.Protocol;
    3638import net.sf.basedb.core.ProtocolType;
     
    4749import org.embl.cg.bloader.models.Tab2MAGEProtocol;
    4850
     51import uk.ac.ebi.nugo.plugins.tab2mageimport.validation.Tab2MageValidationFactory;
    4952import uk.ac.ebi.nugo.plugins.util.NutribasePluginException;
    5053import uk.ac.ebi.nugo.plugins.util.Tab2MageHelper;
     
    9699  private Set<String> expFactors= new HashSet<String>();
    97100  /**
    98     List of protocol object for experiment.
    99    */
    100   //private List<Protocol> usedProtocols =  new ArrayList<Protocol>();
     101    Map of pooled sample -to- extract.
     102   */
     103    private Map<String, List<String>> sampleExtMap =  new HashMap<String, List<String>>();
     104   
     105  /**
     106    Map of pooled biosource -to- sample.
     107   */
     108    private Map<String, List<String>> bioSourceSamMap =  new HashMap<String, List<String>>();
     109   
     110  /**
     111    Map of pooled extract -to- labeled extract.
     112   */
     113    private Map<String, List<String>> extractLEMap =  new HashMap<String, List<String>>();
    101114  /**
    102115    creates a new tab2mage writer factory
     
    106119      @param rdt
    107120   */
    108   public Tab2MageWriterFactory(SessionControl sc, Set<Tab2MAGEProtocol> protocols, ArrayList<Tab2MAGEHybridization> hybs, RawDataType rdt)
     121  public Tab2MageWriterFactory(SessionControl sc, Set<Tab2MAGEProtocol> protocols,
     122                ArrayList<Tab2MAGEHybridization> hybs, RawDataType rdt,
     123                Map<String, List<String>> sampleExtract,
     124                Map<String, List<String>> bioSourceSample,
     125                Map<String, List<String>> extractLabExtract)
    109126  {     
    110127    this.hybs= hybs;
    111128    this.rdt= rdt;
    112129    this.protocols = protocols;
    113     dc= sc.newDbControl(); // create a single dbcontrol for this writer factory
     130    dc= sc.newDbControl(); // create a single db control for this writer factory
     131    this.sc= sc;
     132    if (sampleExtract!=null && !sampleExtract.isEmpty() ) this.sampleExtMap.putAll(sampleExtract);
     133    if (bioSourceSample!=null && !bioSourceSample.isEmpty()) this.bioSourceSamMap.putAll(bioSourceSample);
     134    if (extractLabExtract!=null && !extractLabExtract.isEmpty()) this.extractLEMap.putAll(extractLabExtract);
    114135  }
    115136 
     
    135156        return success= false;
    136157      }
     158      // store rawbioassay and experimental factors for later use by the experiment writer
    137159      this.rbas=hybWriter.getRbaCatche();
    138160      this.expFactors=hybWriter.getExpFactors();
     
    142164    {
    143165      success= false;
    144       t.printStackTrace();
    145166      log.error("WriterFactory: writing Protocol and Hybridization failed");
    146167      dc.close();
     
    166187  }
    167188 
     189  // this should only be executed if the preceding #write() works fine
     190
     191  @SuppressWarnings("unchecked")
     192  public boolean writePooledMetaData()
     193  {
     194    boolean done= true;
     195    //Tab2MageHelper.write(",,, handling pooled data........");
     196    try
     197    {
     198      // create a new db control since the last once would have been closed anyway
     199      if (dc == null || !dc.isConnected()|| dc.isClosed()) dc = sc.newDbControl();
     200   
     201      Tab2MageHelper.write("Entering the try loop");
     202      for (Map.Entry<String , List<String>> entry : sampleExtMap.entrySet())
     203      {
     204        Tab2MageHelper.write("\n++ The sample extract from the SampleExractMap is : "+entry.getKey()+":"+ entry.getValue());
     205        List<String> parents= entry.getValue();
     206        List<BasicItem> children = new ArrayList<BasicItem>();
     207        for (String parent : parents )
     208        {
     209          Tab2MageHelper.write("++The current parent being checked is "+ parent);
     210          Sample p = Tab2MageHelper.findSample(dc, parent); // get the parent from the database
     211          ItemQuery<Extract> childrenQuery  = p.getExtracts(); // get all the extracts ( children of parents -Sample)
     212          childrenQuery.include(Include.MINE, Include.NOT_REMOVED); // include those children created by the loggedin user only
     213          if (childrenQuery.list(dc).size()!=0)
     214            children.add(childrenQuery.list(dc).get(0));  // pick the first child or extract in this case
     215        }
     216        String childofParent = entry.getKey(); // in this example this is the extract
     217        Tab2MageHelper.write("...The key from map is : " + childofParent );
     218        Extract e= Tab2MageHelper.findExtract(dc, childofParent);
     219        Tab2MageHelper.write("...the already created object fetched is : " + e.getName() );
     220        dc.reattachItem(e);
     221        e.setPooled(true);
     222        for (BasicItem<?> child : children)
     223        {
     224          e.getCreationEvent().addSource((MeasuredBioMaterial) child, Float.parseFloat("0.10"));
     225        }
     226       
     227      }
     228      dc.commit();
     229    }
     230    catch(Throwable tr)
     231    {
     232      done= false;
     233      log.error("WriterFactory: setting pooled items failed");
     234      dc.close();
     235      throw new NutribasePluginException(tr.getMessage());
     236    }
     237    finally
     238    {
     239      if (dc!=null)
     240        dc.close();
     241    }
     242    done=false;
     243    return done;
     244  }
     245 
    168246  /**
    169247    writes the  protocol type not found in the database which must be within the allowed range in tab2mage specification
     
    171249    @param localDc
    172250   */
    173   public void writeProtocolTypes(DbControl localDc)
    174   {
     251  public void writeProtocolTypes(SessionControl sc)
     252  {
     253    DbControl localDc=sc.newDbControl();
    175254    try
    176255    {
     
    178257      {
    179258        boolean foundType =Tab2MageHelper.checkIfProtocolTypesExist(protocol,localDc);
    180         //System.out.println(foundType? "ProtocolType Exist " : "ProtocolType DoNot Exist");
    181259        if (!foundType)
    182260        {
     
    192270    {
    193271      log.error("ProtocolTypes cannot be created");
    194       tr.printStackTrace();
    195272      localDc.close(); // if there is an error. the creation of annotation types is rolled back.
    196273      throw new NutribasePluginException(tr.getMessage()); 
     
    201278        localDc.close();
    202279    }
    203   }
    204    
    205  
    206   /**
    207     creates a new array batch if one does not exist already 
    208       @param arrayDesign
    209     @return array batch
    210    */
    211   private ArrayBatch createArrayBatch (ArrayDesign arrayDesign, int i )
    212   {
    213     String accession = arrayDesign.getName()+"-Batch#" + i; // accession is thename of the slide
    214     ArrayBatch arrayBatch = Tab2MageHelper.findArrayBatch(dc, accession);
    215     if (arrayBatch== null)
    216     {
    217       arrayBatch = ArrayBatch.getNew(dc, arrayDesign);
    218       arrayBatch.setName(accession);
    219       dc.saveItem(arrayBatch);
    220     }
    221     return arrayBatch;
    222   }
    223   /**
    224     creates a raw bioassay
    225       @param name
    226       @param rawDataType
    227     @return
    228    */
    229   private RawBioAssay createRawBioAssay( String name, RawDataType rawDataType)
    230   {
    231     //System.out.println("Creating raw bioassay: " + name);
    232       RawBioAssay rba = RawBioAssay.getNew(dc, rawDataType);
    233       rba.setName(name);
    234       dc.saveItem(rba);
    235       return rba;
    236     }
    237   /**
    238     gets the protocol accession number  given
    239     @param protMap, the Hybline protocol map
    240     @param type, the protocol type
    241     @return the accession number
    242    */
    243 
    244   private String getProtocolAccesion(Map<String, String> protMap, String type)
    245   {
    246     //System.out.println(" \n+++++++ Checking out the Hyb Protocols +++++\n");
    247     String accession="";
    248     for (Map.Entry<String, String> prot: protMap.entrySet())
    249     {
    250       //System.out.println(" Hyb Protocol is " + prot.getKey()+ ":" +prot.getValue());
    251       if (prot.getKey().equals(type.toUpperCase()))
    252       {
    253         accession =prot.getValue();
    254         break;
    255       }
    256     }
    257     return accession;
    258   }
    259   /**
    260     get protocol given the protocolname and type
    261    * @return
    262    */
    263   private Protocol getProtocol(String protocolAccesion)
    264   {
    265     //System.out.println(" \n+++++++ Getting Protocols +++++\n");
    266     Protocol protocol=null;
    267     for (Map.Entry<String, Protocol> prot: protocolAccessionMap.entrySet())
    268     {
    269       //System.out.println(" Protocol Accession Map is: " + prot.getKey()+ ":" +prot.getValue());
    270       if (prot.getKey().equalsIgnoreCase(protocolAccesion))
    271       {
    272         protocol =prot.getValue();
    273         break;
    274       }
    275     }
    276     return protocol;
    277280  }
    278281 
     
    286289  }
    287290 
    288   private void setAnnotations(Annotatable annotatable, Map<String,String>annotationMap)
    289   {
    290     Map<AnnotationType, String> annotationTypes = new HashMap<AnnotationType, String>();
    291     for (Map.Entry<String, String> an : annotationMap.entrySet())
    292     {
    293       AnnotationType at =Tab2MageHelper.getAnnotationTypeByName(an.getKey(),dc);
    294       if (at!=null)
    295       {
    296         annotationTypes.put(at, an.getValue());
    297       }
    298     }
    299     if (!annotationTypes.isEmpty())
    300     {
    301       for (Map.Entry<AnnotationType, String> annt : annotationTypes.entrySet())
    302       {
    303         //System.out.println("Annotation type - Value mapping is " + annt.getKey().toString()+ ":" +annt.getValue());
    304          
    305         // remove annotations if the annotatable item has annotations already
    306         // this is because, we consider the annotatable item as a new item  that
    307         // should not reference an already existing annotation  of an item with
    308         //the same name, even if the item has been deleted.
    309         //if (annotatable.isAnnotated()) annotatable.removeAnnotations();
    310         if (annotatable instanceof  RawBioAssay)
    311         {
    312           //System.out.println("YES, IT IS AN INSTANCE OF RAWBIOASSAY");
    313           AnnotationType t = annt.getKey();
    314           if (t.isEnabledForItem(Item.RAWBIOASSAY)) // if the annotation type is enable for raw bioassay item, set annotations
    315           {
    316             AnnotationSet as = annotatable.getAnnotationSet();
    317             String values= annt.getValue();
    318             System.out.println("Inserting: "+ annt.getValue()+" annotation for: "+ annotatable.toString());
    319            
    320             if (t.getValueType().equals(Type.FLOAT))
    321             {
    322               System.out.println("YES, the annotation value type is float");
    323               Float v = new Float(Float.parseFloat(values));
    324               as.getAnnotation(annt.getKey()).setValue(v);
    325              
    326             }
    327             else //if( t.getValueType().equals(Type.STRING))
    328             {
    329               as.getAnnotation(annt.getKey()).setValue(annt.getValue());
    330             }
    331           }
    332           // otherwise do nothing
    333         }
    334         else
    335         {
    336           AnnotationSet as = annotatable.getAnnotationSet();
    337           //System.out.println("Inserting: "+ annt.getValue()+" annotation for: "+ annotatable.toString());
    338           as.getAnnotation(annt.getKey()).setValue(annt.getValue());
    339         }
    340        
    341       }
    342     }
    343   }
    344  
    345   /**
    346     sets annotations for protocol parameters
    347     @param annotatable, the item that uses the protocol
    348     @param annotationMap, map of [annotation types - value] pair
    349    */
    350   private void setParameterAnnotations(Annotatable annotatable, Map<String,String>annotationMap)
    351   {
    352     Map<AnnotationType, String> ats = new HashMap<AnnotationType, String>();
    353     for (Map.Entry<String, String> an : annotationMap.entrySet())
    354     {
    355       //System.out.println(" Annotation type [BioMat,Param] Value is " + an.getKey()+ ":" +an.getValue());
    356       AnnotationType at =Tab2MageHelper.getAnnotationTypeByName(an.getKey(),dc);
    357       if (at!=null)
    358       {
    359         ats.put(at, an.getValue());
    360       }
    361     }
    362     if (!ats.isEmpty())
    363     {
    364       for (Map.Entry<AnnotationType, String> anv : ats.entrySet())
    365       {
    366         if (annotatable.getProtocol()!=null)
    367         {
    368           if (annotatable.getProtocol().isParameter(anv.getKey()))
    369           {
    370             AnnotationSet as = annotatable.getAnnotationSet();
    371             //System.out.println("Inserting: "+ anv.getValue()+" annotation for: "+ annotatable.toString());
    372             as.getAnnotation(anv.getKey()).setValue(anv.getValue());
    373           }
    374         }
    375       }
    376     }
    377   }
    378 
    379291  /**
    380292    get the list of raw bio asssay
     
    385297    return rbas;
    386298  }
    387 
    388 
    389299}
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/mail/Tab2MageEMessaging.java

    r362 r374  
    2020
    2121import org.apache.log4j.Logger;
     22
     23import uk.ac.ebi.nugo.plugins.util.NutribasePluginException;
    2224/**
    2325  This class is the e messaging for the Tab2Mage import and export. This is
     
    3335  private String mailFrom = "";
    3436  private String mailTo = "";
    35   //private String host = "smtp.ebi.ac.uk";
    3637  private String host="";
    3738  private String body = "";
     
    4445    this.mailFrom = from;
    4546    this.mailTo= to;
    46     if (fileName!="")tab2MageFileName = fileName;
    47     if (userName!="")loggedinUserName=userName;
     47    if (!fileName.equals("")) tab2MageFileName = fileName;
     48    if (!userName.equals("")) loggedinUserName=userName;
    4849    this.host= hostname;
    4950    if (status) // if successful
     
    107108      message.setSentDate(new Date());
    108109     
    109       System.out.println("sending message.......");
     110      log.info("sending message.......");
    110111      //sending the tab2mage message
    111112      Transport.send(message);
     
    114115    {
    115116      log.error("Email message cannot be sent, your email address maybe invalid. Or " +me.getMessage()+ ". Contact your smtp sever adminstrator");
    116       me.printStackTrace();
    117       //throw new NutribasePluginException("Email message cannot be sent, your email address maybe invalid. Or " +me.getMessage()+ ". Contact your smtp sever adminstrator");
     117      throw new NutribasePluginException("Email message cannot be sent, your email address maybe invalid. Or " +me.getMessage()+ ". Contact your smtp sever adminstrator");
    118118    }
    119119    catch (UnsupportedEncodingException e)
    120120    {
    121121      log.error("You have some unsupported characters in your base/nutribase username or email address.");
    122       e.printStackTrace();
    123       //throw new NutribasePluginException(e.getMessage());
     122      throw new NutribasePluginException(e.getMessage());
    124123    }
    125124  }
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/validation/AgilentValidation.java

    r362 r374  
    6060      for (File agFile : agilentFiles )
    6161      {
    62         Tab2MageHelper.write("Validating agilent file : "+ agFile.getName());
     62        log.info("Validating agilent file : "+ agFile.getName());
    6363        AgilentRDParser agParser= new AgilentRDParser(agFile, dc);
    6464        String [] headers= agParser.getHeaders();
    6565        if (headers==null) continue;
    66         //Tab2MageHelper.write("\n..........The list of agilent headers\n");
    6766        List<String> headerList = Tab2MageHelper.arrayContentToLowercase(headers);
    68         //int i=0;
    69         //for (String header :headerList )
    70         //{
    71         //  i++;
    72         //  Tab2MageHelper.write("Header " + i + ": "+ header);
    73         //}
    74         //Tab2MageHelper.write("End of agilent headers\n");
    7567        List<AgilentDataColumns> mandatoryColumns= Arrays.asList(AgilentDataColumns.values());
    7668        for (AgilentDataColumns man :mandatoryColumns )
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/validation/GenePixFileValidation.java

    r362 r374  
    7171        Base2GenePixRDParser gParser= new Base2GenePixRDParser(gprFile, dc);
    7272        String [] headers= gParser.getHeaders();
    73         //Tab2MageHelper.write("\n..........The list of Genepix headers\n");
    7473        List<String> headerList = Tab2MageHelper.arrayContentToLowercase(headers);
    75         //int i=0;
    76         //for (String header :headerList )
    77         //{
    78         //  i++;
    79         //  Tab2MageHelper.write("Header " + i + ": "+ header);
    80         //}
    81       //  Tab2MageHelper.write("End of Genepix headers\n");
    8274        List<GenePixDataColumns> mandatoryColumns= Arrays.asList(GenePixDataColumns.values());
    8375        for (GenePixDataColumns man :mandatoryColumns )
     
    9587      success = false;
    9688      log.error("The gpr files cannot be validated"+tr.getMessage());
    97       tr.printStackTrace();
    9889    }
    9990    return success;
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/validation/RawDataValidation.java

    r362 r374  
    77
    88/**
    9   This inteface is for the validation of raw data files.
     9  This interface is for the validation of raw data files.
    1010  Note: seperate implementation to base1/ baseloader
    1111    @author Dominic Oyeniran
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/validation/Tab2MageImportValidatorUtils.java

    r362 r374  
    2929import uk.ac.ebi.nugo.plugins.tab2mageimport.AnnotationTypeFileMapping;
    3030import uk.ac.ebi.nugo.plugins.util.NutribasePluginException;
     31import uk.ac.ebi.nugo.plugins.util.Tab2MageConstants;
    3132import uk.ac.ebi.nugo.plugins.util.Tab2MageHelper;
    3233
     
    8081  List<String> annotationTypes = new LinkedList<String>();
    8182 
    82 
     83  //annotate this guy later.
     84  private static Map< String, List<String>> BioSourceSamplePoolMap= new HashMap< String, List<String>>();
     85  private static Map< String, List<String>> SampleExractPoolMap= new HashMap< String, List<String>>();
     86  private static Map<String, List<String>> ExractLabeledExtractPoolMap= new HashMap< String, List<String>>();
     87 
    8388  /**
    8489      creates the hyb validator util
     
    126131        createAnnotationTypeValueMap(parameterAnnotationType);
    127132        createAnnotationTypeValueMap(factorValueAnnotationType); 
     133     
    128134      }
    129135    }
     
    138144    for(Map.Entry<String, String> e : map.entrySet())
    139145    {
    140       //Tab2MageHelper.write(e.getKey() + ": " + e.getValue());
    141146      if (Values.getFloat(e.getValue())== 0)
    142147      {
     
    174179        if (parameterAnnotationType.containsKey(e.getKey()))
    175180        {
    176           //Tab2MageHelper.write("Found Parameter key : [" + e.getKey()+ "] and value is :" + parameterAnnotationType.get(e.getKey()));
    177181          parameter="true";
    178182        }
    179         //Tab2MageHelper.write(".....checking biomat map");
     183       
    180184        if (bioMaterialAnnotationType.containsKey(e.getKey()))
    181185        {
    182           //Tab2MageHelper.write("Found BioMat key: [" + e.getKey()+ "] and value is :" + bioMaterialAnnotationType.get(e.getKey()));
    183186          items.add("biosource");
    184187        }
    185         //Tab2MageHelper.write(".....checking factor value map");
    186188        if (factorValueAnnotationType.containsKey(e.getKey()))
    187189        {
    188           //Tab2MageHelper.write("Found Factor Value key: [" + e.getKey()+ "] and value is :" + factorValueAnnotationType.get(e.getKey()));
    189190          items.add("rawbioassay");
    190191        }
    191              
    192192        AnnotationTypeFileMapping at = new AnnotationTypeFileMapping(name, valuetype, parameter,items);
    193193        annotationTypeFileMappings.add(at);
     
    197197    {
    198198      log.error("Annotation File cannot be created");
    199       t.printStackTrace();
    200      
     199           
    201200    }
    202201    return annotationTypeFileMappings;
     
    233232    try
    234233    {
    235       //Tab2MageHelper.write("creating the subdirectory ....");
    236234      if (!Directory.exists(dc, dir, directoryName))
    237235      {
     
    240238        dc.saveItem(subDir);
    241239      }
    242       Tab2MageHelper.write("creating the file.....");       
     240      log.info("creating the file.....");       
    243241      // create a file : filename into the subdirectory (temp) created above
    244242      file =  File.getFile(dc, subDir, filename, true);
     
    263261    {
    264262      log.error("Error: " + tex.getMessage());
    265       tex.printStackTrace();
    266263      throw new NutribasePluginException("Temporary File cannot be created");
    267264    }
     
    278275    return file;
    279276  }
     277/**
     278    check if the hybridization headers contain Protocol[pool]
     279      @return TRUE if yes and FALSE otherwise.
     280   */
     281  public boolean checkForPoolingProtocol()
     282  {
     283    boolean pooled = header.contains(Tab2MageConstants.protocol_pool.getName())? true : false;
     284    return pooled;
     285  }
     286  // if pooled do handlepool()
     287  public void handlePool()
     288  {
     289    //call checkForPoolingProtocol and if pooled?
     290    Map<String, String> BioSourceSampleMap= new HashMap<String,String>();
     291    Map<String, String> SampleExtractMap= new HashMap<String,String>();
     292    Map<String, String> ExtractLabeledExtractMap= new HashMap<String,String>();
     293   
     294    // clear maps of parent child relationships
     295    if (!BioSourceSampleMap.isEmpty()) BioSourceSampleMap.clear();
     296    if (!SampleExtractMap.isEmpty()) SampleExtractMap.clear();
     297    if (!ExtractLabeledExtractMap.isEmpty()) ExtractLabeledExtractMap.clear();
     298    try
     299    {
     300      for (Tab2MAGEHybridization hyb: hybs)
     301      {
     302        for (Tab2MAGEHybridizationLine line : hyb.getLines())
     303        {
     304          // populate maps of parent child relationships
     305          BioSourceSampleMap.put(line.getBioSource(), line.getSample());
     306          SampleExtractMap.put(line.getSample(), line.getExtract());
     307          ExtractLabeledExtractMap.put(line.getExtract(), line.getLabeledExtract());
     308        }
     309      }
     310     
     311      SampleExractPoolMap.putAll(getParentChildMap(SampleExtractMap));
     312      BioSourceSamplePoolMap.putAll(getParentChildMap(BioSourceSampleMap));
     313      ExractLabeledExtractPoolMap.putAll(getParentChildMap(ExtractLabeledExtractMap));
     314    }
     315    catch(Throwable tr)
     316    {
     317      log.error("cannot processing pooling" + tr.getMessage());
     318    }
     319  }
     320 
     321  private Map<String, List<String>> getParentChildMap(Map<String, String> childParentMap)
     322  {
     323    Map<String, List<String>> map = new HashMap<String, List<String>>();
     324    for (Map.Entry<String, String> childParentEntry : childParentMap.entrySet())
     325    {
     326      String child= childParentEntry.getValue();
     327      List<String> parents= getParents(child, childParentMap);
     328      if (parents.size()>=2) // means that the child has more than one parents
     329      {
     330        map.put(child, parents);
     331      }
     332    }
     333    return map;
     334  }
     335 
     336  private List<String> getParents(String child, Map<String, String> childParentMap)
     337  {
     338    List<String> parents= new ArrayList<String>();
     339    //if (!child.equals("")|| child.length()>=1 )
     340    if (!child.equals("") && child.length()>=1 ) //ensure that child is not an empty string
     341    {
     342      for (Map.Entry<String, String> entry : childParentMap.entrySet())
     343      {
     344        if (child.equalsIgnoreCase(entry.getValue()))
     345        {
     346          parents.add(entry.getKey());
     347        }
     348      }
     349    }
     350    return parents;
     351  }
     352
     353  public Map<String, List<String>> getBioSourceSamplePoolMap()
     354  {
     355    return BioSourceSamplePoolMap;
     356  }
     357
     358  public Map<String, List<String>> getExractLabeledExtractPoolMap()
     359  {
     360    return ExractLabeledExtractPoolMap;
     361  }
     362
     363  public Map<String, List<String>> getSampleExractPoolMap()
     364  {
     365    return SampleExractPoolMap;
     366  }
    280367}
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/validation/Tab2MageValidationFactory.java

    r362 r374  
    1010import java.util.Arrays;
    1111import java.util.List;
     12import java.util.Map;
    1213import java.util.Set;
    1314
     
    5253   private static Set<Tab2MAGEProtocol> catchedProtocol=null;
    5354   private static ArrayList<Tab2MAGEHybridization> catchedHybs=null;
     55   
     56   private static Map<String , List<String>> sampleExtractMap= null;
     57   private static Map<String, List<String>> bioSourceSampleMap =null;
     58   private static Map<String, List<String>>  extractLabeledExtractMap = null;
     59   
    5460   /**
    5561      Filename with extension e.g tab2mage.txt
     
    6066    */
    6167   private Directory dir;
     68   /**
     69      the db control created from session
     70    */
    6271   private DbControl dc;
     72   /**
     73      session control passed as parameter on creating this class
     74    */
    6375   private SessionControl sc;
    6476   /**
     
    8193   
    8294  private Tab2MAGEExperiment tExperiment;
     95/**
     96      variable that indicates if experiment is pooled or not.
     97    */
     98   private boolean pooled;
     99
    83100   /**
    84101     
     
    91108      @param expPlatform
    92109    */
    93   public Tab2MageValidationFactory(String fileName, DbControl dControl, Directory fileDirectory, String expPlatform)
     110  public Tab2MageValidationFactory(String fileName, SessionControl sControl, Directory fileDirectory, String expPlatform)
    94111  {
    95112    filename= fileName;
    96     dc = dControl;
    97     sc =  dc.getSessionControl();
     113    dc = sControl.newDbControl();
     114    sc = sControl;
    98115    dir=fileDirectory;
    99116    platform= expPlatform;
    100     //this call the Tab2mage file validation routine
    101     Tab2MageHelper.write("About to begin tab2mage file validation");
     117    //this calls the Tab2mage file validation routine
    102118    validateTab2MageFile();
    103119  }
     
    152168      if (isFileValid)
    153169      {
    154         //Tab2MageHelper.write("Is the tab2magefile format valid? "  + isFileValid);
    155170        //  parse and read the tab2magefile
    156171        reader = new Base2Tab2MageFileReader(tab2MageFile, dc);
     
    158173       
    159174        //validate experiment
    160         Tab2MageHelper.write("Begin Experiment validation");
     175        log.info("Begin Experiment validation");
    161176        tExperiment= reader.getExperiment();
    162177        Tab2MageExperimentValidation experimentVal= new Tab2MageExperimentValidation(reader);
    163178        boolean expValidated= experimentVal.validate(); // return true or false
    164179       
    165         //Tab2MageHelper.write(expValidated ? "yes the exp is validated" : "No exp is not validated");
    166180        if (!expValidated)
    167181        {
     
    169183          throw new NutribasePluginException("SORRY: The experiment section of the tab2mage file: " +filename+ " is invalid. Must be rectified to proceed");
    170184        }
    171         Tab2MageHelper.write("Finished  experiment validation");   
     185        log.info("Finished  experiment validation");   
    172186       
    173187        //validate protocols
    174188        if (dc == null || !dc.isConnected() || dc.isClosed()) //dc = dir.getDbControl();
    175189          dc= sc.newDbControl();
    176         Tab2MageHelper.write("Begin Protocol validation");
     190        log.info("Begin Protocol validation");
    177191        Set<Tab2MAGEProtocol> protocols = reader.getProtocols(); // we get all the  protocols
    178192        Tab2MageProtocolValidation protocolVal= new Tab2MageProtocolValidation(protocols, dc);
     
    183197          throw new NutribasePluginException("SORRY: The protocol section of the tab2mage file: " +filename+ " is invalid. Must be rectified to proceed. See the log file for more details");
    184198        }
    185         // Display the protocols only for debugging     
    186         //Tab2MageHelper.write("\n+++++++++++++++++++++++ALL THE PROTOCOLS++++++++++++++++++++++++++++++++++++++\n");
    187         //for (Tab2MAGEProtocol p : protocols)
    188         //{
    189         //  Tab2MageHelper.write(p.getAccession()+ "\t" +p.getText()+ "\t" +p.getName() + "\t" +p.getType()+ "\t" +p.getParameters());
    190         //}
    191         //Display all the parameters, only for debugging
    192        
    193         //Tab2MageHelper.write("\n++++++++++++++++++++ The parameters ++++++++++++++\n");
    194         //List<String> params= protocolVal.getProtocolParameters();
    195         //for (String p : params)
    196         //{
    197         //  Tab2MageHelper.write(p);
    198         //}
    199              
    200         Tab2MageHelper.write("Finished  protocol validation");
     199                     
     200        log.info("Finished  protocol validation");
    201201       
    202202        /*
     
    204204        */
    205205        if (dc == null || !dc.isConnected()) dc = sc.newDbControl();
    206         Tab2MageHelper.write("Begin Hybridization validation");
     206        log.info("Begin Hybridization validation");
    207207        ArrayList<Tab2MAGEHybridization> hybs = reader.getHybridizations();
    208208       
    209         //Tab2MageHelper.write( "Finished getting hybs from the reader object, now +++++ listing hyb names+++++ ");
    210         //for (Tab2MAGEHybridization hyb : hybs)
    211         //{
    212         //  System.out.printf("\nThe hyridization name for this hyb is %s\n",hyb.getName());
    213         //}
    214209          // validate headers
    215210        boolean validateHeaders= Tab2MageHybridizationValidation.validateHeader(new ArrayList<String>(Arrays.asList(reader.getHeaders())));
     
    220215        }
    221216          //validate rows /lines
    222         //Tab2MageHelper.write("Begin validate hyb rows after headers"); //NOTE: the db control is closed here
     217         
    223218        Tab2MageHybridizationValidation validateHyb = new Tab2MageHybridizationValidation(dir, platform, hybs, reader, dc);
    224219        if (!validateHyb.validate())
     
    227222          throw new ValidationException("There is an error in the Tab2Mage Hybridization section!");
    228223        }
    229         Tab2MageHelper.write("Finished  Hybridization validation");
     224        log.info("Finished  Hybridization validation");
    230225        //NOTE: the db control is closed here
    231226       
     
    233228         
    234229        if (dc == null || !dc.isConnected() || dc.isClosed()) dc = sc.newDbControl();
    235         //Tab2MageHelper.write("\n+++++++++++ List AT - value type map ++++++++++++++\n ");
     230       
    236231        Tab2MageImportValidatorUtils utils = new Tab2MageImportValidatorUtils(hybs, new ArrayList<String>(Arrays.asList(reader.getHeaders())));
    237232        utils.initialiseMaps();
     
    239234       
    240235        tab2MageFile= File.getByPath(dc, tab2MageFile.getPath(), false); 
    241         //Tab2MageHelper.write("create file and directory");
     236       
    242237        String filename= "anntype.txt";
    243         Tab2MageHelper.write("The ta2mage file mime and file type is: " + tab2MageFile.getMimeType()+ " -- "+tab2MageFile.getFileType());
    244        
    245238        utils.createFile(sc, dir, "tempAT",  tab2MageFile.getMimeType(),tab2MageFile.getFileType() , filename);
    246         //Tab2MageHelper.write("Finished createFiles()");
    247239        atFile = utils.getFile();
    248240       
     
    253245        writer.writeFile();
    254246        dc.commit();
    255         Tab2MageHelper.write("Writing file :"+atFile.getName()+ "completed!");       
     247       
     248        log.info("Writing temporary annotation type file :"+atFile.getName()+ "completed!");       
    256249       
    257250        /*
     
    259252           
    260253         */
    261         //System.out.println("The experiment platform is :"+ platform);
     254       
     255        // [ create a new DC  here because the last one has been closed]
     256       
    262257        if (dc == null || !dc.isConnected() || dc.isClosed()) dc = sc.newDbControl();
    263258        dir= Directory.getByPath(dc, dir.getPath());
    264259        if (platform.equalsIgnoreCase("genepix")) 
    265260        {
    266           Tab2MageHelper.write("Begin GenePix File validation");   
     261          log.info("Begin GenePix File validation");   
    267262          List<File> gprFiles= Tab2MageHelper.getRawDataFiles(dir, dc, platform, filename);
    268263          GenePixFileValidation gprValidation= new GenePixFileValidation(gprFiles, dc);
     
    273268          }
    274269          GenePixValidation.validateRawFiles(hybs);
    275           Tab2MageHelper.write("Finished GenePix File validation");
     270          log.info("Finished GenePix File validation");
    276271        }
    277272        /*
     
    283278          // we need to parse the headers
    284279          // obtain and check if the headers is within the allowed range
    285           Tab2MageHelper.write("Begin Agilent File validation");   
     280          log.info("Begin Agilent File validation");   
    286281          List<File> agFiles= Tab2MageHelper.getRawDataFiles(dir, dc, platform, filename);
    287282          AgilentValidation agValidation= new AgilentValidation(agFiles,dc);
     
    291286            throw new ValidationException("An agilent file is missing once or more mandatory columns!");
    292287          }
    293           Tab2MageHelper.write("Finished Agilent File validation");
     288          log.info("Finished Agilent File validation");
    294289        }
    295290         
     
    320315  }
    321316  /**
    322     returns true if validation is succesful and false otherwise.
     317    returns true if validation is successful and false otherwise.
    323318      @return validated;
    324319   */
     
    363358    get the protocols in the tab2mage File
    364359    @return protocols.
    365  */
     360  */
    366361  public static Set<Tab2MAGEProtocol> getCatchedProtocol()
    367362  {
     
    381376    return tExperiment;
    382377  }
     378 
     379  /**
     380    check if experiment is pooled , indicated by the protocol header.
     381      @return pooled TRUE if pooled indicated by Protocol[pool] and false otherwise.
     382   */
     383  public boolean isPooled()
     384  {
     385    return pooled;
     386  }
     387 
     388  /**
     389    get Sample -to- List of Extract map.
     390      @return  Map<String, List<String>
     391   */
     392  public static Map<String, List<String>> getSampleExtractMap()
     393  {
     394    return sampleExtractMap;
     395  }
     396  /**
     397      get BioSource -to- List of Sample map.
     398      @return map
     399   */
     400  public static Map<String, List<String>> getBioSourceSampleMap()
     401  {
     402    return bioSourceSampleMap;
     403  }
     404  /**
     405     get Extract -to- List of Labeled Extract map.
     406    @return map
     407   */
     408  public static Map<String, List<String>> getExtractLabeledExtractMap()
     409  {
     410    return extractLabeledExtractMap;
     411  }
    383412}
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/util/PluginConfigDetector.java

    r362 r374  
    8484    public PluginConfiguration detectPluginConfig(File exampleFile) throws Exception
    8585    {   
    86       System.out.println("auto-detecting PluginConfiguration");
     86      log.info("auto-detecting PluginConfiguration");
    8787 
    8888      DbControl dc = sc.newDbControl();
     
    126126      {
    127127        log.error("No suitable plugin configuration found for this plugin. Please ensure you have a valid " + pluginType!=null? pluginType.toString(): "" + " configuration in Base2");
    128         x.printStackTrace();
     128       
    129129        throw new Exception("No suitable plugin configuration found for this plugin. Please ensure you have a valid " + pluginType!=null? pluginType.toString(): "" + " configuration in Base2");
    130130      }
     
    173173              if (importer.isImportable(in))
    174174                configs.add(config);
    175               System.out.println("The name of the plugin configuration is: "+config.getName());
     175                  log.info("The name of the plugin configuration found is: "+config.getName());
    176176            }
    177177            else if(pluginType== DetectablePluginTypes.ANNOTATIONTYPES)
     
    190190              configs.add(config);
    191191         }
    192                  
    193           //close the stream
     192           //close the stream
    194193          in.close();
    195194        }
     
    197196      catch (Exception x)
    198197      {
    199         x.printStackTrace();
     198         log.error(x.getMessage());
    200199      }
    201200      return configs;
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/util/Tab2MageHelper.java

    r362 r374  
    255255       //    try to locate the files in subdirectories too. /home/dominic/test/test/ instead
    256256       if (fileQuery.count(dc)==0)
    257          //dir.getSubDirectories();
     257       {
     258         System.out.println( "The direcrtory may already exist");//dir.getSubDirectories();
    258259         return validPlatform;
     260       }
    259261       ItemResultList<File> fileList = fileQuery.list(dc);
    260262       System.out.println("The number of files in Dir : " + dir.getPath()+ " is : " +fileList.size());
     
    271273        if (!ext.equalsIgnoreCase(ExperimentPlatformsLibrary.TXT.getFileExtension()))
    272274        {
    273           System.out.println("++++ Now checking platform +++++++++++");
     275          //System.out.println("++++ Now checking platform +++++++++++");
    274276          ExperimentPlatformsLibrary platform = ExperimentPlatformsLibrary.fromExtension(ext);   
    275277          if (platform!=null) // platform (raw data files provided) is supported
     
    277279            if (platform.getPlatformName().equalsIgnoreCase(rdt.getId())) //does the files match experiment platform?
    278280            {
    279               System.out.println("Platform ["+ platform.getPlatformName() +"] is supported" );
     281              //System.out.println("Platform ["+ platform.getPlatformName() +"] is supported" );
    280282              validPlatform= true;
    281283            }
    282284          } else if (platform == null) //raw data files -platforms are not supported.
    283285          {
    284             System.out.println("Platform not supported. Check the zip file content");
     286            //System.out.println("Platform not supported. Check the zip file content");
    285287            validPlatform= false;
    286288          }
     
    292294     catch (Throwable t)
    293295     {
    294       t.printStackTrace();
     296      // t.printStackTrace();
    295297       return false;
    296298     }
     
    364366     catch (Throwable t)
    365367     {
    366        t.printStackTrace();
     368       //t.printStackTrace();
    367369       throw new NutribasePluginException(t.getMessage());
    368370     }
     
    401403     catch (Throwable t)
    402404     {
    403       t.printStackTrace();
     405      //t.printStackTrace();
    404406      throw new NutribasePluginException(t.getMessage());
    405407     }
     
    586588    return s;
    587589  }
    588  
     590  /**
     591   *
     592   * @param dc
     593   * @param sampleName
     594   */
     595 
     596  public static Sample findSample(DbControl dc, String sampleName)
     597  {
     598    Sample s= null;
     599    ItemQuery<Sample> query = Sample.getQuery();
     600    //query.include(Include.MINE, Include.IN_PROJECT, Include.NOT_REMOVED);
     601    query.include(Include.MINE, Include.NOT_REMOVED);
     602    query.restrict(Restrictions.eq(Hql.property("name"), Expressions.string(sampleName)));
     603    if (query.list(dc).size()!=0)
     604      return query.list(dc).get(0);
     605    else
     606      return s;
     607   
     608   
     609  }
     610  public static Extract findExtract(DbControl dc, String extractName)
     611  {
     612    Extract e= null;
     613    ItemQuery<Extract> query = Extract.getQuery();
     614    //query.include(Include.MINE, Include.IN_PROJECT, Include.NOT_REMOVED);
     615    query.include(Include.MINE, Include.NOT_REMOVED);
     616    query.restrict(Restrictions.eq(Hql.property("name"), Expressions.string(extractName)));
     617    if (query.list(dc).size()!=0)
     618      return query.list(dc).get(0);
     619    else
     620      return e;
     621   
     622  }
    589623 
    590624 
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/util/ZipUnpacker.java

    r362 r374  
    99import java.io.IOException;
    1010import java.io.InputStream;
    11 import java.text.SimpleDateFormat;
    12 import java.util.Date;
    13 import java.util.Locale;
    1411import java.util.zip.ZipEntry;
    1512import java.util.zip.ZipInputStream;
    16 
    17 import org.apache.log4j.Logger;
    18 
    19 import uk.ac.ebi.nugo.plugins.tab2mageimport.validation.Tab2MageValidationFactory;
    2013
    2114import net.sf.basedb.core.DbControl;
     
    2316import net.sf.basedb.core.File;
    2417import net.sf.basedb.core.Location;
    25 import net.sf.basedb.core.Path;
    26 import net.sf.basedb.core.SessionControl;
    27 import net.sf.basedb.core.Path.Type;
     18import net.sf.basedb.core.PluginDefinition;
    2819import net.sf.basedb.core.Quota;
    2920import net.sf.basedb.core.QuotaType;
     21import net.sf.basedb.core.SessionControl;
    3022import net.sf.basedb.core.SystemItems;
    3123import net.sf.basedb.core.User;
    32 import net.sf.basedb.core.PluginDefinition;
    3324import net.sf.basedb.util.zip.FileUnpacker;
     25
     26import org.apache.log4j.Logger;
    3427
    3528
     
    4639public class ZipUnpacker
    4740{
    48   protected static Logger log = Logger.getLogger(Tab2MageValidationFactory.class);
     41  protected static Logger log = Logger.getLogger(ZipUnpacker.class);
    4942  private User user;
    5043  private File file;
     
    5548  private SessionControl sc;
    5649 
    57   public ZipUnpacker(File zipFile, User user, DbControl dc)
     50  public ZipUnpacker(File zipFile, User user, SessionControl sc)
    5851  {
    5952    this.user = user;
    60     this.dc=dc;
     53    this.dc=sc.newDbControl();
    6154    this.file= zipFile;
    62     this.sc= dc.getSessionControl();
     55    //this.sc= dc.getSessionControl();
    6356  }
    6457  /**
    6558    Unpacks a zip file, checking that there is enough space to accommodate
    6659    the zip file once it is unpacked.
    67    * @throws NutribasePluginException
     60      @throws NutribasePluginException
    6861   */
    6962  public void unpack() throws NutribasePluginException
    7063  {
    71     System.out.println("Begin to unpack the files");
     64    log.info("Begin to unpack the files");
    7265    try
    7366    {
     
    9487    catch (Throwable exc)
    9588    {
     89      dc.close();
     90      log.info("File cannot be unpacked", exc);
    9691      new NutribasePluginException(exc.getMessage());
    9792    }
    9893    finally
    9994    {
    100      
     95      if (dc!=null)
     96        dc.close();
    10197    }
    10298  }
     
    160156      catch (IOException ioe)
    161157      {
    162         ioe.printStackTrace();
     158        //ioe.printStackTrace();
     159        log.error(ioe.getMessage());
    163160      }
    164161      return totalSize;
    165162    }
    166  
     163  /**
     164    create a sub-directory to contain the unzip files
     165    @param zipFile, the zip file to unpack
     166    @param user, currently logged-in user
     167    @param dc, the database control
     168   */
    167169  public void createSubDirectory(File zipFile, User user , DbControl dc)
    168170  {
     
    170172     
    171173        Directory zipFileDir = zipFile.getDirectory();
    172         System.out.println("zipFile is located in dir " + zipFileDir.toString());
     174        log.info("zipFile is located in dir " + zipFileDir.toString());
    173175        Directory subDir = Directory.getNew(dc, zipFileDir);
    174176        String fileName = zipFile.getName();
Note: See TracChangeset for help on using the changeset viewer.