From: Gildas Le C. <lec...@sb...> - 2010-02-09 13:29:17
|
Index: Tab2MageExporter/ChangeLog.txt =================================================================== --- Tab2MageExporter/ChangeLog.txt (revision 1186) +++ Tab2MageExporter/ChangeLog.txt (working copy) @@ -1,5 +1,13 @@ ,____This file will contain information about changes in subsequent releases. -Latest version 2.0 +version 1.0 - Pooling of biomaterials - Pooled sample, extract, and labeled extract are now supported in this release. - Redesigned code to improve reuse. + +version 1.01 : 08/02/2010 - lecorguille +- Fix a problem with pooling which was not supported ... for me +- Modification : Filenames are use instead of RawBioAssays' names for File[raw] column in the Hybridization section +- Add the possibility to have several Files[raw] per RawBioAssay (ex : one cy3 and one cy5) +- Add a scan column in the Hybridization section +- Add a BioSourceDescription column in the Hybridization section +- Fix a problem with protocols in the Hybridization section Index: Tab2MageExporter/lib/BASE2Core.jar =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: Tab2MageExporter/lib/BASE2WSClient.jar =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: Tab2MageExporter/lib/BASE2WSClient.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Index: Tab2MageExporter/lib/BASE2CorePlugins.jar =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageFileWriter.java =================================================================== --- Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageFileWriter.java (revision 1186) +++ Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageFileWriter.java (working copy) @@ -61,6 +61,15 @@ @author Dominic Oyeniran @email oye...@eb.../doy...@gm... @version 1.0 + + @author Gildas Le Corguillé + @email lec...@sb... + @version 1.01 + + ChangeLog : + 05/02/2010 - lecorguille : addition of a Scan column to the output file + 08/02/2010 - lecorguille : addition of a BioSourceDescription column to the output file + displaying of the protocol descriptions in one line */ public class Tab2MageFileWriter { @@ -83,8 +92,10 @@ //OutputStreamWriter is used so that characters written to it are encoded into bytes using a specified charset for all out= new BufferedWriter(new OutputStreamWriter(outputFile.getUploadStream(false),encoding)); statusOut= new BufferedWriter(new OutputStreamWriter(statusFile.getUploadStream(false),encoding)); + + statusOut.write(" Please check the messages below for the status of the export\n\n"); } - catch(UnsupportedEncodingException e) + catch (IOException e) { new NutribasePluginException(e.getMessage()); } @@ -138,8 +149,8 @@ { try { - statusOut.write(" Please check the messages below for the status of the export"); //not part of experiment and may be moved elsewhere. + out.write("# This file contains an experiment exported in tab2mage specification from BASE\n\n"); out.write("Experiment section \n"); out.write(Tab2MageConstants.domain.getName()+"\t"+Application.getHostName()+"\n"); @@ -150,7 +161,7 @@ String description = experiment.getDescription()!=null && experiment.getDescription().length()!=0 ? experiment.getDescription(): ValueFormatter.getEmptyStringIfNull(experiment.getAbstract()).toString(); out.write(Tab2MageConstants.description.getName()+"\t"+description +"\n"); out.write(Tab2MageConstants.release_date.getName()+"\t"+job.getValue("releaseDate").toString()+"\n"); - out.write(Tab2MageConstants.submission_date.getName()+"\t"+Values.formatDate(new Date())+"\n"); + out.write(Tab2MageConstants.submission_date.getName()+"\t"+ValueFormatter.DATE_FORMAT.format(new Date())+"\n"); out.write(Tab2MageConstants.submitter.getName()+"\t"+experiment.getOwner().getName()+"\n"); out.write(Tab2MageConstants.submitter_email.getName()+"\t"+ValueFormatter.getEmptyStringIfNull(experiment.getOwner().getEmail())+"\n"); out.write(Tab2MageConstants.organization.getName()+"\t"+ ValueFormatter.getEmptyStringIfNull(experiment.getOwner().getOrganisation()) +"\n"); @@ -170,6 +181,7 @@ response.setError(ex.getMessage(), Arrays.asList(ex)); } } + /** writes Tab2Mage protocol section @param protocols, list of protocols to write @@ -190,7 +202,7 @@ if (protocol!=null) { out.write("P-BASE-"+protocol.getId()+"\t"); - out.write(ValueFormatter.getEmptyStringIfNull(protocol.getDescription())+"\t"); + out.write(ValueFormatter.getStringWithoutLineBreaker(String.valueOf(ValueFormatter.getEmptyStringIfNull(protocol.getDescription())))+"\t"); out.write(ValueFormatter.getEmptyStringIfNull(protocol.getName())+"\t"); out.write(ValueFormatter.getEmptyStringIfNull(protocol.getProtocolType().getName())+"\t"); ItemQuery<AnnotationType> parameterQuery= protocol.getParameters(); @@ -247,11 +259,11 @@ } /** + * @deprecated Tab2Mage Hybridization Channel Line Section @param hybDataRow, the data rows to display @param response, the response object to return failures or exceptions */ - public static void writeTab2MageHybridizationRow( List<String> hybDataRows,Response response) { try @@ -276,6 +288,7 @@ response.setError(ex.getMessage(), Arrays.asList(ex)); } } + /** write the Tab2Mage File Hybridization Section @param hybList, the list of Hybridizations @@ -285,7 +298,6 @@ @param factorValueHeaders, experimental section header @param response, response object */ - private static void writeTab2MageHybridizationRows(List<Tab2MageHybridization> hybList,Set<String> bioXterHybSectionHeader, Set<String> protocolHeaders,Set<String>parameterHeaders,Set<String>factorValueHeaders, Response response) @@ -299,7 +311,6 @@ out.write(ValueFormatter.getEmptyStringIfNull(h.getLine().getFileRaw())+"\t") ; tempList.add(ValueFormatter.getEmptyStringIfNull(h.getLine().getFileRaw())+"\t"); - int channelNo = h.getChannelNumber(); Tab2MageHybridizationLine l= h.getLine(); @@ -343,6 +354,10 @@ Map<String, String> parameterMap = new HashMap<String, String>(); parameterMap.putAll(l.getParameter()); + //Scan + out.write(ValueFormatter.getEmptyStringIfNull(l.getScan())+"\t") ; + tempList.add(ValueFormatter.getEmptyStringIfNull(l.getScan())+"\t") ; + //Hybridization out.write(ValueFormatter.getEmptyStringIfNull(l.getHybridization())+"\t") ; tempList.add(ValueFormatter.getEmptyStringIfNull(l.getHybridization())+"\t") ; @@ -365,6 +380,7 @@ out.write(ValueFormatter.getEmptyStringIfNull(sl.getExtract())+"\t") ; out.write(ValueFormatter.getEmptyStringIfNull(sl.getSample())+"\t") ; out.write(ValueFormatter.getEmptyStringIfNull(sl.getBioSource())+"\t") ; + out.write(ValueFormatter.getEmptyStringIfNull(sl.getBioSourceDescription())+"\t") ; // biomaterial xteristics @@ -411,6 +427,8 @@ } } + /** NOT USE + * @deprecated */ public static void createZipFile(User user, File tab2mageFile, DbControl dc ) { Directory dir= user.getHomeDirectory(); @@ -425,13 +443,16 @@ } - /** + + /** closes the file writers */ public static void closeWriter() { try { + out.flush(); + statusOut.flush(); if (out!= null) out.close(); if (statusOut!=null) statusOut.close(); } @@ -463,7 +484,7 @@ { return statusOut; } - + static void setStatusOut(Writer statusOut) { Tab2MageFileWriter.statusOut = statusOut; Index: Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/ExportHelper.java =================================================================== --- Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/ExportHelper.java (revision 1186) +++ Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/ExportHelper.java (working copy) @@ -1,18 +1,24 @@ package uk.ac.ebi.nugo.plugins.ta2mageexport; +import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import net.sf.basedb.core.Affymetrix; import net.sf.basedb.core.Annotatable; import net.sf.basedb.core.AnnotationType; +import net.sf.basedb.core.ArrayDesign; import net.sf.basedb.core.BaseException; import net.sf.basedb.core.BioSource; import net.sf.basedb.core.DbControl; import net.sf.basedb.core.Directory; import net.sf.basedb.core.Extract; +import net.sf.basedb.core.File; +import net.sf.basedb.core.FileSetMember; import net.sf.basedb.core.Hybridization; +import net.sf.basedb.core.ItemQuery; import net.sf.basedb.core.ItemResultList; import net.sf.basedb.core.LabeledExtract; import net.sf.basedb.core.MeasuredBioMaterial; @@ -22,6 +28,7 @@ import net.sf.basedb.core.Sample; import net.sf.basedb.core.SessionControl; import net.sf.basedb.core.User; +import net.sf.basedb.core.plugin.Response; import uk.ac.ebi.nugo.common.Tab2MageConstants; /** @@ -29,11 +36,28 @@ [TODO] This class may be merged to other utils in the main base 2 source code @author Dominic Oyeniran @version 1.0 + + + @author Gildas Le Corguillé + @email lec...@sb... + @version 1.01 + + ChangeLog : + 05/02/2010 - lecorguille : modifification of the getItems fonctions to allow pooling + 05/02/2010 - lecorguille : substitution of RawBioAssay names in the File[Raw] be the filenames + */ public class ExportHelper { - public static Set<Sample> getSamples(Annotatable item, DbControl dc) + + /** + * @deprecated by lecorguille + * @param item + * @param dc + * @return + */ + public static Set<Sample> getSamplesBk(Annotatable item, DbControl dc) { Set<Sample> itemList= new LinkedHashSet<Sample>(); Set<Annotatable> pooledObjects= item.getAnnotatableParents(); @@ -53,13 +77,14 @@ } /** + * @deprecated by lecorguille gets a sample from extract. returns the first item at random, if extract is pooled @param extract, extract item @param dc, the database control @return Sample */ - public static Sample getSample(Annotatable extract, DbControl dc) + public static Sample getSampleBk(Annotatable extract, DbControl dc) { Sample sample=null; Set<Annotatable> sampleOrPooledExtracts= extract.getAnnotatableParents(); //returns sample and pooled extract @@ -86,13 +111,14 @@ } /** + * @deprecated by lecorguille gets an extract from a labeled extract. returns the first item at random, if labeled extract is pooled @param labeledExtract, labeled extract item @param dc, the database control @return extract */ - public static Extract getExtract(Annotatable labeledExtract, DbControl dc) + public static Extract getExtractBk(Annotatable labeledExtract, DbControl dc) { Extract extract=null; Set<Annotatable> extractOrPooledLabeledExtracts= labeledExtract.getAnnotatableParents(); //returns sample and pooled extract @@ -117,29 +143,14 @@ } return extract; } - - - public static Set<Extract> getExtracts(Annotatable item, DbControl dc) - { - Set<Extract> itemList= new LinkedHashSet<Extract>(); - Set<Annotatable> pooledObjects= item.getAnnotatableParents(); - for (Annotatable pooled: pooledObjects) - { - if (pooled instanceof LabeledExtract) - { - Set<Annotatable> extracts= pooled.getAnnotatableParents(); - for (Annotatable extractItem: extracts) - { - Extract extract= Extract.getById(dc, extractItem.getId()); - itemList.add(extract); - } - } - } - return itemList; - } - - public static Set<BioSource> getBiosources(MeasuredBioMaterial item, DbControl dc) + /** + * @deprecated by lecorguille + * @param item + * @param dc + * @return + */ + public static Set<BioSource> getBiosourcesBk(MeasuredBioMaterial item, DbControl dc) { Set<BioSource> bioSourceList= new LinkedHashSet<BioSource>(); Set<Annotatable> pooledSamples= item.getAnnotatableParents(); @@ -158,16 +169,15 @@ return bioSourceList; } - /** + * @deprecated by lecorguille gets a biosource from sample. returns the first item at random, if sample is pooled @param sample, sample item @param dc. the database control @return BioSource */ - - public static BioSource getBioSource(Annotatable sample, DbControl dc) + public static BioSource getBioSourceBk(Annotatable sample, DbControl dc) { BioSource biosource=null; Set<Annotatable> biosourceOrPooledSample= sample.getAnnotatableParents(); //returns biosource and pooled samples @@ -195,6 +205,189 @@ } /** + * @author lecorguille + * Return a Extract from a non-pooling LabeledExtract. + * @param labeledExtract + * @param dc the database control + * @return Extract + */ + private static Extract getExtract(LabeledExtract labeledExtract, DbControl dc) { + Extract extract=null; + + Set<Annotatable> extractAnnots = labeledExtract.getAnnotatableParents(); + for (Annotatable extractAnnot : extractAnnots) { + extract = Extract.getById(dc, extractAnnot.getId()); + } + return extract; + } + + /** + * @author lecorguille + * Return a set of Extract from a LabeledExtract. + * this method can return several Extracts if there is a LabeledExtract pooling + * @param labeledExtract + * @param dc the database control + * @return Set<Extract> + */ + public static Set<Extract> getExtracts(LabeledExtract labeledExtract, DbControl dc) { + + Set<Extract> itemList= new LinkedHashSet<Extract>(); + + // not pooled + if (!labeledExtract.isPooled()) { + itemList.add(getExtract(labeledExtract, dc)); + } + // pooled + else { + Set<Annotatable> labeledExtractPoolAnnots = labeledExtract.getAnnotatableParents(); + for (Annotatable labeledExtractPoolAnnot : labeledExtractPoolAnnots) { + LabeledExtract labeledExtractPooled = LabeledExtract.getById(dc, labeledExtractPoolAnnot.getId()); + itemList.add(getExtract(labeledExtractPooled, dc)); + } + } + + return (itemList); + } + + /** + * @author lecorguille + * Return a Sample from a non-pooling Extract. + * @param extract + * @param dc the database control + * @return Sample + */ + private static Sample getSample(Extract extract, DbControl dc) { + Sample sample=null; + + Set<Annotatable> sampleAnnots = extract.getAnnotatableParents(); + for (Annotatable sampleAnnot : sampleAnnots) { + sample = Sample.getById(dc, sampleAnnot.getId()); + } + return sample; + } + + /** + * @author lecorguille + * Return a set of Sample from a Extract. + * this method can return several Samples if there is a Extract pooling + * @param extract + * @param dc the database control + * @return Set<Sample> + */ + public static Set<Sample> getSamples(Extract extract, DbControl dc) + { + Set<Sample> itemList= new LinkedHashSet<Sample>(); + + // not pooled + if (!extract.isPooled()) { + itemList.add(getSample(extract, dc)); + } + // pooled + else { + Set<Annotatable> extractPoolAnnots = extract.getAnnotatableParents(); + for (Annotatable extractPoolAnnot : extractPoolAnnots) { + Extract extractPooled = Extract.getById(dc, extractPoolAnnot.getId()); + itemList.add(getSample(extractPooled, dc)); + } + } + + return (itemList); + } + + /** + * @author lecorguille + * Return a Biosource from a non-pooling Sample. + * @param sample + * @param dc the database control + * @return BioSource + */ + private static BioSource getBioSource(Sample sample, DbControl dc) { + BioSource bioSource=null; + + Set<Annotatable> bioSourceAnnots = sample.getAnnotatableParents(); + for (Annotatable bioSourceAnnot : bioSourceAnnots) { + bioSource = BioSource.getById(dc, bioSourceAnnot.getId()); + } + return bioSource; + } + + /** + * @author lecorguille + * Return a set of Biosource from a Sample. + * this method can return several Biosources if there is a Sample pooling + * @param sample + * @param dc the database control + * @return Set<BioSource> + */ + public static Set<BioSource> getBioSources(Sample sample, DbControl dc) + { + Set<BioSource> itemList= new LinkedHashSet<BioSource>(); + + // not pooled + if (!sample.isPooled()) { + itemList.add(getBioSource(sample, dc)); + } + // pooled + else { + Set<Annotatable> samplePoolAnnots = sample.getAnnotatableParents(); + for (Annotatable samplePoolAnnot : samplePoolAnnots) { + Sample samplePooled = Sample.getById(dc, samplePoolAnnot.getId()); + itemList.add(getBioSource(samplePooled, dc)); + } + } + + return (itemList); + } + + /** + * @author lecorguille + * Return a set of Tab2MageHybridizationLine from a RawBioAssay. + * This method can return several lines if there is several Files for the RawBioAssay (ex: Nimblegen 2 channels <=> 2 files per scan) + * @param rba + * @param dc the database control + * @param response + * @return Set<Tab2MageHybridizationLine> + * @TODO use non-deprecated methods for Affymetrix + * @TODO it's not very clean but it's work without huge modifications + */ + public static Set<Tab2MageHybridizationLine> getRawBioAssayFiles(RawBioAssay rba, DbControl dc, Response response) { + Set<Tab2MageHybridizationLine> itemList= new LinkedHashSet<Tab2MageHybridizationLine>(); + + try + { + if (rba.getArrayDesign().isAffyChip()) + { + Tab2MageHybridizationLine hybRow = new Tab2MageHybridizationLine(); + + File celFile=Affymetrix.getCelFile(rba); + File cdfFile= Affymetrix.getCdfFile(rba.getArrayDesign()); + + hybRow.set("File", Tab2MageConstants.raw_file.getName(), celFile.getName()); + hybRow.set("File",Tab2MageConstants.cdf_file.getName(), cdfFile.getName()); + + itemList.add(hybRow); + } + else + { + ItemQuery<FileSetMember> fileSetMemberQuery =(ItemQuery<FileSetMember>) rba.getFileSet().getMembers(); // get all the labeled extract + ItemResultList<FileSetMember> fileSetMembers= fileSetMemberQuery.list(dc); + + for (FileSetMember fileSetMember :fileSetMembers) { + Tab2MageHybridizationLine hybRow = new Tab2MageHybridizationLine(); + hybRow.set("File", Tab2MageConstants.raw_file.getName(), fileSetMember.getFile().getName()); + itemList.add(hybRow); + } + } + } + catch(Throwable tr) + { + response.setError(tr.getMessage(), Arrays.asList(tr)); + } + + return itemList; + } + + /** Gets the base format id for the protocols in the Tab2Mage Protocol Section, if protocol is null an empty string is returned this is required to have consistent tab delimited format @@ -226,7 +419,6 @@ return at.getDefaultValue()!=null? at.getDefaultValue():""; } - /** creates the header from Hybridization Section header data structure @@ -234,7 +426,6 @@ @return the set of hybridization section headers */ - @SuppressWarnings("unchecked") public static Set<String> createHybridizationSectionHeader( DbControl dc, List<Tab2MageHybridization> hybList, Set<String> bioXterHybSectionHeader, Set<String> protocolHybSectionHeader, Set<String> parameterHybSectionHeader, Set<String> factorValuesHybSectionHeader) @@ -265,6 +456,9 @@ { hybHeader.add("FactorValue["+factorValueHeader+"]"); } + + if (l.getScan()!=null && l.getScan().length()!=0) + hybHeader.add(Tab2MageConstants.scan.getName()); if (l.getHybridization()!=null && l.getHybridization().length()!=0) hybHeader.add(Tab2MageConstants.hybridization.getName()); @@ -310,7 +504,6 @@ return hybHeader; } - /** create the set of protocol objects for the tab2mage protocol section each protocol object maps to a line of the protocol section of the tab2mage file @@ -344,20 +537,23 @@ protocols.add(lbExtractProtocol); // add extract protocol - Extract extract= getExtract(labeledExtract, dc); - if (extract!=null) - { - Protocol extractProtocol =extract.getCreationEvent().getProtocol(); - protocols.add(extractProtocol); + Set<Extract> extracts = ExportHelper.getExtracts(labeledExtract, dc); + for (Extract extract : extracts) { + if (extract!=null) + { + Protocol extractProtocol =extract.getCreationEvent().getProtocol(); + protocols.add(extractProtocol); + } + // add sample protocol + Set<Sample> samples = ExportHelper.getSamples(extract, dc); + for (Sample sample : samples) { + if (sample != null) + { + Protocol sampleProtocol=sample.getCreationEvent().getProtocol(); + protocols.add(sampleProtocol); + } + } } - // add sample protocol - - Sample sample = getSample(extract, dc); - if (sample != null) - { - Protocol sampleProtocol=sample.getCreationEvent().getProtocol(); - protocols.add(sampleProtocol); - } } } return protocols; @@ -389,6 +585,7 @@ } return p; } + /** utility method for the tab2mage exporter it ges the only the Keys mapped to not null and not empty ("") values in a map. Index: Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageHybridization.java =================================================================== --- Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageHybridization.java (revision 1186) +++ Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageHybridization.java (working copy) @@ -37,6 +37,15 @@ @author Dominic Oyeniran @email oye...@eb.../doy...@gm... + @version 1.0 + + + @author Gildas Le Corguillé + @email lec...@sb... + @version 1.01 + + ChangeLog : + 05/02/2010 - lecorguille : addition of SCAN */ public class Tab2MageHybridization { @@ -44,11 +53,13 @@ protected static Logger log = Logger.getLogger(Tab2MageHybridization.class); public static final String BIOSOURCE = "BioSource"; + public static final String BIOSOURCEDESCRIPTION = "BioSourceDescription"; public static final String SAMPLE = "Sample"; public static final String EXTRACT = "Extract"; public static final String LABELEDEXTRACT = "LabeledExtract"; public static final String DYE = "Dye"; public static final String HYBRIDIZATION = "Hybridization"; + public static final String SCAN = "Scan"; public static final String BIOMATERIALCHARACTERISTICS = "BioMaterialCharacteristics"; public static final String PROTOCOL = "Protocol"; public static final String PARAMETER = "Parameter"; @@ -123,6 +134,7 @@ /** + * @deprecated by lecorguille Get the size of the <code>Tab2MageHybridization</code> object. The size is the number of <code>Tab2MageHybridizationLine</code> objects stored. @@ -141,6 +153,7 @@ } /** + * @deprecated by lecorguille Get the set of all <code>Tab2MageHybridizationLine</code> objects. @return A <code>HashMap</code> with a String as key and a <code>TAB2MAGEHybridizationLine</code> as value */ @@ -150,6 +163,7 @@ } /** + * @deprecated by lecorguille Get the name of the raw data file. @return The name of the raw data file */ @@ -177,6 +191,7 @@ /** + * @deprecated by lecorguille Get the information about the Array[...] entries in the Tab2Mage files. @return a <code>HashMap</code> with the information from the Array entries. @@ -203,6 +218,7 @@ /** + * @deprecated by lecorguille Has the Hyb object a pooled property */ public boolean isPooled() @@ -210,6 +226,7 @@ return pooled; } /** + * @deprecated by lecorguille check if the Hyb line object a re pooled abnd set the global variable pooled * @param pooled */ @@ -219,6 +236,7 @@ } /** + * @deprecated by lecorguille get the name of the Hybridization from the HybLine objects @return @throws NutribasePluginException Index: Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageSubHybLine.java =================================================================== --- Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageSubHybLine.java (revision 1186) +++ Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageSubHybLine.java (working copy) @@ -30,11 +30,20 @@ @author Dominic Oyeniran @email oye...@eb.../doy...@gm... @version 1.0 + + + @author Gildas Le Corguillé + @email lec...@sb... + @version 1.01 + + ChangeLog : + 05/02/2010 - lecorguille : addition of BioSourceDescription */ public class Tab2MageSubHybLine { protected String bioSource; + protected String bioSourceDescription; protected String sample; protected String extract; protected String labeledExtract; @@ -74,6 +83,17 @@ this.bioSource = bioSource; } + + public String getBioSourceDescription() + { + return bioSourceDescription; + } + + public void setBioSourceDescription(String bioSourceDescription) + { + this.bioSourceDescription = bioSourceDescription; + } + /* Sample */ @@ -182,8 +202,15 @@ setBioSource((String)value); return; } + + //set BioSource + if (key == Tab2MageHybridization.BIOSOURCEDESCRIPTION) + { + setBioSourceDescription((String)value); + return; + } - // set sample + // set Sample if (key == Tab2MageHybridization.SAMPLE) { setSample((String)value); Index: Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageValidator.java =================================================================== --- Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageValidator.java (revision 1186) +++ Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageValidator.java (working copy) @@ -22,6 +22,7 @@ */ package uk.ac.ebi.nugo.plugins.ta2mageexport; +import java.io.IOException; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.LinkedList; @@ -56,6 +57,15 @@ @author Dominic Oyeniran @email oye...@eb.../doy...@gm... @version 1.0 + + + @author Gildas Le Corguillé + @email lec...@sb... + @version 1.01 + + ChangeLog : + 05/02/2010 - lecorguille : addition a pooling management for the setting of protocols + 08/02/2010 - lecorguille : fix a problem with protocols */ public class Tab2MageValidator { @@ -80,10 +90,13 @@ // counts the number of extraction protocol used in the experiment private static int samplingProtocolCount=0; + /** @deprecated by lecorguille */ private Set<String> parameterHeaders= new LinkedHashSet<String>(); + /** @deprecated by lecorguille */ private Set<String> bioMaterialXteristicsHeaders= new LinkedHashSet<String>(); + /** @deprecated by lecorguille */ private static Set<String> factorValuesHybSectionHeader= new LinkedHashSet<String>(); private static Set<String> protocolHybSectionHeader= new LinkedHashSet<String>(); @@ -95,7 +108,7 @@ */ private int channelNumber = 0; // the experiment - private Experiment experiment; + private ItemResultList<RawBioAssay> rawBioAssays; private SessionControl sc; @@ -107,9 +120,9 @@ @param sc @param response */ - public Tab2MageValidator(Experiment experiment, SessionControl sc, Response response) + public Tab2MageValidator(ItemResultList<RawBioAssay> rawBioAssays, SessionControl sc, Response response) { - this.experiment=experiment; + this.rawBioAssays=rawBioAssays; this.sc = sc; this.response= response; countProtocols(); @@ -126,8 +139,7 @@ try { dc = sc.newDbControl(); - ItemResultList<RawBioAssay> rbas= experiment.getRawBioAssays().list(dc); - for (RawBioAssay rba : rbas) + for (RawBioAssay rba : rawBioAssays) { if (rba.getProtocol()!=null) feProtocolCount++ ; @@ -147,16 +159,17 @@ if (labeledExtract.getProtocol()!=null) labelingProtocolCount++; - //Extract extract = labeledExtract.getExtract(); // RefExtract - Extract extract = ExportHelper.getExtract(labeledExtract, dc); - if (extract.getProtocol()!=null) - extractProtocolCount++; - - //sample - Sample sample = ExportHelper.getSample(extract, dc); - if (sample.getProtocol()!=null) - samplingProtocolCount++; - + Set<Extract> extracts = ExportHelper.getExtracts(labeledExtract, dc); + for (Extract extract : extracts) { + if (extract.getProtocol()!=null) + extractProtocolCount++; + + Set<Sample> samples = ExportHelper.getSamples(extract, dc); + for (Sample sample : samples) { + if (sample.getProtocol()!=null) + samplingProtocolCount++; + } + } } } } @@ -176,56 +189,59 @@ /** create both the parameter [AT] header and BioMaterialCharactertistic[AT] headers found in the whole experiment */ - @SuppressWarnings({"deprecation","unchecked"}) private void createHeaders() { DbControl dc =null; try { dc = sc.newDbControl(); - ItemResultList<RawBioAssay> rbas= experiment.getRawBioAssays().list(dc); - for (RawBioAssay rba : rbas) + for (RawBioAssay rba : rawBioAssays) { if (rba.getProtocol()!=null) { - createParameterSectionHeaders(rba, dc ); + //createParameterSectionHeaders(rba, dc); createProtocolHybSectionHeader(Tab2MageValidator.getFeProtocolCount(),Tab2MageConstants.protocol_featureextraction.getName()); } if (rba.getScan().getProtocol()!=null) { - createParameterSectionHeaders(rba.getScan(), dc ); + //createParameterSectionHeaders(rba.getScan(), dc ); createProtocolHybSectionHeader(Tab2MageValidator.getScanningProtocolCount(), Tab2MageConstants.protocol_scanning.getName()); } if (rba.getScan().getHybridization().getProtocol()!=null) { - createParameterSectionHeaders(rba.getScan().getHybridization(), dc ); + //createParameterSectionHeaders(rba.getScan().getHybridization(), dc ); createProtocolHybSectionHeader(Tab2MageValidator.getHybridizationProtocolCount(), Tab2MageConstants.protocol_hyb.getName()); } - ItemResultList<LabeledExtract>labeledExtracts = (ItemResultList<LabeledExtract>) + ItemResultList<LabeledExtract> labeledExtracts = (ItemResultList<LabeledExtract>) rba.getScan().getHybridization().getCreationEvent().getSources().list(dc); for (LabeledExtract labeledExtract :labeledExtracts) { if (labeledExtract.getProtocol()!=null) { - createParameterSectionHeaders(labeledExtract, dc ); + //createParameterSectionHeaders(labeledExtract, dc ); createProtocolHybSectionHeader(Tab2MageValidator.getLabelingProtocolCount(), Tab2MageConstants.protocol_labeling.getName()); } - //Extract extract= labeledExtract.getExtract(); - Extract extract = ExportHelper.getExtract(labeledExtract, dc); - if (extract.getProtocol()!=null) - { - createParameterSectionHeaders(labeledExtract.getExtract(), dc ); - createProtocolHybSectionHeader(Tab2MageValidator.getExtractProtocolCount(), Tab2MageConstants.protocol_extraction.getName()); + Set<Extract> extracts = ExportHelper.getExtracts(labeledExtract, dc); + for (Extract extract : extracts) { + if (extract.getProtocol()!=null) + { + //createParameterSectionHeaders(labeledExtract.getExtract(), dc ); + createProtocolHybSectionHeader(Tab2MageValidator.getExtractProtocolCount(), Tab2MageConstants.protocol_extraction.getName()); + } + Set<Sample> samples = ExportHelper.getSamples(extract, dc); + for (Sample sample : samples) { + if (sample.getProtocol()!=null) + { + //createParameterSectionHeaders(sample, dc ); + createProtocolHybSectionHeader(Tab2MageValidator.getSamplingProtocolCount(), Tab2MageConstants.protocol_treatment.getName()); + } + Set<BioSource> bioSources = ExportHelper.getBioSources(sample, dc); + for (BioSource bioSource : bioSources) { + if (bioSource!=null) + createBioMatXteristicsSectionHeader(bioSource,dc); + } + } } - Sample sample = ExportHelper.getSample(extract, dc); - if (sample.getProtocol()!=null) - { - createParameterSectionHeaders(sample, dc ); - createProtocolHybSectionHeader(Tab2MageValidator.getSamplingProtocolCount(), Tab2MageConstants.protocol_treatment.getName()); - } - BioSource bioSource= ExportHelper.getBioSource(sample, dc); - if (bioSource!=null) - createBioMatXteristicsSectionHeader(bioSource,dc); } } } @@ -240,14 +256,13 @@ if (dc!=null) dc.close(); } - } /** + * @deprecated by lecorguille Gets the used annotation types (parameters) for an annotatable item and add it to a set of PARAMETER[AT] headers @param annotatable, an item that implements annotatable @param dc, the database control object */ - private void createParameterSectionHeaders(Annotatable anotatable, DbControl dc ) { ItemResultList<Annotation> annotations = anotatable.getAnnotationSet().getAnnotations().list(dc); @@ -258,7 +273,7 @@ } } - /** + /** @deprecated by lecorguille Gets the annotation types used as biomaterial characteristics for an annotatable item @param annotatable, an item that implements annotatable @param dc, the database control object @@ -297,6 +312,7 @@ } /** + * @deprecated initialises the maps required to manage tab2mage data @param map, the map to be intitialised @param isForParameter, TRUE if map is for parameters and FALSE otherwise @@ -326,6 +342,7 @@ } /** + * @deprecated get all the experimental factors for an experiments @param DcControl dc, the database control @param Experiment experiment, the experiment @@ -354,6 +371,7 @@ } /** + * @deprecated get all the experimental factors headers for an experiments @param DcControl dc, the database control @param Experiment experiment, the experiment @@ -414,18 +432,24 @@ return feProtocolCount; } - // get the parameter headers - public Set<String> getParameterHeaders() + /** @deprecated by lecorguille + * get the parameter headers + * */ + public Set<String> getParameterHead() { return parameterHeaders; } - // get the bio material characteristics headers + /** @deprecated by lecorguille + * get the bio material characteristics headers + * */ public Set<String> getBioMaterialXteristicsHeaders() { return bioMaterialXteristicsHeaders; } - - // get the factor values header used in the experiment + + /** @deprecated by lecorguille + * get the factor values header used in the experiment + * */ public static Set<String> getFactorValuesHybSectionHeader() { return factorValuesHybSectionHeader; Index: Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageHybridizationLine.java =================================================================== --- Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageHybridizationLine.java (revision 1186) +++ Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageHybridizationLine.java (working copy) @@ -36,6 +36,15 @@ This class models the a Tab2Mage Hybridization Row in a BASE experiment for a Tab2Mage Export File @author Dominic Oyeniran @email oye...@eb.../doy...@gm... + + + @author Gildas Le Corguillé + @email lec...@sb... + @version 1.01 + + ChangeLog : + 05/02/2010 - lecorguille : addition of scan methods + 05/02/2010 - lecorguille : deletion of number of line control which was limited by the comparison the channel number */ public class Tab2MageHybridizationLine { @@ -47,6 +56,7 @@ protected String labeledExtract; protected String dye; protected String hybridization; + protected String scan; protected Map<String, String> file = new HashMap<String, String>(); protected Map<String, String> protocol = new HashMap<String, String>(); protected Map<String, String> parameter = new HashMap<String, String>(); @@ -88,6 +98,19 @@ { this.hybridization = hybridization; } + + /* + Scan + */ + public String getScan() + { + return scan; + } + + public void setScan(String scan) + { + this.scan = scan; + } /* Data Files @@ -198,6 +221,13 @@ setHybridization((String)value); return; } + + // Scan + if (key == Tab2MageHybridization.SCAN) + { + setScan((String)value); + return; + } // Parameters if (key == Tab2MageHybridization.PARAMETER) @@ -263,16 +293,16 @@ } else { - if (lines.size()!= channelNumber) // check the the line numbers matches the channel number + /*if (lines.size()!= channelNumber) // check the the line numbers matches the channel number { log.error("The Hybridization " + name + " doesn't have the right number of lines!"); return false; } else - { + {*/ subLineSet.addAll(lines); return true; - } + //} } } Index: Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/Tab2MageExporter.java =================================================================== --- Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/Tab2MageExporter.java (revision 1186) +++ Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/Tab2MageExporter.java (working copy) @@ -23,7 +23,6 @@ package uk.ac.ebi.nugo.plugins; -import java.io.Writer; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -34,7 +33,6 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import net.sf.basedb.core.Affymetrix; import net.sf.basedb.core.Annotatable; import net.sf.basedb.core.Annotation; import net.sf.basedb.core.AnnotationSet; @@ -79,6 +77,7 @@ import net.sf.basedb.util.Values; import uk.ac.ebi.nugo.common.Helper; import uk.ac.ebi.nugo.common.Tab2MageConstants; +import uk.ac.ebi.nugo.common.ValueFormatter; import uk.ac.ebi.nugo.plugins.ta2mageexport.ExportHelper; import uk.ac.ebi.nugo.plugins.ta2mageexport.Tab2MageFileWriter; import uk.ac.ebi.nugo.plugins.ta2mageexport.Tab2MageHybridization; @@ -91,6 +90,19 @@ @author Dominic Oyeniran @email oye...@eb... /doy...@gm... @version 1.0 + + + @author Gildas Le Corguillé + @email lec...@sb... + @version 1.01 + + ChangeLog : + 05/02/2010 - lecorguille : modification of a lot of things about pooling depending of the other class + now, lines are repeated if there are several files per RawBioAssay or pooling of Sample, Extract or LabeledExtract + Tab2Mage format doesn't support pooling like Base2 does : + - Base2 pool 2 Samples in a Ref Sample + - Tab2Mage format pool 2 BioSources in the Ref Sample + 08/02/2010 - lecorguille : addition of BioSourceDescription */ public class Tab2MageExporter extends AbstractPlugin @@ -276,247 +288,190 @@ Set<Protocol> protocols = new LinkedHashSet<Protocol>(); Set<String> hybSectionHeader= new LinkedHashSet<String>(); Set<String> protocolHybSectionHeader= new LinkedHashSet<String>(); - + + + + boolean overwrite = false; try { dc=sc.newDbControl(); User user = User.getById(dc, sc.getLoggedInUserId()); + + + /* -- output files -- */ if ((Boolean)job.getValue("overwrite") != null) overwrite = (Boolean)job.getValue("overwrite"); String p = (String)job.getValue("exportPath"); File file=Helper.processFilePath(user,overwrite, dc,p); String statusp=(String)job.getValue("statusPath"); File statusFile=Helper.processFilePath(user,overwrite, dc,statusp); + Tab2MageFileWriter.createFileWriters(file, statusFile); + + + /* --- Experiment --- */ Experiment experiment= (Experiment)job.getValue("experiment"); - experiment= Experiment.getById(dc,experiment.getId()); - - // check if the logged in user owned the experiment, if not the export exit with a message. + experiment= Experiment.getById(dc,experiment.getId()); - if (!(experiment.getOwner().equals(user))) - { + // check if the logged in user owned the experiment, if not the export exit with a message. + if (!(experiment.getOwner().equals(user))) { response.setError("[EXPORT FAILED: User - "+user.getName()+ " do not own this experiment or have permission to export it].", Arrays.asList(new Throwable())); return; } - if (experiment.getExperimentalFactors().list(dc).size()==0) - { + if (experiment.getExperimentalFactors().list(dc).size()==0) { response.setError("[EXPORT FAILED: Experimental factors have not been specified for this experiment].", Arrays.asList(new Throwable())); return; } - - // check that raw bio assays have been added to experiment, otherwise fails - + + + /* --- RawBioAssay --- */ ItemQuery<RawBioAssay> rawBioAssaysQuery = experiment.getRawBioAssays(); rawBioAssaysQuery.order(Orders.asc(Hql.property("name"))); ItemResultList<RawBioAssay> rawBioAssays= rawBioAssaysQuery.list(dc); - if (rawBioAssays==null || rawBioAssays.size()==0) - { + + // check that raw bio assays have been added to experiment, otherwise fails + if (rawBioAssays==null || rawBioAssays.size()==0) { response.setError("[EXPORT FAILED: Experiment - "+ experiment+ " do not have a rawbiosay specified].",Arrays.asList(new Throwable())); return; } - // create all the required writers for the status file and the export file - Tab2MageFileWriter.createFileWriters(file, statusFile); + // initialise, count resources used, create concurrentmap for all parameter and biomaterial headers + Tab2MageValidator validator = new Tab2MageValidator (rawBioAssays, sc, response); - //initialise, count resources used, create concurrentmap for all parameter and biomaterial headers - Tab2MageValidator validator = new Tab2MageValidator (experiment, sc, response); - //Tab2MageHybridization hybridization= new Tab2MageHybridization (); - for (RawBioAssay rba : rawBioAssays) { - // create the Tab2MageHybridization object - Tab2MageHybridization hybridization= new Tab2MageHybridization (); - // create the Tab2MageHybridizationLine object - Tab2MageHybridizationLine hybRow = new Tab2MageHybridizationLine(); - - // set the number of channels for the Hybridization - hybridization.setChannelNumber(validator.getChannelNumber()); // mainly useful during the writing stage - - /* - Experimental Factor Section - */ - AnnotationSet annotationSet =rba.isAnnotated() ? rba.getAnnotationSet() : null; - ItemQuery<AnnotationType> experimentalFactorsQuery= experiment.getExperimentalFactors(); - experimentalFactorsQuery.include(Include.MINE, Include.SHARED, Include.OTHERS, Include.IN_PROJECT, Include.NOT_REMOVED); - ItemResultList<AnnotationType> experimentalFactors = experimentalFactorsQuery.list(dc); - for (AnnotationType exprFactor :experimentalFactors) - { - if (!exprFactor.isRemoved()) + Set<Tab2MageHybridizationLine> hybRows = ExportHelper.getRawBioAssayFiles(rba, dc, response); + for (Tab2MageHybridizationLine hybRow : hybRows) { + + + /* --- Array design ---*/ + ArrayDesign arrayDesign = rba.getArrayDesign(); + hybRow.set("Array",Tab2MageConstants.array_accession.getName(),arrayDesign.getName()); + setProtocolAndParameterAtrributes(hybRow,rba,Tab2MageValidator.getFeProtocolCount(), Tab2MageConstants.protocol_featureextraction.getName(), response, dc); + + + /* --- Scan --- */ + Scan scan= rba.getScan(); + hybRow.set(Tab2MageConstants.scan.getName(), null,scan.getName()); + setProtocolAndParameterAtrributes(hybRow,scan,Tab2MageValidator.getScanningProtocolCount(), Tab2MageConstants.protocol_scanning.getName(),response, dc); + + + /* --- Experimental factor section --- */ + AnnotationSet annotationSet = rba.isAnnotated() ? rba.getAnnotationSet() : null; + ItemQuery<AnnotationType> experimentalFactorsQuery = experiment.getExperimentalFactors(); + experimentalFactorsQuery.include(Include.MINE, Include.SHARED, Include.OTHERS, Include.IN_PROJECT, Include.NOT_REMOVED); + ItemResultList<AnnotationType> experimentalFactors = experimentalFactorsQuery.list(dc); + for (AnnotationType exprFactor :experimentalFactors) { - if (annotationSet!=null) - { - Annotation an= annotationSet.findAnnotation(exprFactor); - /* - Please use the line below instead of the one above for base 2.5 API to get inherited annotation types. - Annotation an = annotationSet.findAnnotations(exprFactor); - List<Annotation> findAnnotations(dc, exprFactor, true); - Loop through the list.....needs more check - */ - - if (an!=null) //exprFacor has annotations - { - List<?> values= an.getValues(); - hybRow.set("FactorValue", exprFactor.getName(), values==null || values.size()==0 ? "" : Values.getString(values, ", ", true)); + if (!exprFactor.isRemoved()) { + if (annotationSet!=null) { + Annotation an= annotationSet.findAnnotation(exprFactor); + /* + Please use the line below instead of the one above for base 2.5 API to get inherited annotation types. + Annotation an = annotationSet.findAnnotations(exprFactor); + List<Annotation> findAnnotations(dc, exprFactor, true); + Loop through the list.....needs more check + */ + + if (an!=null) { //exprFacor has annotations + List<?> values= an.getValues(); + hybRow.set("FactorValue", exprFactor.getName(), values==null || values.size()==0 ? "" : Values.getString(values, ", ", true)); + } + else { // exprFactor has no annotations + hybRow.set("FactorValue", exprFactor.getName(), "" ); + } } - else // exprFactor has no annotations - { + else { //The raw bio assay is not annotated hybRow.set("FactorValue", exprFactor.getName(), "" ); } } - else //The raw bio assay is not annotated - { - hybRow.set("FactorValue", exprFactor.getName(), "" ); - } } - } - - //Array Design - ArrayDesign arrayDesign = null; - try - { - arrayDesign= rba.getArrayDesign(); - } - catch(Throwable tr) - { - response.setError("[EXPORT FAILED: All Array Design(s) must be provided in BASE to continue].",Arrays.asList(tr)); - } - // Populate the Array file map in HybLine - setArraysAttributes(hybRow, arrayDesign ); - - // Populate the Data file map in HybLine - setFileAttributes(hybRow, arrayDesign, rba, response); - - //Raw BioAssay protocol and parameter - setProtocolAndParameterAtrributes(hybRow,rba,Tab2MageValidator.getFeProtocolCount(), - Tab2MageConstants.protocol_featureextraction.getName(), response, dc); - - //Scanning Protocol and Parameters - Scan scan= rba.getScan(); - setProtocolAndParameterAtrributes(hybRow,scan,Tab2MageValidator.getScanningProtocolCount(), - Tab2MageConstants.protocol_scanning.getName(),response, dc); - - /* - Array Slide - */ - Hybridization hyb= scan.getHybridization(); - if (hyb.getArraySlide()==null) - { - response.setError("[Export Failed] please add an array slide for Hybridization:"+hyb.getName(), Arrays.asList(new Throwable())); - return; - } - else - { - hybRow.set("Array","serial", hyb.getArraySlide().getName()); - } - /* - Hybridization - */ - hybRow.set(Tab2MageConstants.hybridization.getName(), null,hyb.getName()); - BioMaterialEvent bioMaterialEvent= hyb.getCreationEvent(); // an event that created the hyridization - - // Hybridization protocol and parameter - setProtocolAndParameterAtrributes(hybRow,hyb,Tab2MageValidator.getHybridizationProtocolCount(), - Tab2MageConstants.protocol_hyb.getName(), response, dc); - - ItemQuery<LabeledExtract> labeledExtractQuery =(ItemQuery<LabeledExtract>) bioMaterialEvent.getSources(); // get all the labeled extract - ItemResultList<LabeledExtract> labeledExtracts= labeledExtractQuery .list(dc); - int size = labeledExtracts.size(); - - // create the Tab2MageSubHybLine object List - List<Tab2MageSubHybLine> subLines = new ArrayList<Tab2MageSubHybLine>(); - - int count=1; // initialise the count variable to 1 - // Loop through all the labeled extracts - for (LabeledExtract labeledExtract :labeledExtracts) // can have more than one labeled extract (e.g. 2 color experiments) - { - //create the new SubHyb Line - Tab2MageSubHybLine subLine = new Tab2MageSubHybLine(); - /* - labeled extract - */ - Protocol lbExtractProtocol= labeledExtract.getCreationEvent().getProtocol(); - subLine.set(Tab2MageConstants.labeledextract.getName(), null, labeledExtract.getName()); - - // labelling protocol and parameter - setProtocolAndParameterAtrributes(dc, subLine,labeledExtract,Tab2MageValidator.getLabelingProtocolCount(), - Tab2MageConstants.protocol_labeling.getName(),lbExtractProtocol, response); - /* - Label - */ - String labelName= labeledExtract.getLabel().getName(); // the name of the label - subLine.set(Tab2MageConstants.dye.getName(), null,labelName); - - /* - Extract - */ - - Extract extract= ExportHelper.getExtract(labeledExtract, dc); - if (extract!=null) - { - Protocol extractProtocol =extract.getCreationEvent().getProtocol(); //extract protocol - subLine.set(Tab2MageConstants.extract.getName(), null, extract.getName()); - // extraction protocol and parameter - setProtocolAndParameterAtrributes(dc, subLine,extract,Tab2MageValidator.getExtractProtocolCount(), - Tab2MageConstants.protocol_extraction.getName(), extractProtocol, response); - } + /* --- Hybridization --- */ + Hybridization hyb = scan.getHybridization(); + hybRow.set(Tab2MageConstants.hybridization.getName(), null,hyb.getName()); + setProtocolAndParameterAtrributes(hybRow,hyb,Tab2MageValidator.getHybridizationProtocolCount(), Tab2MageConstants.protocol_hyb.getName(), response, dc); - /* - Sample - */ + /* --- Array slide --- */ + hybRow.set("Array","serial", hyb.getArraySlide().getName()); - Sample sample= ExportHelper.getSample(extract, dc); - if (sample != null) - { - Protocol sampleProtocol=sample.getCreationEvent().getProtocol(); //sampling protocol - subLine.set(Tab2MageConstants.sample.getName(), null, sample.getName()); - - // sampling protocol and parameter - setProtocolAndParameterAtrributes(dc, subLine,sample,Tab2MageValidator.getSamplingProtocolCount(), - Tab2MageConstants.protocol_treatment.getName(),sampleProtocol, response ); - } + // create the Tab2MageSubHybLine object List + List<Tab2MageSubHybLine> subLines = new ArrayList<Tab2MageSubHybLine>(); - /* - Biosource - */ - - BioSource bioSource=ExportHelper.getBioSource(sample, dc); - if (bioSource != null) - { - subLine.set(Tab2MageConstants.biosource.getName(), null, bioSource.getName()); + /* --- labeled extract --- */ + BioMaterialEvent bioMaterialEvent= hyb.getCreationEvent(); // an event that created the hyridization + ItemQuery<LabeledExtract> labeledExtractQuery =(ItemQuery<LabeledExtract>) bioMaterialEvent.getSources(); // get all the labeled extract + ItemResultList<LabeledExtract> labeledExtracts= labeledExtractQuery.list(dc); + int size = labeledExtracts.size(); + for (LabeledExtract labeledExtract :labeledExtracts) { // can have more than one labeled extract (e.g. 2 color experiments) + + /* --- Label --- */ + String labelName = labeledExtract.getLabel().getName(); // the name of the label + - //section for biomaterial xterixtics - ItemQuery<Annotation> query = bioSource.getAnnotationSet().getAnnotations(); - query.include(Include.MINE, Include.NOT_REMOVED, Include.IN_PROJECT,Include.SHARED); - List<Annotation> annotations = query.list(dc); - for (Annotation annotation: annotations) - { - AnnotationType at=annotation.getAnnotationType(); - if(!at.isRemoved()) - { - List<?> values= annotation==null? null:annotation.getValues(); - subLine.set(Tab2MageConstants.bio_mat_charact.getName(), annotation.getAnnotationType().getName(), - values==null || values.size()==0 ? ExportHelper.getDefaultValue(at) : Values.getString(values, ", ", true)); + /* --- Extracts --- */ + Set<Extract> extracts = ExportHelper.getExtracts(labeledExtract, dc); + for (Extract extract : extracts) { + + /* --- Samples --- */ + Set<Sample> samples = ExportHelper.getSamples(extract, dc); + for (Sample sample : samples) { + + /* --- Biosources --- */ + Set<BioSource> bioSources = ExportHelper.getBioSources(sample, dc); + for (BioSource bioSource : bioSources) { + + //create the new SubHyb Line + Tab2MageSubHybLine subLine = new Tab2MageSubHybLine(); + + subLine.set(Tab2MageConstants.labeledextract.getName(), null, labeledExtract.getName()); + setProtocolAndParameterAtrributes(subLine,labeledExtract,Tab2MageValidator.getLabelingProtocolCount(), Tab2MageConstants.protocol_labeling.getName(),response, dc); + subLine.set(Tab2MageConstants.dye.getName(), null,labelName); + subLine.set(Tab2MageConstants.extract.getName(), null, extract.getName()); + setProtocolAndParameterAtrributes(subLine,extract,Tab2MageValidator.getExtractProtocolCount(), Tab2MageConstants.protocol_extraction.getName(), response, dc); + subLine.set(Tab2MageConstants.sample.getName(), null, sample.getName()); + setProtocolAndParameterAtrributes(subLine,sample,Tab2MageValidator.getSamplingProtocolCount(), Tab2MageConstants.protocol_treatment.getName(), response, dc); + subLine.set(Tab2MageConstants.biosource.getName(), null, bioSource.getName()); + subLine.set(Tab2MageConstants.biosourcedescription.getName(), null, ValueFormatter.getStringWithoutLineBreaker(bioSource.getDescription())); + + //section for biomaterial xterixtics + ItemQuery<Annotation> query = bioSource.getAnnotationSet().getAnnotations(); + query.include(Include.MINE, Include.NOT_REMOVED, Include.IN_PROJECT,Include.SHARED); + List<Annotation> annotations = query.list(dc); + for (Annotation annotation: annotations) + { + AnnotationType at=annotation.getAnnotationType(); + if(!at.isRemoved()) + { + List<?> values= annotation==null? null:annotation.getValues(); + subLine.set(Tab2MageConstants.bio_mat_charact.getName(), annotation.getAnnotationType().getName(), + values==null || values.size()==0 ? ExportHelper.getDefaultValue(at) : Values.getString(values, ", ", true)); + } + } + + + subLines.add(subLine); //make a list of subLines + } } } - } - - subLines.add(subLine); //make a list of subLines - count++; - } //end of labeled extract loop - - hybRow.addHybSubLines(size, hybRow.getName(), subLines); // add the subLines (i.e. Tab2MageSubHybLine objectc list to Tab2MageHybridizationLine Object + } //end of labeled extract loop + hybRow.addHybSubLines(size, hybRow.getName(), subLines); // add the subLines (i.e. Tab2MageSubHybLine object list to Tab2MageHybridizationLine Object + - hybridization.addLine(hybRow); // add Tab2MageHybridizationLine Object to Tab2MageHybridization object - if(!hybs.contains(hybridization)) - hybs.add(hybridization); // add Tab2MageHybridization Object to the List of Tab2MageHybridization object + // create the Tab2MageHybridization object + Tab2MageHybridization hybridization= new Tab2MageHybridization (); + // set the number of channels for the Hybridization + hybridization.setChannelNumber(validator.getChannelNumber()); // mainly useful during the writing stage + hybridization.addLine(hybRow); // add Tab2MageHybridizationLine Object to Tab2MageHybridization object + if(!hybs.contains(hybridization)) + hybs.add(hybridization); // add Tab2MageHybridization Object to the List of Tab2MageHybridization object + } }// end of raw biossay for loop - // create headers for biomaterial xteristics Set<String> bioMatHeaders = new LinkedHashSet<String>(); @@ -546,17 +501,14 @@ // get the headers for the experiment factor values and add to experimental factor values header set factorValueHeaders.addAll(ExportHelper.getHeaderWithValuesOnly(l.getFactorValues())); } - /* Create all the used protocols objects */ protocols = ExportHelper.createProtocols(rawBioAssays, dc); - /* create all used Tab2Mage Hybridization sections protocol headers */ protocolHybSectionHeader= Tab2MageValidator.getProtocolHybSectionHeader(); - /* Create Tab2Mage Hybridization Section Header */ @@ -569,64 +521,25 @@ Tab2MageFileWriter.writeTab2MageFile(experiment, protocols,hybs, hybSectionHeader,bioMatHeaders, protocolHybSectionHeader, paramHeaders,factorValueHeaders, job, response, dc); + Tab2MageFileWriter.getStatusOut().write("DONE\n"); + Tab2MageFileWriter.closeWriter(); - //statusOut.close(); - Writer out= Tab2MageFileWriter.getOut(); - out.flush(); - out.close(); dc.commit(); response.setDone("Experiment " + experiment.getName() + " exported successfully"); } catch (Throwable ex) { + Tab2MageFileWriter.closeWriter(); response.setError(ex.getMessage(), Arrays.asList(ex)); } finally { + Tab2MageFileWriter.closeWriter(); if (dc != null) dc.close(); } } - + /** - set the array attributes of the the <code>Tab2MageHybridizationLine</code> object - @param hybRow, the <code>Tab2MageHybridizationLine</code> object - @param arrayDesign, the Array Design - */ - private void setArraysAttributes (Tab2MageHybridizationLine hybRow, ArrayDesign arrayDesign ) - { - hybRow.set("Array",Tab2MageConstants.array_accession.getName(),arrayDesign.getName()); - } - - /** - set the file attributes of the the <code>Tab2MageHybridizationLine</code> object - @param hybRow, the Tab2MageHybridizationLine object - @param arrayDesign, the Array Design - @param rba, the raw bio assay - @param response, the response object to return errors in case of failure during the setting of file values - */ - private void setFileAttributes(Tab2MageHybridizationLine hybRow, ArrayDesign arrayDesign, RawBioAssay rba, Response response) - { - try - { - if (arrayDesign.isAffyChip()) - { - File cdfFile= Affymetrix.getCdfFile(arrayDesign); - File celFile=Affymetrix.getCelFile(rba); - hybRow.set("File", Tab2MageConstants.raw_file.getName(), celFile.getName()); - hybRow.set("File",Tab2MageConstants.cdf_file.getName(), cdfFile.getName()); - } - else - { - hybRow.set("File", Tab2MageConstants.raw_file.getName(), rba.getName()); - } - - } - catch(Throwable tr) - { - response.setError(tr.getMessage(), Arrays.asList(tr)); - } - } - /** set the protocol and parameters attributes/values for Labeling -to- Sampling protocol and parameters @param dc, the database control @param subLine, the <code>Tab2MageSubHybLine</code> object @@ -636,11 +549,11 @@ @param protocol, the protocol object @param response, the response object to return errors in case of failure during the setting of parameter values */ - private void setProtocolAndParameterAtrributes(DbControl dc,Tab2MageSubHybLine subLine, Annotatable anotatable, int prot... [truncated message content] |