Changeset 449
- Timestamp:
- Oct 30, 2007, 3:54:31 PM (15 years ago)
- Location:
- trunk/uk/ac/ebi/Tab2MageExporter/src/uk/ac/ebi/nugo
- Files:
-
- 5 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/uk/ac/ebi/Tab2MageExporter/src/uk/ac/ebi/nugo/common/Helper.java
r423 r449 11 11 import net.sf.basedb.core.ArrayDesign; 12 12 import net.sf.basedb.core.ArraySlide; 13 import net.sf.basedb.core.BaseException; 13 14 import net.sf.basedb.core.BioSource; 14 15 import net.sf.basedb.core.DbControl; 16 import net.sf.basedb.core.Directory; 15 17 import net.sf.basedb.core.Extract; 16 18 import net.sf.basedb.core.File; … … 23 25 import net.sf.basedb.core.Path; 24 26 import net.sf.basedb.core.Sample; 27 import net.sf.basedb.core.SessionControl; 25 28 import net.sf.basedb.core.Type; 26 29 import net.sf.basedb.core.User; … … 31 34 /** 32 35 A plugin utils class for the tab2mage export and export. 33 [TODO] This class may be merged to other utils in the main base 2 source code 34 @author Dominic Oyeniran 36 @author Dominic Oyeniran 35 37 @version 1.0 36 38 */ … … 68 70 69 71 72 public static File processFilePath (User user,boolean overwrite, SessionControl sc, String pathString) 73 { 74 DbControl dc= null; 75 File file =null; 76 try 77 { 78 dc= sc.newDbControl(); 79 if (pathString.startsWith("~/")) 80 { 81 pathString = "~"+user.getLogin()+pathString.substring(1); 82 } 83 Path path = new Path(pathString, Path.Type.FILE); 84 85 file= File.getByPath(dc, path, true); 86 file.setMimeType("text/plain"); //set the type of the file 87 if (file.isInDatabase() && !overwrite && !file.isRemoved()) 88 { 89 throw new ItemAlreadyExistsException("File[path="+path+"]"); 90 } 91 else if(!file.isInDatabase()) 92 { 93 dc.saveItem(file); 94 } 95 dc.commit(); 96 } 97 catch(Exception e) 98 { 99 dc.close(); 100 } 101 finally 102 { 103 if (dc!=null) 104 dc.close(); 105 } 106 107 return file; 108 } 70 109 /** 71 110 Displays the content of the map. Helps to check that the content displayed is correct. … … 109 148 of a tab2mage file 110 149 @param atName , annotation type name 111 @return annotationType s, <code>AnnotationType</code>150 @return annotationType, <code>AnnotationType</code> 112 151 */ 113 152 public static AnnotationType getAnnotationTypeByName(String atName, DbControl dc) … … 211 250 return ar; 212 251 } 213 /** 214 writes a string to standard output 215 @param o 216 */ 217 public static void write(String o) 218 { 219 System.out.println("&& DEBUG : "+o); 220 } 221 252 222 253 223 254 /** … … 311 342 return le; 312 343 } 344 345 346 /** 347 gets the currently looged in user default directory 348 @param sc, the seesion control 349 @return path of the user directory as a string object 350 */ 351 public static String getUserDefaultDirectory( SessionControl sc) 352 { 353 DbControl dc = sc.newDbControl(); 354 String p =""; 355 try 356 { 357 User user = User.getById(dc, sc.getLoggedInUserId()); 358 Directory dir= user.getHomeDirectory(); 359 Path path = dir.getPath(); 360 p=path.toString(); 361 } 362 catch(Exception e) 363 { 364 new BaseException(e.getMessage()); 365 } 366 finally 367 { 368 if (dc!=null) dc.close(); 369 } 370 return p; 371 } 313 372 } -
trunk/uk/ac/ebi/Tab2MageExporter/src/uk/ac/ebi/nugo/common/Tab2MageConstants.java
r396 r449 1 /** 2 * 3 */ 1 /* $Id: Tab2MageConstants.java 2006-08-08 dominic $ 2 3 This file is for NutriBASE - Nutrigenomics BioArray Software Environment. 4 A customisation of the BASE SOFTWARE. 5 Developed at the EBI , Cambridge. 6 Author: Dominic Oyeniran: oyeniran@ebi.ac.uk 7 */ 4 8 package uk.ac.ebi.nugo.common; 5 9 … … 13 17 @author Dominic Oyeniran 14 18 @version 1.0 15 @base.modified $Date16 19 */ 17 20 public enum Tab2MageConstants … … 193 196 The parameter header 194 197 */ 195 parameter(49, "Parameter"); 198 parameter(49, "Parameter"), 199 200 /** 201 The protocol header 202 */ 203 protocol(50, "Protocol"), 204 205 /** 206 nucleic acid extraction 207 */ 208 nucleicacidextraction(51, "Nucleic_Acid_Extraction"); 209 ; 196 210 197 211 /** -
trunk/uk/ac/ebi/Tab2MageExporter/src/uk/ac/ebi/nugo/common/ValueFormatter.java
r423 r449 16 16 /** 17 17 A utility class containing static methods for formatting parameter values. 18 [TODO] This class may be merged to util class in the main base 2 source code19 18 @author Dominic Oyeniran 20 19 @email oyeniran@ebi.ac.uk -
trunk/uk/ac/ebi/Tab2MageExporter/src/uk/ac/ebi/nugo/common/ZipUnpacker.java
r423 r449 13 13 import java.util.zip.ZipInputStream; 14 14 15 import net.sf.basedb.core.DatabaseException; 15 16 import net.sf.basedb.core.DbControl; 16 17 import net.sf.basedb.core.Directory; … … 31 32 /** 32 33 This class unpacks zip file provided by users into the base file structure 33 Note: Parts of the codes are authored by Misha Bayer - email: sbrn@scri.ac.uk,34 Note: Parts of the codes were authored by Misha Bayer - email: sbrn@scri.ac.uk, 34 35 @author Dominic Oyeniran 35 36 @email oyeniran@ebi.ac.uk 36 @see BatchDataImport.java and BatchLoader plugin developed by Misha Bayer.37 38 37 39 38 */ … … 75 74 { 76 75 createSubDirectory( file, user); 77 // now call the m athod to unpack the zip files76 // now call the method to unpack the zip files 78 77 PluginDefinition zipFilePlugin = PluginDefinition.getByClassName(dc, "net.sf.basedb.plugins.ZipFileUnpacker"); 79 78 FileUnpacker unpacker = zipFilePlugin.newInstance(net.sf.basedb.plugins.ZipFileUnpacker.class, null, dc.getSessionControl(), null, null); … … 115 114 //unlimited storage (e.g. for user root) will return -1 116 115 long quotaValue = quota.getQuotaValue(totalQuotaType, Location.PRIMARY); 117 //System.out.println("the quota value of the user: " + user.getName()+ " is: "+quotaValue );116 log.info("the quota value of the user: " + user.getName()+ " is: "+quotaValue ); 118 117 long currentDiskUsage = user.getDiskUsage(totalQuotaType, Location.PRIMARY); 119 118 //check whether remaining disk space and zip file size are compatible 120 119 long remainingSpace = quotaValue - currentDiskUsage; 121 //System.out.println("the remaining space for user: " + user.getName()+ " is: "+remainingSpace );120 log.info("the remaining space for user: " + user.getName()+ " is: "+remainingSpace ); 122 121 if(remainingSpace < zipFileSize && quotaValue!=-1) 123 122 { … … 172 171 //get the parent directory 173 172 Directory zipFileDir = zipFile.getDirectory(); 174 //System.out.println("zipFile is located in dir " + zipFile.getPath());173 log.info("zipFile is located in dir " + zipFile.getPath()); 175 174 Directory d = Directory.getById(dc, zipFileDir.getId()); 176 175 Directory subDir = d.newSubDirectory(); 177 String fileName = zipFile.getName(); 178 String fileNameNoExt = fileName.substring(0, fileName.indexOf(".")); 179 subDir.setName(fileNameNoExt); 180 subDir.setDescription("Unzippped directory created at "+new Date()); 181 dc.saveItem(subDir); 182 dc.commit(); 183 //unzippedFilesDirectory = subDir; 176 if (subDir.isInDatabase()) 177 { 178 throw new DatabaseException("The Directory ["+ subDir.getPath().toString()+ "] already exists"); 179 } 180 else if (!subDir.isInDatabase()) 181 { 182 String fileName = zipFile.getName(); 183 String fileNameNoExt = fileName.substring(0, fileName.indexOf(".")); 184 subDir.setName(fileNameNoExt); 185 subDir.setDescription("Unzippped directory created at "+new Date()); 186 dc.saveItem(subDir); 187 } 188 dc.commit(); 184 189 setUnzippedFilesDirectory(subDir); 185 190 } 186 191 catch (Throwable ex) 187 192 { 188 log.error("--Create subdirectory FAILED" );193 log.error("--Create subdirectory FAILED", ex); 189 194 } 190 195 finally -
trunk/uk/ac/ebi/Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/Tab2MageExporter.java
r396 r449 1 /* $Id: Tab2MageExporter.java 200 6-10-22dominic $2 3 Copyright (C) Authors contributing to this file.1 /* $Id: Tab2MageExporter.java 2007-09-01 dominic $ 2 3 Copyright (C) 2007 Authors contributing to this file. 4 4 5 5 This file is for NutriBASE - Nutrigenomics BioArray Software Environment. … … 22 22 */ 23 23 package uk.ac.ebi.nugo.plugins; 24 25 24 26 import java.io.Writer; 25 27 import java.util.ArrayList; … … 28 30 import java.util.Collections; 29 31 import java.util.Date; 30 import java.util.HashMap;31 32 import java.util.LinkedHashSet; 32 import java.util.LinkedList;33 33 import java.util.List; 34 import java.util.Map;35 34 import java.util.Set; 36 35 import java.util.concurrent.ConcurrentHashMap; … … 81 80 import uk.ac.ebi.nugo.common.Helper; 82 81 import uk.ac.ebi.nugo.common.Tab2MageConstants; 83 import uk.ac.ebi.nugo.plugins.ta2mageexport.ExporHelper; 84 import uk.ac.ebi.nugo.plugins.ta2mageexport.Tab2MageWriter; 85 82 import uk.ac.ebi.nugo.plugins.ta2mageexport.ExportHelper; 83 import uk.ac.ebi.nugo.plugins.ta2mageexport.Tab2MageFileWriter; 84 import uk.ac.ebi.nugo.plugins.ta2mageexport.Tab2MageHybridization; 85 import uk.ac.ebi.nugo.plugins.ta2mageexport.Tab2MageHybridizationLine; 86 import uk.ac.ebi.nugo.plugins.ta2mageexport.Tab2MageSubHybLine; 87 import uk.ac.ebi.nugo.plugins.ta2mageexport.Tab2MageValidator; 86 88 87 89 /** 88 90 A plugin that exports an experiment in tab2mage specification for submission to ArrayExpress public repository. 89 91 @author Dominic Oyeniran 92 @email oyeniran@ebi.ac.uk /doyeniran@gmail.com 90 93 @version 1.0 91 @base.modified $Date$ 94 92 95 */ 93 94 public class Tab2MageExporter 95 extends AbstractPlugin 96 implements InteractivePlugin 96 public class Tab2MageExporter extends AbstractPlugin 97 implements InteractivePlugin 97 98 { 98 99 private static final About about= 99 100 new AboutImpl 100 101 ( 101 "Tab2M AGEexporter",102 "This plugin is used to exportan experiment in the tab2mage format specfication. The tab2mage specification " +102 "Tab2Mage exporter", 103 "This plugin is for exporting an experiment in the tab2mage format specfication. The tab2mage specification " + 103 104 "is provided by the microarray informatics team at the EBI, Cambridge. The exported experiment can later be " + 104 "imported by the corresponding import plugin.",105 " 2.0",105 "imported into BASE by the corresponding import plugin.", 106 "1.0", 106 107 "2006, NutriBase development team", 107 108 null, 108 109 "oyeniran@ebi.ac.uk", 109 "http:// base.thep.lu.se"110 "http://www.ebi.ac.uk/~oyeniran" 110 111 ); 111 112 … … 114 115 115 116 private PluginParameter<String> pathParameter; 116 private static final String pathDefaultValue="/home/tab2mage.txt";117 117 private PluginParameter<String> statusPathParameter; 118 private static final String statusPathDefaultValue="/home/statusreport.txt";119 118 private PluginParameter<Experiment> experimentParameter; 120 119 private BooleanParameterType overwriteType= new BooleanParameterType(false, false);; … … 138 137 "Save as", 139 138 "Please specify the file name where the plugin should store it's output", 140 new PathParameterType(Path.Type.FILE, pathDefaultValue, true));139 new PathParameterType(Path.Type.FILE, Helper.getUserDefaultDirectory(sc)+"/tab2mage.txt", true)); 141 140 142 141 statusPathParameter = new PluginParameter<String>( … … 144 143 "Save Status File as", 145 144 "Please specify the file name where the plugin should store causes for failure and errors", 146 new PathParameterType(Path.Type.FILE, statusPathDefaultValue, true));145 new PathParameterType(Path.Type.FILE, Helper.getUserDefaultDirectory(sc)+"/statusreport.txt", true)); 147 146 148 147 experimentParameter = new PluginParameter<Experiment>( … … 259 258 return about; 260 259 } 260 @Override 261 261 public boolean supportsConfigurations() 262 262 { 263 263 return false; 264 264 } 265 @Override 265 266 public boolean requiresConfiguration() 266 267 { … … 272 273 { 273 274 DbControl dc=null; 274 Set<Protocol> protocols = new LinkedHashSet<Protocol>(); //to get protocols as they are entered275 275 //use a linked list to get objects e.g. protocols as they are entered. 276 Set<Protocol> protocols = new LinkedHashSet<Protocol>(); 276 277 Set<String> hybSectionHeader= new LinkedHashSet<String>(); 277 278 Set<String> protocolHybSectionHeader= new LinkedHashSet<String>(); 278 List<String> protocolRefId= new LinkedList<String>(); 279 List<String> hybridizationDataRows=new LinkedList<String>(); 280 List<String> parameterValues= new LinkedList<String>(); 281 282 List<Annotation> expFactorValues= new LinkedList<Annotation>(); 283 Map<AnnotationType, Annotation> factorValues= new HashMap<AnnotationType,Annotation>(); 284 List<String> twoColorHybDataRows=new LinkedList<String>(); 285 List<String> twoColorParameterValues=new LinkedList<String>(); 286 List<String> twoColorFirstParameterValues=new LinkedList<String>(); 287 List<String> twoColorProtocolRefId= new LinkedList<String>(); 288 List<String> twoColorFirstProtocolRefId= new LinkedList<String>(); 289 290 //pooling data strutures - //NOTE:Pooling is not fully supported at the moment 291 List<String> poolSampleHeader=new LinkedList<String>(); 292 List<String> poolSampleTail= new LinkedList<String>(); 293 List<String> poolHybDataRows=new LinkedList<String>(); 294 279 295 280 boolean overwrite = false; 296 boolean twoColorHyb= false; 297 //pooling attributes 298 boolean pooledSampleFlag= false; 299 281 300 282 try 301 283 { … … 309 291 Experiment experiment= (Experiment)job.getValue("experiment"); 310 292 experiment= Experiment.getById(dc,experiment.getId()); 293 311 294 // check if the logged in user owned the experiment, if not the export exit with a message. 295 312 296 if (!(experiment.getOwner().equals(user))) 313 297 { 314 response.set Done("[EXPORT FAILED: User - "+user.getName()+ " do not own this experiment or have permission to export it].");298 response.setError("[EXPORT FAILED: User - "+user.getName()+ " do not own this experiment or have permission to export it].", Arrays.asList(new Throwable())); 315 299 return; 316 300 } 317 301 if (experiment.getExperimentalFactors().list(dc).size()==0) 318 302 { 319 response.setError("[E xport Failed]Experimental factors have not been specified for this experiment].", Arrays.asList(new Throwable()));303 response.setError("[EXPORT FAILED: Experimental factors have not been specified for this experiment].", Arrays.asList(new Throwable())); 320 304 return; 321 322 } 323 //initialise, count resources used, create concurrentmap for all parameter headers 324 getResourceCounter(experiment,dc); 305 } 325 306 326 Tab2MageWriter.createFileWriters(file, statusFile); 327 328 // Get all protocols and hybs 307 // check that raw bio assays have been added to experiment, otherwise fails 308 329 309 ItemQuery<RawBioAssay> rawBioAssaysQuery = experiment.getRawBioAssays(); 330 310 rawBioAssaysQuery.order(Orders.asc(Hql.property("name"))); … … 335 315 return; 336 316 } 317 318 // create all the required writers for the status file and the export file 319 320 Tab2MageFileWriter.createFileWriters(file, statusFile); 321 322 //initialise, count resources used, create concurrentmap for all parameter and biomaterial headers 323 Tab2MageValidator validator = new Tab2MageValidator (experiment, sc, response); 324 325 //Tab2MageHybridization hybridization= new Tab2MageHybridization (); 326 337 327 for (RawBioAssay rba : rawBioAssays) 338 328 { 339 initialiseMaps(parameterMap,true); 340 initialiseMaps(twoColorParameterMap,true); 341 initialiseMaps(twoColorFirstParameterMap,true); 342 initialiseMaps(bioXterParameterMap,false); 343 initialiseMaps(twoColorBioXterParameterMap,false); 344 345 twoColorHybDataRows.add("-done-"); 329 // create the Tab2MageHybridization object 330 Tab2MageHybridization hybridization= new Tab2MageHybridization (); 331 // create the Tab2MageHybridizationLine object 332 Tab2MageHybridizationLine hybRow = new Tab2MageHybridizationLine(); 333 334 // set the number of channels for the Hybridization 335 hybridization.setChannelNumber(validator.getChannelNumber()); // mainly useful during the writing stage 336 346 337 /* 347 Data files and array information section// 348 */ 338 Experimental Factor Section 339 */ 340 AnnotationSet annotationSet =rba.isAnnotated() ? rba.getAnnotationSet() : null; 341 ItemQuery<AnnotationType> experimentalFactorsQuery= experiment.getExperimentalFactors(); 342 experimentalFactorsQuery.include(Include.MINE, Include.SHARED, Include.OTHERS, Include.IN_PROJECT, Include.NOT_REMOVED); 343 ItemResultList<AnnotationType> experimentalFactors = experimentalFactorsQuery.list(dc); 344 for (AnnotationType exprFactor :experimentalFactors) 345 { 346 if (!exprFactor.isRemoved()) 347 { 348 if (annotationSet!=null) 349 { 350 Annotation an= annotationSet.findAnnotation(exprFactor); 351 if (an!=null) //exprFacor has annotations 352 { 353 List<?> values= an.getValues(); 354 hybRow.set("FactorValue", exprFactor.getName(), values==null || values.size()==0 ? "" : Values.getString(values, ", ", true)); 355 } 356 else // exprFactor has no annotations 357 { 358 hybRow.set("FactorValue", exprFactor.getName(), "" ); 359 } 360 } 361 else //The raw bio assay is not annotated 362 { 363 hybRow.set("FactorValue", exprFactor.getName(), "" ); 364 } 365 } 366 } 367 349 368 //Array Design 350 ArrayDesign arrayDesign = rba.getArrayDesign();351 if (arrayDesign.isAffyChip())369 ArrayDesign arrayDesign = null; 370 try 352 371 { 353 File cdfFile= Affymetrix.getCdfFile(arrayDesign); 354 File celFile=Affymetrix.getCelFile(rba); 355 hybSectionHeader.add(Tab2MageConstants.raw_file.getName()); 356 hybridizationDataRows.add(celFile.getName()); 357 twoColorHybDataRows.add(celFile.getName()); 358 hybSectionHeader.add(Tab2MageConstants.cdf_file.getName()); 359 hybridizationDataRows.add(cdfFile.getName()); 360 twoColorHybDataRows.add(cdfFile.getName()); 372 arrayDesign= rba.getArrayDesign(); 361 373 } 362 else374 catch(Throwable tr) 363 375 { 364 hybSectionHeader.add(Tab2MageConstants.raw_file.getName()); 365 hybridizationDataRows.add(rba.getName()); 366 twoColorHybDataRows.add(rba.getName()); 376 response.setError("[EXPORT FAILED: All Array Design(s) must be provided in BASE to continue].",Arrays.asList(tr)); 367 377 } 368 hybSectionHeader.add(Tab2MageConstants.array_accession.getName()); 369 hybridizationDataRows.add(arrayDesign.getName()); 370 twoColorHybDataRows.add(arrayDesign.getName()); 371 372 //Raw BioAssay protocol 373 protocols.add(rba.getProtocol()); 374 if (extractionProtocolCount>0) 375 { 376 protocolHybSectionHeader.add(Tab2MageConstants.protocol_featureextraction.getName()); 377 protocolRefId.add(getFormattedProtocolId(rba.getProtocol())); 378 twoColorFirstProtocolRefId.add(getFormattedProtocolId(rba.getProtocol())); 379 } 380 381 // rba protocol parameters 382 if (rba.isAnnotated()) setParameterValues(rba,dc); 383 384 //Scanning Protocol 378 // Populate the Array file map in HybLine 379 setArraysAttributes(hybRow, arrayDesign ); 380 381 // Populate the Data file map in HybLine 382 setFileAttributes(hybRow, arrayDesign, rba, response); 383 384 //Raw BioAssay protocol and parameter 385 setProtocolAndParameterAtrributes(hybRow,rba,Tab2MageValidator.getFeProtocolCount(), 386 Tab2MageConstants.protocol_featureextraction.getName(), response, dc); 387 388 //Scanning Protocol and Parameters 385 389 Scan scan= rba.getScan(); 386 if (scanningProtocolCount>0) 387 { 388 protocolHybSectionHeader.add(Tab2MageConstants.protocol_scanning.getName()); 389 protocolRefId.add(getFormattedProtocolId(scan.getProtocol())); 390 twoColorFirstProtocolRefId.add(getFormattedProtocolId(scan.getProtocol())); 391 } 392 protocols.add(scan.getProtocol()); // add scanning protocol 393 // Scanning protocol parameter 394 if (scan.isAnnotated()) setParameterValues(scan,dc); 395 396 //Hybridization 390 setProtocolAndParameterAtrributes(hybRow,scan,Tab2MageValidator.getScanningProtocolCount(), 391 Tab2MageConstants.protocol_scanning.getName(),response, dc); 392 393 /* 394 Array Slide 395 */ 397 396 Hybridization hyb= scan.getHybridization(); 398 397 if (hyb.getArraySlide()==null) … … 403 402 else 404 403 { 405 hybSectionHeader.add("Array[serial]"); 406 hybridizationDataRows.add(hyb.getArraySlide().getName()); 407 twoColorHybDataRows.add(hyb.getArraySlide().getName()); 404 hybRow.set("Array","serial", hyb.getArraySlide().getName()); 408 405 } 409 406 410 407 /* 411 Names of materials and processes section408 Hybridization 412 409 */ 413 hybSectionHeader.add(Tab2MageConstants.hybridization.getName()); 414 hybridizationDataRows.add(hyb.getName()); 415 twoColorHybDataRows.add(hyb.getName()); 416 410 hybRow.set(Tab2MageConstants.hybridization.getName(), null,hyb.getName()); 417 411 BioMaterialEvent bioMaterialEvent= hyb.getCreationEvent(); // an event that created the hyridization 418 419 Protocol hybProtocol= bioMaterialEvent.getProtocol(); //hybridization protocol 420 protocols.add(hybProtocol); 421 422 if (hybridizationProtocolCount>0) 423 { 424 protocolHybSectionHeader.add(Tab2MageConstants.protocol_hyb.getName()); 425 protocolRefId.add(getFormattedProtocolId(hybProtocol)); 426 twoColorFirstProtocolRefId.add(getFormattedProtocolId(hybProtocol)); 427 } 428 // Hybridization protocol parameter 429 if (hyb.isAnnotated()) setParameterValues(hyb,dc); 430 412 413 // Hybridization protocol and parameter 414 setProtocolAndParameterAtrributes(hybRow,hyb,Tab2MageValidator.getHybridizationProtocolCount(), 415 Tab2MageConstants.protocol_hyb.getName(), response, dc); 416 431 417 ItemQuery<LabeledExtract> labeledExtractQuery =(ItemQuery<LabeledExtract>) bioMaterialEvent.getSources(); // get all the labeled extract 432 418 ItemResultList<LabeledExtract> labeledExtracts= labeledExtractQuery .list(dc); 433 int hybsize=labeledExtracts.size(); 434 int count=1; 435 for (LabeledExtract labeledExtract :labeledExtracts) // can have more than one labeled extract (2 color experiments) 419 int size = labeledExtracts.size(); 420 421 // create the Tab2MageSubHybLine object List 422 List<Tab2MageSubHybLine> subLines = new ArrayList<Tab2MageSubHybLine>(); 423 424 int count=1; // initialise the count variable to 1 425 // Loop through all the labeled extracts 426 for (LabeledExtract labeledExtract :labeledExtracts) // can have more than one labeled extract (e.g. 2 color experiments) 436 427 { 437 // labeled extract 438 hybSectionHeader.add(Tab2MageConstants.labeledextract.getName()); 428 //create the new SubHyb Line 429 Tab2MageSubHybLine subLine = new Tab2MageSubHybLine(); 430 431 /* 432 labeled extract 433 */ 439 434 Protocol lbExtractProtocol= labeledExtract.getCreationEvent().getProtocol(); 440 protocols.add(lbExtractProtocol); // labeled extract protocol 441 if (labelingProtocolCount>0)protocolHybSectionHeader.add(Tab2MageConstants.protocol_labeling.getName()); 442 if (count<hybsize || count==1) 443 { 444 hybridizationDataRows.add(labeledExtract.getName()); 445 if (labelingProtocolCount>0) protocolRefId.add(getFormattedProtocolId(lbExtractProtocol)); 446 } 447 else if (count==2) 448 { 449 twoColorHyb=true; 450 twoColorHybDataRows.add(labeledExtract.getName()); 451 if (labelingProtocolCount>0)twoColorProtocolRefId.add(getFormattedProtocolId(lbExtractProtocol)); 452 } 453 // labelling protocol parameter 454 setParameterValues(labeledExtract,dc, count, hybsize); 455 456 // Label 435 subLine.set(Tab2MageConstants.labeledextract.getName(), null, labeledExtract.getName()); 436 437 // labelling protocol and parameter 438 setProtocolAndParameterAtrributes(dc, subLine,labeledExtract,Tab2MageValidator.getLabelingProtocolCount(), 439 Tab2MageConstants.protocol_labeling.getName(),lbExtractProtocol, response); 440 /* 441 Label 442 */ 457 443 String labelName= labeledExtract.getLabel().getName(); // the name of the label 458 hybSectionHeader.add(Tab2MageConstants.dye.getName()); 459 if (count < hybsize || count==1) 460 { 461 hybridizationDataRows.add(labelName); 462 } 463 else if (count==2) 464 { 465 twoColorHybDataRows.add(labelName); 466 } 467 468 // Extract 469 Extract extract= labeledExtract.getExtract(); 444 subLine.set(Tab2MageConstants.dye.getName(), null,labelName); 445 446 /* 447 Extract 448 */ 449 450 Extract extract= ExportHelper.getExtract(labeledExtract, dc); 470 451 if (extract!=null) 471 452 { 472 hybSectionHeader.add(Tab2MageConstants.extract.getName());473 453 Protocol extractProtocol =extract.getCreationEvent().getProtocol(); //extract protocol 474 if (extractProtocolCount>0) protocolHybSectionHeader.add(Tab2MageConstants.protocol_extraction.getName()); 475 protocols.add(extractProtocol); 476 if (count < hybsize || count==1) 477 { 478 hybridizationDataRows.add(extract.getName()); 479 if (extractProtocolCount>0)protocolRefId.add(getFormattedProtocolId(extractProtocol)); 480 } 481 else if (count==2) 482 { 483 twoColorHybDataRows.add(extract.getName()); 484 if (extractProtocolCount>0)twoColorProtocolRefId.add(getFormattedProtocolId(extractProtocol)); 485 } 486 // extraction protocol parameter 487 setParameterValues(extract,dc,count,hybsize); 454 subLine.set(Tab2MageConstants.extract.getName(), null, extract.getName()); 455 456 // extraction protocol and parameter 457 setProtocolAndParameterAtrributes(dc, subLine,extract,Tab2MageValidator.getExtractProtocolCount(), 458 Tab2MageConstants.protocol_extraction.getName(), extractProtocol, response); 488 459 } 489 460 490 //Sample 491 Sample sample =extract.getSample(); // The sample, extract is created from 461 /* 462 Sample 463 */ 464 465 Sample sample= ExportHelper.getSample(extract, dc); 492 466 if (sample != null) 493 467 { 494 hybSectionHeader.add(Tab2MageConstants.sample.getName());495 468 Protocol sampleProtocol=sample.getCreationEvent().getProtocol(); //sampling protocol 496 if (samplingProtocolCount>0)protocolHybSectionHeader.add(Tab2MageConstants.protocol_treatment.getName()); 497 protocols.add(sampleProtocol); 498 if (count < hybsize || count==1) 469 subLine.set(Tab2MageConstants.sample.getName(), null, sample.getName()); 470 471 // sampling protocol and parameter 472 setProtocolAndParameterAtrributes(dc, subLine,sample,Tab2MageValidator.getSamplingProtocolCount(), 473 Tab2MageConstants.protocol_treatment.getName(),sampleProtocol, response ); 474 } 475 476 /* 477 Biosource 478 */ 479 480 BioSource bioSource=ExportHelper.getBioSource(sample, dc); 481 if (bioSource != null) 482 { 483 subLine.set(Tab2MageConstants.biosource.getName(), null, bioSource.getName()); 484 485 //section for biomaterial xterixtics 486 ItemQuery<Annotation> query = bioSource.getAnnotationSet().getAnnotations(); 487 query.include(Include.MINE, Include.NOT_REMOVED, Include.IN_PROJECT,Include.SHARED); 488 List<Annotation> annotations = query.list(dc); 489 for (Annotation annotation: annotations) 499 490 { 500 hybridizationDataRows.add(sample.getName()); 501 if (samplingProtocolCount>0)protocolRefId.add(getFormattedProtocolId(sampleProtocol)); 502 } 503 else if (count==2) 504 { 505 twoColorHybDataRows.add(sample.getName()); 506 if (samplingProtocolCount>0) twoColorProtocolRefId.add(getFormattedProtocolId(sampleProtocol)); 507 } 508 // sampling protocol parameter 509 setParameterValues(sample,dc,count,hybsize); 510 } 511 512 // Biosource 513 Set<BioSource> bioSources= new LinkedHashSet(); 514 if (sample.isPooled()) 515 { 516 pooledSampleFlag=true; 517 poolSampleHeader.addAll(hybridizationDataRows); 518 519 bioSources.addAll(ExporHelper.getBiosources(sample, dc)); 520 } 521 else if (!sample.isPooled()) 522 { 523 bioSources.add(sample.getBioSource()); 524 } 525 int bioSourceCount=1; 526 for (BioSource bioSource: bioSources) 527 { 528 if (bioSource!=null) 529 { 530 hybSectionHeader.add(Tab2MageConstants.biosource.getName()); 531 if (count < hybsize || count==1) 491 AnnotationType at=annotation.getAnnotationType(); 492 if(!at.isRemoved()) 532 493 { 533 if (bioSourceCount==1) // this caters for the the first Biosource for pooling and non pooling 534 { 535 hybridizationDataRows.add(bioSource.getName()); 536 } 537 else if (pooledSampleFlag && bioSourceCount>1) // this cater for other biources when samples were pooled 538 { 539 poolSampleTail.add(bioSource.getName()); 540 } 541 } 542 else if(count==2) 543 { 544 twoColorHybDataRows.add(bioSource.getName()); 545 if (pooledSampleFlag && bioSourceCount>1) poolSampleTail.add(bioSource.getName()); 546 } 547 548 //section for biomaterial xterixtics 549 List<Annotation> annotations = bioSource.getAnnotationSet().getAnnotations().list(dc); 550 for (Annotation annotation: annotations) 551 { 552 AnnotationType at=annotation.getAnnotationType(); 553 if(!at.isRemoved()) 554 { 555 List<?> values= annotation==null? null:annotation.getValues(); 556 if (count < hybsize || count==1) 557 { 558 if (bioSourceCount==1) // this caters for the the first Biosource for pooling and non pooling 559 { 560 for (String header : bioXterParameterMap.keySet()) 561 { 562 if (header.equals(annotation.getAnnotationType().getName())) 563 { 564 bioXterParameterMap.replace(header, values==null || values.size()==0 ? getDefaultValue(at) : Values.getString(values, ", ", true)); 565 } 566 } 567 } 568 else if (pooledSampleFlag && bioSourceCount>1) // this cater for other biources when samples were pooled 569 { 570 poolSampleTail.add(values==null || values.size()==0 ? getDefaultValue(at) : Values.getString(values, ", ", true)); 571 } 572 } 573 else if(count==2) 574 { 575 for (String header : twoColorBioXterParameterMap.keySet()) 576 { 577 if (header.equals(annotation.getAnnotationType().getName())) 578 { 579 twoColorBioXterParameterMap.replace(header, values==null || values.size()==0 ? getDefaultValue(at) : Values.getString(values, ", ", true)); 580 } 581 } 582 if (pooledSampleFlag && bioSourceCount>1) poolSampleTail.add(values==null || values.size()==0 ? getDefaultValue(at) : Values.getString(values, ", ", true)); 583 } 584 } 585 } 586 } 587 if (pooledSampleFlag && bioSourceCount>1) poolSampleTail.add("--*poolend*--"); 588 bioSourceCount++; 589 } 590 count++; 591 592 } //end of labeled extract loop 593 594 /* 595 Populate the Hyb data row before display 596 */ 597 for (Map.Entry<String, String> e: bioXterParameterMap.entrySet()) 598 { 599 hybridizationDataRows.add(e.getValue()); 600 bioXterHybSectionHeader.add(e.getKey()); 601 } 602 if (twoColorHyb) 603 { 604 for (Map.Entry<String, String> e: twoColorBioXterParameterMap.entrySet()) 605 { 606 twoColorHybDataRows.add(e.getValue()); 607 } 608 } 609 // add protocol hyb ref ids 610 for (String protcolId : protocolRefId) //add protocol id 611 { 612 hybridizationDataRows.add(protcolId); 613 } 614 if (twoColorHyb) 615 { 616 twoColorFirstProtocolRefId.addAll(twoColorProtocolRefId); 617 for (String protocolId : twoColorFirstProtocolRefId ) 618 { 619 twoColorHybDataRows.add(protocolId); 620 } 621 } 622 // add parameter values 623 624 for (Map.Entry<String, String> entry: parameterMap.entrySet()) 625 { 626 hybridizationDataRows.add(entry.getValue()); 627 parameterHybSectionHeader.add(entry.getKey()); 628 } 629 if (twoColorHyb) 630 { 631 for (Map.Entry<String, String> firstMapE :twoColorFirstParameterMap.entrySet()) 632 { 633 for (Map.Entry<String, String> mapE :twoColorParameterMap.entrySet()) 634 { 635 if (firstMapE.getKey().equals(mapE.getKey())) 636 { 637 twoColorFirstParameterMap.replace(firstMapE.getKey(), firstMapE.getValue()==""? mapE.getValue():"" ) ; 494 List<?> values= annotation==null? null:annotation.getValues(); 495 subLine.set(Tab2MageConstants.bio_mat_charact.getName(), annotation.getAnnotationType().getName(), 496 values==null || values.size()==0 ? ExportHelper.getDefaultValue(at) : Values.getString(values, ", ", true)); 638 497 } 639 498 } 640 499 } 641 for (String paramValue : twoColorFirstParameterMap.values()) 642 { 643 twoColorHybDataRows.add(paramValue); 644 } 500 501 subLines.add(subLine); //make a list of subLines 502 count++; 503 } //end of labeled extract loop 504 505 hybRow.addHybSubLines(size, hybRow.getName(), subLines); // add the subLines (i.e. Tab2MageSubHybLine objectc list to Tab2MageHybridizationLine Object 506 507 hybridization.addLine(hybRow); // add Tab2MageHybridizationLine Object to Tab2MageHybridization object 508 if(!hybs.contains(hybridization)) 509 hybs.add(hybridization); // add Tab2MageHybridization Object to the List of Tab2MageHybridization object 510 511 }// end of raw biossay for loop 512 513 // create headers for biomaterial xteristics 514 Set<String> bioMatHeaders = new LinkedHashSet<String>(); 515 516 //create headers for the parameters 517 Set<String> paramHeaders = new LinkedHashSet<String>(); 518 519 //create headers for experimental factor values 520 Set<String> factorValueHeaders = new LinkedHashSet<String>(); 521 522 for (Tab2MageHybridization h : hybs) 523 { 524 525 Tab2MageHybridizationLine l = h.getLine(); 526 527 // add headers to main parameter header list 528 paramHeaders.addAll(ExportHelper.getHeaderWithValuesOnly(l.getParameter())); 529 530 for (Tab2MageSubHybLine sl: l.getSubLineSet()) 531 { 532 // get the headers for biomaterial xteristics and add to biomaterial xteristics header set 533 bioMatHeaders.addAll(ExportHelper.getHeaderWithValuesOnly(sl.getBioMaterialCharacteristics())); 534 // get the parameter values headers and add to the set of parameter headers 535 paramHeaders.addAll(ExportHelper.getHeaderWithValuesOnly(sl.getParameter())); 536 645 537 } 646 538 647 /* 648 Experimental Factor Section 649 */ 650 expFactorValues=getExperimentalFactorValues(dc,experiment,rba); 651 for(Annotation value: expFactorValues) 652 { 653 if (value!=null) 654 { 655 List<?> values= value.getValues(); 656 hybridizationDataRows.add(values==null || values.size()==0 ? "" : Values.getString(values, ", ", true)); 657 if (twoColorHyb) twoColorHybDataRows.add(values==null || values.size()==0 ? "" : Values.getString(values, ", ", true)); 658 } 659 else 660 { 661 hybridizationDataRows.add(""); 662 if (twoColorHyb) twoColorHybDataRows.add(""); 663 } 664 } 665 666 if (twoColorHyb)hybridizationDataRows.addAll(twoColorHybDataRows); 667 668 669 // clear all necessary data holder for reuse 670 parameterMap.clear(); 671 twoColorParameterMap.clear(); 672 twoColorFirstParameterMap.clear(); 673 bioXterParameterMap.clear(); 674 twoColorBioXterParameterMap.clear(); 675 protocolRefId.clear(); 676 parameterValues.clear(); 677 factorValues.clear(); 678 twoColorParameterValues.clear(); 679 twoColorFirstParameterValues.clear(); 680 twoColorFirstProtocolRefId.clear(); 681 twoColorProtocolRefId.clear(); 682 683 if (!twoColorHybDataRows.isEmpty()) 684 { 685 twoColorHybDataRows.clear(); 686 twoColorHyb=false; 687 } 688 689 poolSampleHeader.clear(); 690 poolSampleTail.clear(); 691 692 hybridizationDataRows.add(Tab2MageConstants.hybrow_delimeter.getName()); 693 }// end of raw biossay for loop 694 695 //add headers 696 for (String bioXterHeader: bioXterHybSectionHeader) 697 { 698 hybSectionHeader.add("BioMaterialCharacteristics["+bioXterHeader+"]"); 699 } 700 for (String protocolHeader: protocolHybSectionHeader) 701 { 702 hybSectionHeader.add(protocolHeader); 703 } 704 for (String parameterHeader :parameterHybSectionHeader) 705 { 706 hybSectionHeader.add("Parameter["+parameterHeader+"]"); 707 } 708 for (String factorValueHeader :factorValuesHybSectionHeader) 709 { 710 hybSectionHeader.add(factorValueHeader); 539 // get the headers for the experiment factor values and add to experimental factor values header set 540 factorValueHeaders.addAll(ExportHelper.getHeaderWithValuesOnly(l.getFactorValues())); 711 541 } 712 542 713 543 /* 714 Write the tab2mage file544 Create all the used protocols objects 715 545 */ 716 Tab2MageWriter.writeTab2MageFile(experiment, protocols, hybSectionHeader, hybridizationDataRows, job, response, dc); 717 546 protocols = ExportHelper.createProtocols(rawBioAssays, dc); 547 548 /* 549 create all used Tab2Mage Hybridization sections protocol headers 550 */ 551 protocolHybSectionHeader= Tab2MageValidator.getProtocolHybSectionHeader(); 552 553 /* 554 Create Tab2Mage Hybridization Section Header 555 */ 556 557 hybSectionHeader= ExportHelper.createHybridizationSectionHeader(dc,hybs,bioMatHeaders, 558 protocolHybSectionHeader, paramHeaders, factorValueHeaders); 559 /* 560 Write the tab2mage file 561 */ 562 563 Tab2MageFileWriter.writeTab2MageFile(experiment, protocols,hybs, hybSectionHeader,bioMatHeaders, 564 protocolHybSectionHeader, paramHeaders,factorValueHeaders, job, response, dc); 565 718 566 //statusOut.close(); 719 Writer out= Tab2Mage Writer.getOut();567 Writer out= Tab2MageFileWriter.getOut(); 720 568 out.flush(); 721 569 out.close(); … … 730 578 { 731 579 if (dc != null) dc.close(); 732 scanningProtocolCount=0;733 extractionProtocolCount=0;734 hybridizationProtocolCount=0;735 labelingProtocolCount=0;736 extractProtocolCount=0;737 samplingProtocolCount=0;738 newParameterHybSectionHeader.clear();739 bioMatXteristicsHeader.clear();740 bioXterHybSectionHeader.clear();741 factorValuesHybSectionHeader.clear();742 parameterHybSectionHeader.clear();743 580 } 744 581 } 745 582 746 583 /** 747 get all the experimental factors for an experiments 748 @param DcControl dc, the database control 749 @param Experiment experiment, the experiment 750 @param RawBioassay, the rawbioassay that the experimental factors are obtained from 751 @return List, list of annotations 752 */ 753 private static List<Annotation> getExperimentalFactorValues(DbControl dc, Experiment experiment, RawBioAssay rba) 754 { 755 List<Annotation> values= new LinkedList<Annotation>(); 756 AnnotationSet annotationSet = rba.isAnnotated() ? rba.getAnnotationSet() : null; 757 ItemQuery<AnnotationType> experimentalFactorsQuery= experiment.getExperimentalFactors(); 758 experimentalFactorsQuery.include(Include.MINE, Include.SHARED, Include.OTHERS, Include.IN_PROJECT); 759 ItemResultList<AnnotationType> experimentalFactors = experimentalFactorsQuery.list(dc); 760 if (annotationSet!=null) 761 { 762 for (AnnotationType exprFactor :experimentalFactors) 763 { 764 if (!exprFactor.isRemoved()) 765 { 766 //factorValuesHybSectionHeader.add("FactorValue["+exprFactor.getName()+"]"); 767 values.add(annotationSet.findAnnotation(exprFactor)); 768 if (annotationSet.findAnnotation(exprFactor)!=null)factorValuesHybSectionHeader.add("FactorValue["+exprFactor.getName()+"]"); 769 } 770 } 771 } 772 return values; 584 set the array attributes of the the <code>Tab2MageHybridizationLine</code> object 585 @param hybRow, the <code>Tab2MageHybridizationLine</code> object 586 @param arrayDesign, the Array Design 587 */ 588 private void setArraysAttributes (Tab2MageHybridizationLine hybRow, ArrayDesign arrayDesign ) 589 { 590 hybRow.set("Array",Tab2MageConstants.array_accession.getName(),arrayDesign.getName()); 773 591 } 774 592 775 593 /** 776 Gets the base format id for the protocol, if protocol is null an empty string is returned 777 this is required to have consistent tab delimited format 778 @param protocol, the protocol used in the experiment 779 @return protocol id, an empty string is returned when the protocol is null 780 */ 781 private static String getFormattedProtocolId (Protocol protocol) 782 { 783 String tab=""; 784 String protocolId; 785 if (protocol!=null) 786 { 787 protocolId = "P-BASE-"+protocol.getId(); 788 } 789 else 790 { 791 protocolId= tab; 792 } 793 return protocolId ; 594 set the file attributes of the the <code>Tab2MageHybridizationLine</code> object 595 @param hybRow, the Tab2MageHybridizationLine object 596 @param arrayDesign, the Array Design 597 @param rba, the raw bio assay 598 @param response, the response object to return errors in case of failure during the setting of file values 599 */ 600 private void setFileAttributes(Tab2MageHybridizationLine hybRow, ArrayDesign arrayDesign, RawBioAssay rba, Response response) 601 { 602 try 603 { 604 if (arrayDesign.isAffyChip()) 605 { 606 File cdfFile= Affymetrix.getCdfFile(arrayDesign); 607 File celFile=Affymetrix.getCelFile(rba); 608 hybRow.set("File", Tab2MageConstants.raw_file.getName(), celFile.getName()); 609 hybRow.set("File",Tab2MageConstants.cdf_file.getName(), cdfFile.getName()); 610 } 611 else 612 { 613 hybRow.set("File", Tab2MageConstants.raw_file.getName(), rba.getName()); 614 } 615 616 } 617 catch(Throwable tr) 618 { 619 response.setError(tr.getMessage(), Arrays.asList(tr)); 620 } 794 621 } 795 622 /** 796 Set all resource counters used within an experiment 797 @param experiment, the experiment 798 @param dc, the database control object 623 set the protocol and parameters attributes/values for Labeling -to- Sampling protocol and parameters 624 @param dc, the database control 625 @param subLine, the <code>Tab2MageSubHybLine</code> object 626 @param anotatable, the annotatable item to extract protocol and parameters from 627 @param protocolCount, the number of protocols already identified for the annotatable item 628 @param keyEntry, the header to set for the protocol in the <code>SubHybridizationLine</code> protocol map attributes 629 @param protocol, the protocol object 630 @param response, the response object to return errors in case of failure during the setting of parameter values 799 631 */ 800 @SuppressWarnings({"deprecation","unchecked"}) 801 private static void getResourceCounter(Experiment experiment,DbControl dc) 802 { 803 ItemResultList<RawBioAssay> rbas= experiment.getRawBioAssays().list(dc); 804 for (RawBioAssay rba : rbas) 805 { 806 if (rba.getProtocol()!=null) 807 { 808 extractionProtocolCount++ ; 809 getParameterSectionHeader(rba, dc ); 810 } 811 if (rba.getScan().getProtocol()!=null) 812 { 813 scanningProtocolCount++; 814 getParameterSectionHeader(rba.getScan(), dc ); 815 } 816 if (rba.getScan().getHybridization().getProtocol()!=null) 817 { 818 hybridizationProtocolCount++; 819 getParameterSectionHeader(rba.getScan().getHybridization(), dc ); 820 } 821 ItemResultList<LabeledExtract>labeledExtracts = (ItemResultList<LabeledExtract>) 822 rba.getScan().getHybridization().getCreationEvent().getSources().list(dc); 823 for (LabeledExtract labeledExtract :labeledExtracts) 824 { 825 if (labeledExtract.getProtocol()!=null) 826 { 827 labelingProtocolCount++; 828 getParameterSectionHeader(labeledExtract, dc ); 829 } 830 if (labeledExtract.getExtract().getProtocol()!=null) 831 { 832 extractProtocolCount++; 833 getParameterSectionHeader(labeledExtract.getExtract(), dc ); 834 } 835 if (labeledExtract.getExtract().getSample().getProtocol()!=null) 836 { 837 samplingProtocolCount++; 838 getParameterSectionHeader(labeledExtract.getExtract().getSample(), dc ); 839 } 840 if (labeledExtract.getExtract().getSample().getBioSource()!=null) 841 setAllBioMatXteristicsHeader(labeledExtract.getExtract().getSample().getBioSource(),dc); 842 } 843 } 844 } 632 private void setProtocolAndParameterAtrributes(DbControl dc,Tab2MageSubHybLine subLine, Annotatable anotatable, int protocolCount, String keyEntry, Protocol protocol, Response response) 633 { 634 if (protocolCount>0) 635 { 636 subLine.set("Protocol",keyEntry,ExportHelper.getFormattedProtocolId(protocol)); 637 } 638 639 // MeasuredBioMaterial protocol parameters 640 if (anotatable.isAnnotated()) setParameterValues(anotatable,dc, null,subLine, response); 641 } 642 845 643 /** 846 Gets the used annotation types (parameters) for an annotatable item 847 @param annotatable, an item that implements annotatable 848 @param dc, the database control object 644 set the protocol and parameters attributes/values for Image_Analysis -to- Hybridization protocol and parameters 645 @param hybRow, the Tab2MageHybridizationLine object 646 @param anotatable, the annotatable item to extract protocol and parameters from 647 @param protocolCount, the number of protocols already identified for the annotatable item 648 @param keyEntry, the header to set for the protocol in the <code>SubHybridizationLine</code> protocol map attributes 649 @param protocol, the protocol object 650 @param response, the response object to return errors in case of failure during the setting of parameter values 651 @param dc, the database control 849 652 */ 850 851 private static void getParameterSectionHeader(Annotatable anotatable, DbControl dc ) 852 { 853 ItemResultList<Annotation> annotations = anotatable.getAnnotationSet().getAnnotations().list(dc); 854 for (Annotation annotation: annotations) 855 { 856 if (anotatable.getProtocol().isParameter(annotation.getAnnotationType()) && !annotation.getAnnotationType().isRemoved()) 857 newParameterHybSectionHeader.add(annotation.getAnnotationType().getName()); 858 } 859 //Helper.displayParameterHeader(newParameterHybSectionHeader); 860 } 861 /** 862 Gets the annotation types used as biomaterial characteristics for an annotatable item 863 @param annotatable, an item that implements annotatable 864 @param dc, the database control object 865 */ 866 867 private static void setAllBioMatXteristicsHeader(Annotatable anotatable, DbControl dc) 868 { 869 List<Annotation> annotations = anotatable.getAnnotationSet().getAnnotations().list(dc); 870 for (Annotation annotation: annotations) 871 { 872 AnnotationType at=annotation.getAnnotationType(); 873 if(!at.isRemoved()) 874 bioMatXteristicsHeader.add(at.getName()); 875 } 876 } 877 878 /** 879 initialises the maps required to manage tab2mage data 880 @param map, the map to be intitialised 881 @param isForParameter, TRUE if map is for parameters and FALSE otherwise 882 */ 883 884 private static void initialiseMaps(ConcurrentHashMap<String,String> map, boolean isForParameter) 885 { 886 if (map.isEmpty()) 887 { 888 if (isForParameter) 889 { 890 for (String param: newParameterHybSectionHeader) 891 { 892 if (param!=null) map.put(param, ""); 893 } 894 } 895 else if (!isForParameter) 896 { 897 for (String bioXterParam: bioMatXteristicsHeader) 898 { 899 if (bioXterParam!=null) map.put(bioXterParam, ""); 900 } 901 } 902 } 903 } 653 private void setProtocolAndParameterAtrributes(Tab2MageHybridizationLine hybRow, Annotatable anotatable, int protocolCount,String keyEntry, Response response, DbControl dc) 654 { 655 if (protocolCount>0) 656 { 657 hybRow.set("Protocol", keyEntry, ExportHelper.getFormattedProtocolId(anotatable.getProtocol())); 658 } 659 // protocol parameter 660 if (anotatable.isAnnotated()) setParameterValues(anotatable,dc, hybRow,null, response); 661 662 } 663 904 664 /** 905 665 sets protocol parameter values … … 907 667 @param dc, the dabatabase control 908 668 */ 909 private static void setParameterValues(Annotatable anotatable, DbControl dc) 910 { 911 ItemResultList<Annotation> annotations = anotatable.getAnnotationSet().getAnnotations().list(dc); 912 for (Annotation annotation: annotations) 913 { 914 if (anotatable.getProtocol()!=null) // only check if the annotation is not null, watch this! 915 { 916 if (anotatable.getProtocol().isParameter(annotation.getAnnotationType()) && !annotation.getAnnotationType().isRemoved()) 917 { 918 List<?> values= annotation.getValues(); 919 for (String header : parameterMap.keySet()) 669 private static void setParameterValues(Annotatable anotatable, DbControl dc, Tab2MageHybridizationLine hybRow, Tab2MageSubHybLine subLine, Response response) 670 { 671 try 672 { 673 ItemResultList<Annotation> annotations = anotatable.getAnnotationSet().getAnnotations().list(dc); 674 for (Annotation annotation: annotations) 675 { 676 if (anotatable.getProtocol()!=null) // only check if the annotation is not null, watch this! 677 { 678 if (anotatable.getProtocol().isParameter(annotation.getAnnotationType()) && !annotation.getAnnotationType().isRemoved()) 920 679 { 921 if (header.equals(annotation.getAnnotationType().getName())) 922 { 923 parameterMap.replace(header, "", values==null || values.size()==0 ? "" : Values.getString(values, ", ", true)); 924 } 925 } 926 for (String twoColorFirstHeader : twoColorFirstParameterMap.keySet()) 927 { 928 if (twoColorFirstHeader.equals(annotation.getAnnotationType().getName())) 929 { 930 twoColorFirstParameterMap.replace(twoColorFirstHeader, "", values==null || values.size()==0 ? "" : Values.getString(values, ", ", true)); 931 } 680 List<?> values= annotation.getValues(); 681 AnnotationType at= annotation.getAnnotationType(); 682 if (hybRow!=null) 683 hybRow.set("Parameter", at.getName(), values==null || values.size()==0 ? "" : Values.getString(values, ", ", true)); 684 if (subLine!=null) 685 subLine.set("Parameter", at.getName(), values==null || values.size()==0 ? "" : Values.getString(values, ", ", true)); 932 686 } 933 687 } 934 688 } 935 689 } 936 } 690 catch(Throwable tr) 691 { 692 response.setError(tr.getMessage(), Arrays.asList(tr)); 693 } 694 695 } 696 937 697 /** 938 sets protocol parameter values 939 @param anotatable, the annotatable item 940 @param dc, the database control 941 @param count, the two channel count 942 @param hybsize, the number of labeled extract to a Hybridization. 698 get headers from the concurrent hasp maps 699 @return set of string : headers 943 700 */ 944 private static void setParameterValues (Annotatable anotatable, DbControl dc, int count, int hybsize ) 945 { 946 ItemResultList<Annotation> annotations = anotatable.getAnnotationSet().getAnnotations().list(dc); 947 for (Annotation annotation: annotations) 948 { 949 if (anotatable.getProtocol()!=null) 950 { 951 if (anotatable.getProtocol().isParameter(annotation.getAnnotationType()) && !annotation.getAnnotationType().isRemoved()) 952 { 953 List<?> values= annotation.getValues(); 954 if (count < hybsize || count==1) 955 { 956 for (String header : parameterMap.keySet()) 957 { 958 if (header.equals(annotation.getAnnotationType().getName())) 959 { 960 parameterMap.replace(header, "", values==null || values.size()==0 ? "" : Values.getString(values, ", ", true)); 961 } 962 } 963 } 964 else if(count==2) 965 { 966 for (String twoColorHeader : twoColorParameterMap.keySet()) 967 { 968 if (twoColorHeader.equals(annotation.getAnnotationType().getName())) 969 { 970 twoColorParameterMap.replace(twoColorHeader, "", values==null || values.size()==0 ? "" : Values.getString(values, ", ", true)); 971 } 972 } 973 } 974 } 975 } 976 } 977 } 978 701 public static Set<String> getHeaders(ConcurrentHashMap<String,String> map) 702 { 703 Set<String> headers= new LinkedHashSet<String>(); 704 headers.addAll(map.keySet()); 705 return headers; 706 } 707 979 708 /** 980 gets the default value of an annotation type, used when annotation value is null 981 @param at, annotation type to obtain the default value from 982 @return string, deafult value or an empty string if the default value is null 709 List of Hybridizations 983 710 */ 984 private static String getDefaultValue(AnnotationType at) 985 { 986 987 return at.getDefaultValue()!=null? at.getDefaultValue():""; 988 } 989 private static int scanningProtocolCount=0; 990 private static int extractionProtocolCount=0; 991 private static int hybridizationProtocolCount=0; 992 private static int labelingProtocolCount=0; 993 private static int extractProtocolCount=0; 994 private static int samplingProtocolCount=0; 995 private static ConcurrentHashMap<String,String> parameterMap = new ConcurrentHashMap<String, String>(); 996 private static ConcurrentHashMap<String,String> twoColorParameterMap = new ConcurrentHashMap<String, String>(); 997 private static ConcurrentHashMap<String,String> twoColorFirstParameterMap = new ConcurrentHashMap<String, String>(); 998 private static ConcurrentHashMap<String,String> bioXterParameterMap = new ConcurrentHashMap<String, String>(); 999 private static ConcurrentHashMap<String,String> twoColorBioXterParameterMap = new ConcurrentHashMap<String, String>(); 1000 private static Set<String> factorValuesHybSectionHeader= new LinkedHashSet<String>(); 1001 private static Set<String> parameterHybSectionHeader= new LinkedHashSet<String>(); 1002 private static Set<String> newParameterHybSectionHeader= new LinkedHashSet<String>(); 1003 private static Set<String> bioMatXteristicsHeader= new LinkedHashSet<String>(); 1004 private static Set<String> bioXterHybSectionHeader= new LinkedHashSet<String>(); 711 private List<Tab2MageHybridization> hybs = new ArrayList<Tab2MageHybridization>(); 712 1005 713 } 714 -
trunk/uk/ac/ebi/Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageValidator.java
r396 r449 1 /* $Id: Tab2MageValidator.java 2007-10-01 dominic $ 2 3 Copyright (C) 2007 Authors contributing to this file. 4 5 This file is for NutriBASE - Nutrigenomics BioArray Software Environment. 6 A customisation of the BASE SOFTWARE. 7 8 BASE is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public License 10 as published by the Free Software Foundation; either version 2 11 of the License, or (at your option) any later version. 12 13 BASE is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place - Suite 330, 21 Boston, MA 02111-1307, USA. 22 */ 1 23 package uk.ac.ebi.nugo.plugins.ta2mageexport; 2 24 25 import java.util.Arrays; 3 26 import java.util.LinkedHashSet; 27 import java.util.LinkedList; 4 28 import java.util.List; 5 29 import java.util.Set; 30 import java.util.concurrent.ConcurrentHashMap; 6 31 7 32 import net.sf.basedb.core.Annotatable; 8 33 import net.sf.basedb.core.Annotation; 34 import net.sf.basedb.core.AnnotationSet; 9 35 import net.sf.basedb.core.AnnotationType; 36 import net.sf.basedb.core.BioSource; 10 37 import net.sf.basedb.core.DbControl; 11 38 import net.sf.basedb.core.Experiment; 39 import net.sf.basedb.core.Extract; 40 import net.sf.basedb.core.Include; 41 import net.sf.basedb.core.ItemQuery; 12 42 import net.sf.basedb.core.ItemResultList; 13 43 import net.sf.basedb.core.LabeledExtract; 14 44 import net.sf.basedb.core.RawBioAssay; 15 16 /* 17 What the validation class should do: (for next implementation) 18 Export NO FAILURE 19 ---- 20 if raw bioassay data have no protocol, export but report 'missing feature extraction protocol' 21 22 if raw bioassay data are of type 'Affymetrix' but have no CEL file, export but report missing CEL file (AE may refuse your submission) 23 24 if scan has no protocol or no scanner, export but report 'missing scanning protocol (MIAME data)' and/or 'missing scanner' 25 26 if hybridization has no protocol or no hardware, export report 'missing hybridization protocol (MIAME data)' and/or 'missing hardware' 27 28 if hybridization has no ArraySlide, export but report 'missing ArraySlide (barcode) information' 29 30 Note: There is no need to fail here as the ArrayDesign information can be rescued from the Scan (please check) 31 32 if labeled extract has no protocol, export but report 'missing labeling protocol (MIAME data)' 33 34 if extract has no protocol, export but report 'missing extraction protocol (MIAME data)' 35 36 if sample has no protocol, export but report 'missing sampling protocol (MIAME data)' 37 38 IMPORTANT: There is probably a need for keeping track of how many protocols are missing for every records, so that if no protocols are used, then the export should output a BIG error message: 39 'Tab2mage submission incomplete: you must provide which protocols have been used and with which item ' 40 41 This is where the Experiment overview if a complementary effort to the tab2mage plugin: it already has a facility for checking all missing items) 42 43 44 if biosource has no annotationtype 'Species' reported, export but report 'Key MIAME annotation missing: AE may refuse your submission' 45 46 if Experiment has no Experimental Factor declared and Experimental design and experiment design type are missing, export but report missing information (AE may refuse your submission) 47 48 if Protocol description is empty or less than 25 characters in length, export but report 'description is too short and may compromise MIAME compliance' 49 FAILURE - No Export 50 ---- 51 if raw bioassay data has no ArrayDesign or no Scan associated, then FAIL and report cause of failure=link missing between Raw Bioassay and Scan, or/and. Raw Bioassay data and ArrayDesign 52 53 (scan and hyb are automatically associated so no risk of breakage here) 54 55 if hybridization has no labeled extract associated, then FAIL and report cause of failure=link missing between Hyb and Labeled Extract 56 if labeled extract has no parent 'Extract', FAIL and report cause of failure=link missing between extracts and labeled extract 57 if extract has no parent 'Sample', FAIL and report cause of failure=link missing between sample and extract 58 if sample has no parent 'BioSource', FAIL and report cause of failure=link missing between biosource and sample 59 45 import net.sf.basedb.core.Sample; 46 import net.sf.basedb.core.SessionControl; 47 import net.sf.basedb.core.plugin.Response; 48 49 import org.apache.log4j.Logger; 50 51 import uk.ac.ebi.nugo.common.Tab2MageConstants; 52 53 54 /** 55 The tab2mage export validator 56 @author Dominic Oyeniran 57 @email oyeniran@ebi.ac.uk/doyeniran@gmail.com 58 @version 1.0 60 59 */ 61 62 60 public class Tab2MageValidator 63 61 { 64 62 // logger 63 private static Logger log = Logger.getLogger(Tab2MageValidator.class); 64 65 // counts the number of feature extraction protocol used in the experiment 66 private static int feProtocolCount=0; 67 68 // counts the number of scanning protocols used in the experiment 65 69 private static int scanningProtocolCount=0; 66 private static int extractionProtocolCount=0; 70 71 // counts the number of hybridization protocol used in the experiment 67 72 private static int hybridizationProtocolCount=0; 73 74 // counts the number of labelling protocol used in the experiment 68 75 private static int labelingProtocolCount=0; 76 77 // counts the number of extraction protocol used in the experiment 69 78 private static int extractProtocolCount=0; 79 80 // counts the number of extraction protocol used in the experiment 70 81 private static int samplingProtocolCount=0; 71 private static Set<String> newParameterHybSectionHeader= new LinkedHashSet<String>(); 72 private static Set<String> bioMatXteristicsHeader= new LinkedHashSet<String>(); 82 83 private Set<String> parameterHeaders= new LinkedHashSet<String>(); 84 85 private Set<String> bioMaterialXteristicsHeaders= new LinkedHashSet<String>(); 86 87 private static Set<String> factorValuesHybSectionHeader= new LinkedHashSet<String>(); 88 89 private static Set<String> protocolHybSectionHeader= new LinkedHashSet<String>(); 90 91 /* channel number to indicate platforms 92 1-- affymetrix 93 2-- agilent. genepix etc 94 3-- ...... 95 */ 96 private int channelNumber = 0; 97 // the experiment 73 98 private Experiment experiment; 74 99 75 /** 76 creates a new Tab2Mage Validator 77 * @param experiment 78 */ 79 public Tab2MageValidator(Experiment experiment) 100 private SessionControl sc; 101 102 private Response response; 103 104 /** 105 creates a new Tab2Mage Validator 106 @param experiment 107 @param sc 108 @param response 109 */ 110 public Tab2MageValidator(Experiment experiment, SessionControl sc, Response response) 80 111 { 81 112 this.experiment=experiment; 82 getResourceCounter(experiment,experiment.getDbControl()); 83 } 84 85 /** 86 Set all resource counters used within an experiment 87 @param experiment, the experiment 88 @param dc, the database control object 89 */ 113 this.sc = sc; 114 this.response= response; 115 countProtocols(); 116 createHeaders(); 117 } 118 119 /** 120 counts all protocols used in the experiment and initialise protocol variables 121 */ 122 @SuppressWarnings("unchecked") 123 private void countProtocols() 124 { 125 DbControl dc =null; 126 try 127 { 128 dc = sc.newDbControl(); 129 ItemResultList<RawBioAssay> rbas= experiment.getRawBioAssays().list(dc); 130 for (RawBioAssay rba : rbas) 131 { 132 if (rba.getProtocol()!=null) 133 feProtocolCount++ ; 134 135 if (rba.getScan().getProtocol()!=null) 136 scanningProtocolCount++; 137 138 if (rba.getScan().getHybridization().getProtocol()!=null) 139 hybridizationProtocolCount++; 140 141 ItemResultList<LabeledExtract>labeledExtracts = (ItemResultList<LabeledExtract>) 142 rba.getScan().getHybridization().getCreationEvent().getSources().list(dc); 143 if (channelNumber==0) 144 setChannelNumber(labeledExtracts.size()); 145 for (LabeledExtract labeledExtract :labeledExtracts) 146 { 147 if (labeledExtract.getProtocol()!=null) 148 labelingProtocolCount++; 149 150 //Extract extract = labeledExtract.getExtract(); // RefExtract 151 Extract extract = ExportHelper.getExtract(labeledExtract, dc); 152 if (extract.getProtocol()!=null) 153 extractProtocolCount++; 154 155 //sample 156 Sample sample = ExportHelper.getSample(extract, dc); 157 if (sample.getProtocol()!=null) 158 samplingProtocolCount++; 159 160 } 161 } 162 } 163 catch(Throwable tr) 164 { 165 log.error("the protocol count was not successful", tr); 166 response.setError("the protocol counting was not successful", Arrays.asList(tr)); 167 dc.close(); 168 } 169 finally 170 { 171 if (dc!=null) 172 dc.close(); 173 } 174 } 175 176 /** 177 create both the parameter [AT] header and BioMaterialCharactertistic[AT] headers found in the whole experiment 178 */ 90 179 @SuppressWarnings({"deprecation","unchecked"}) 91 private static void getResourceCounter(Experiment experiment,DbControl dc) 92 { 93 ItemResultList<RawBioAssay> rbas= experiment.getRawBioAssays().list(dc); 94 for (RawBioAssay rba : rbas) 95 { 96 if (rba.getProtocol()!=null) 97 { 98 extractionProtocolCount++ ; 99 getParameterSectionHeader(rba, dc ); 100 } 101 if (rba.getScan().getProtocol()!=null) 102 { 103 scanningProtocolCount++; 104 getParameterSectionHeader(rba.getScan(), dc ); 105 } 106 if (rba.getScan().getHybridization().getProtocol()!=null) 107 { 108 hybridizationProtocolCount++; 109 getParameterSectionHeader(rba.getScan().getHybridization(), dc ); 110 } 111 ItemResultList<LabeledExtract>labeledExtracts = (ItemResultList<LabeledExtract>) 112 rba.getScan().getHybridization().getCreationEvent().getSources().list(dc); 113 for (LabeledExtract labeledExtract :labeledExtracts) 114 { 115 if (labeledExtract.getProtocol()!=null) 116 { 117 labelingProtocolCount++; 118 getParameterSectionHeader(labeledExtract, dc ); 119 } 120 if (labeledExtract.getExtract().getProtocol()!=null) 121 { 122 extractProtocolCount++; 123 getParameterSectionHeader(labeledExtract.getExtract(), dc ); 124 } 125 if (labeledExtract.getExtract().getSample().getProtocol()!=null) 126 { 127 samplingProtocolCount++; 128 getParameterSectionHeader(labeledExtract.getExtract().getSample(), dc ); 129 } 130 if (labeledExtract.getExtract().getSample().getBioSource()!=null) 131 setAllBioMatXteristicsHeader(labeledExtract.getExtract().getSample().getBioSource(),dc); 132 } 133 } 134 } 135 /** 136 Gets the used annotation types (parameters) for an annotatable item 180 private void createHeaders() 181 { 182 DbControl dc =null; 183 try 184 { 185 dc = sc.newDbControl(); 186 ItemResultList<RawBioAssay> rbas= experiment.getRawBioAssays().list(dc); 187 for (RawBioAssay rba : rbas) 188 { 189 if (rba.getProtocol()!=null) 190 { 191 createParameterSectionHeaders(rba, dc ); 192 createProtocolHybSectionHeader(Tab2MageValidator.getFeProtocolCount(),Tab2MageConstants.protocol_featureextraction.getName()); 193 } 194 if (rba.getScan().getProtocol()!=null) 195 { 196 createParameterSectionHeaders(rba.getScan(), dc ); 197 createProtocolHybSectionHeader(Tab2MageValidator.getScanningProtocolCount(), Tab2MageConstants.protocol_scanning.getName()); 198 } 199 if (rba.getScan().getHybridization().getProtocol()!=null) 200 { 201 createParameterSectionHeaders(rba.getScan().getHybridization(), dc ); 202 createProtocolHybSectionHeader(Tab2MageValidator.getHybridizationProtocolCount(), Tab2MageConstants.protocol_hyb.getName()); 203 } 204 ItemResultList<LabeledExtract>labeledExtracts = (ItemResultList<LabeledExtract>) 205 rba.getScan().getHybridization().getCreationEvent().getSources().list(dc); 206 for (LabeledExtract labeledExtract :labeledExtracts) 207 { 208 if (labeledExtract.getProtocol()!=null) 209 { 210 createParameterSectionHeaders(labeledExtract, dc ); 211 createProtocolHybSectionHeader(Tab2MageValidator.getLabelingProtocolCount(), Tab2MageConstants.protocol_labeling.getName()); 212 } 213 //Extract extract= labeledExtract.getExtract(); 214 Extract extract = ExportHelper.getExtract(labeledExtract, dc); 215 if (extract.getProtocol()!=null) 216 { 217 createParameterSectionHeaders(labeledExtract.getExtract(), dc ); 218 createProtocolHybSectionHeader(Tab2MageValidator.getExtractProtocolCount(), Tab2MageConstants.protocol_extraction.getName()); 219 } 220 Sample sample = ExportHelper.getSample(extract, dc); 221 if (sample.getProtocol()!=null) 222 { 223 createParameterSectionHeaders(sample, dc ); 224 createProtocolHybSectionHeader(Tab2MageValidator.getSamplingProtocolCount(), Tab2MageConstants.protocol_treatment.getName()); 225 } 226 BioSource bioSource= ExportHelper.getBioSource(sample, dc); 227 if (bioSource!=null) 228 createBioMatXteristicsSectionHeader(bioSource,dc); 229 } 230 } 231 } 232 catch(Throwable tr) 233 { 234 log.error("cannot create / set parameters headers and biomaterials headers", tr ); 235 response.setError("cannot create / set parameters headers and biomaterials headers", Arrays.asList(tr)); 236 dc.close(); 237 } 238 finally 239 { 240 if (dc!=null) 241 dc.close(); 242 } 243 244 } 245 /** 246 Gets the used annotation types (parameters) for an annotatable item and add it to a set of PARAMETER[AT] headers 137 247 @param annotatable, an item that implements annotatable 138 248 @param dc, the database control object 139 249 */ 140 250 141 private static void getParameterSectionHeader(Annotatable anotatable, DbControl dc )251 private void createParameterSectionHeaders(Annotatable anotatable, DbControl dc ) 142 252 { 143 253 ItemResultList<Annotation> annotations = anotatable.getAnnotationSet().getAnnotations().list(dc); … … 145 255 { 146 256 if (anotatable.getProtocol().isParameter(annotation.getAnnotationType()) && !annotation.getAnnotationType().isRemoved()) 147 newParameterHybSectionHeader.add(annotation.getAnnotationType().getName()); 148 } 149 //Tab2MageHelper.displayParameterHeader(newParameterHybSectionHeader); 257 parameterHeaders.add(annotation.getAnnotationType().getName()); 258 } 150 259 } 151 260 … … 156 265 */ 157 266 158 private static void setAllBioMatXteristicsHeader(Annotatable anotatable, DbControl dc) 159 { 160 List<Annotation> annotations = anotatable.getAnnotationSet().getAnnotations().list(dc); 267 private void createBioMatXteristicsSectionHeader(Annotatable anotatable, DbControl dc) 268 { 269 270 List<Annotation> annotations = anotatable.getAnnotationSet().getAnnotations().list(dc); 161 271 for (Annotation annotation: annotations) 162 272 { 163 AnnotationType at=annotation.getAnnotationType(); 164 if(!at.isRemoved()) 165 bioMatXteristicsHeader.add(at.getName()); 166 } 167 } 168 169 public static Set<String> getBioMatXteristicsHeader() 170 { 171 return bioMatXteristicsHeader; 172 } 173 174 public static int getExtractionProtocolCount() 175 { 176 return extractionProtocolCount; 177 } 178 273 if (annotation.getValues()!=null && !annotation.getValues().isEmpty()) 274 { 275 AnnotationType at=annotation.getAnnotationType(); 276 if(!at.isRemoved()) 277 { 278 bioMaterialXteristicsHeaders.add(at.getName()); 279 //("bio header added is :"+ at.getName()); 280 } 281 } 282 } 283 284 } 285 /** 286 create a list of the protocol headers for the hyridization section of tab2mage file. 287 duplicates are eliminated with the use of linked hash set. 288 @param count, the number of each protocol used across the raw bio assay. 289 @param header, the header for each protocol used across the raw bio assay 290 */ 291 private static void createProtocolHybSectionHeader(int count, String header) 292 { 293 if (count>0) 294 { 295 protocolHybSectionHeader.add(header); 296 } 297 } 298 299 /** 300 initialises the maps required to manage tab2mage data 301 @param map, the map to be intitialised 302 @param isForParameter, TRUE if map is for parameters and FALSE otherwise 303 */ 304 305 public ConcurrentHashMap<String,String> initialiseMaps(ConcurrentHashMap<String,String> map, boolean isForParameter) 306 { 307 308 if (map.isEmpty()) 309 { 310 if (isForParameter) // get the parameter[AT] headers and put in a ConcurrentHashMap 311 { 312 for (String param: parameterHeaders) 313 { 314 if (param!=null) map.put(param, ""); 315 } 316 } 317 else if (!isForParameter) // get all biomaterial xteristics [AT] headers and put in a ConcurrentHashMap 318 { 319 for (String bioXterParam: bioMaterialXteristicsHeaders) 320 { 321 if (bioXterParam!=null) map.put(bioXterParam, ""); 322 } 323 } 324 } 325 return map; 326 } 327 328 /** 329 get all the experimental factors for an experiments 330 @param DcControl dc, the database control 331 @param Experiment experiment, the experiment 332 @param RawBioassay, the rawbioassay that the experimental factors are obtained from 333 @return List, list of annotations 334 */ 335 public static List<Annotation> getExperimentalFactorValues(DbControl dc, Experiment experiment, RawBioAssay rba) 336 { 337 List<Annotation> values= new LinkedList<Annotation>(); 338 AnnotationSet annotationSet = rba.isAnnotated() ? rba.getAnnotationSet() : null; 339 ItemQuery<AnnotationType> experimentalFactorsQuery= experiment.getExperimentalFactors(); 340 experimentalFactorsQuery.include(Include.MINE, Include.SHARED, Include.OTHERS, Include.IN_PROJECT); 341 ItemResultList<AnnotationType> experimentalFactors = experimentalFactorsQuery.list(dc); 342 if (annotationSet!=null) 343 { 344 for (AnnotationType exprFactor :experimentalFactors) 345 { 346 if (!exprFactor.isRemoved()) 347 { 348 values.add(annotationSet.findAnnotation(exprFactor)); 349 if (annotationSet.findAnnotation(exprFactor)!=null)factorValuesHybSectionHeader.add("FactorValue["+exprFactor.getName()+"]"); 350 } 351 } 352 } 353 return values; 354 } 355 356 /** 357 get all the experimental factors headers for an experiments 358 @param DcControl dc, the database control 359 @param Experiment experiment, the experiment 360 @param RawBioassay, the rawbioassay that the experimental factors are obtained from 361 @return List, list of annotations 362 */ 363 public static Set<String> getExperimentalFactorHeader(DbControl dc, Experiment experiment, RawBioAssay rba) 364 { 365 Set<String> headers= new LinkedHashSet<String>(); 366 AnnotationSet annotationSet = rba.isAnnotated() ? rba.getAnnotationSet() : null; 367 ItemQuery<AnnotationType> experimentalFactorsQuery= experiment.getExperimentalFactors(); 368 experimentalFactorsQuery.include(Include.MINE, Include.SHARED, Include.OTHERS, Include.IN_PROJECT); 369 ItemResultList<AnnotationType> experimentalFactors = experimentalFactorsQuery.list(dc); 370 if (annotationSet!=null) 371 { 372 for (AnnotationType exprFactor :experimentalFactors) 373 { 374 if (!exprFactor.isRemoved()) 375 { 376 377 if (annotationSet.findAnnotation(exprFactor)!=null)headers.add("FactorValue["+exprFactor.getName()+"]"); 378 } 379 } 380 } 381 return headers; 382 } 383 384 385 // get the extraction protocol count 179 386 public static int getExtractProtocolCount() 180 387 { 181 388 return extractProtocolCount; 182 389 } 183 390 // get the hybidization protocol count 184 391 public static int getHybridizationProtocolCount() 185 392 { 186 393 return hybridizationProtocolCount; 187 394 } 188 395 // get the labelling protocol count 189 396 public static int getLabelingProtocolCount() 190 397 { 191 398 return labelingProtocolCount; 192 399 } 193 194 public static Set<String> getNewParameterHybSectionHeader() 195 { 196 return newParameterHybSectionHeader; 197 } 198 400 // get the sampling protocol count 199 401 public static int getSamplingProtocolCount() 200 402 { 201 403 return samplingProtocolCount; 202 404 } 203 405 // get the scanning protocol count 204 406 public static int getScanningProtocolCount() 205 407 { 206 408 return scanningProtocolCount; 207 409 } 208 209 private static void validateUsers() // 210 { 211 212 213 } 214 410 411 // get the feature extraction protocol count 412 public static int getFeProtocolCount() 413 { 414 return feProtocolCount; 415 } 416 417 // get the parameter headers 418 public Set<String> getParameterHeaders() 419 { 420 return parameterHeaders; 421 } 422 // get the bio material characteristics headers 423 public Set<String> getBioMaterialXteristicsHeaders() 424 { 425 return bioMaterialXteristicsHeaders; 426 } 427 428 // get the factor values header used in the experiment 429 public static Set<String> getFactorValuesHybSectionHeader() 430 { 431 return factorValuesHybSectionHeader; 432 } 433 434 // get the protocol Hyb section header 435 public static Set<String> getProtocolHybSectionHeader() 436 { 437 return protocolHybSectionHeader; 438 } 439 440 441 public int getChannelNumber() 442 { 443 return channelNumber; 444 } 445 446 void setChannelNumber(int channelNumber) 447 { 448 this.channelNumber = channelNumber; 449 } 215 450 }
Note: See TracChangeset
for help on using the changeset viewer.