Changeset 20
- Timestamp:
- Mar 22, 2011, 1:52:56 PM (11 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/conf/BaseFilters.groovy
r18 r20 186 186 } catch( Exception e ) { 187 187 // Synchronization fails. Log error and continue; don't bother the user with it 188 e.printStackTrace() 188 189 log.error e.getMessage() 189 190 } -
trunk/grails-app/domain/nl/tno/metagenomics/AssaySample.groovy
r12 r20 216 216 otherAssaySample.oligoNumber = oligoNumber; 217 217 otherAssaySample.tagName = tagName; 218 otherAssaySample.run = run;219 218 220 219 // Move attached data 221 def dataList = sequenceData?.toList()220 def dataList = [] + sequenceData?.toList() 222 221 def otherAssay = otherAssaySample.assay; 223 222 224 223 if( dataList && dataList.size() > 0 ) { 225 224 for( def j = dataList.size() - 1; j >= 0; j-- ) { 226 // Copy data 227 dataList[j].sample = otherAssaySample; 228 this.removeFromSequenceData( dataList[j] ); 229 otherAssaySample.addToSequenceData( dataList[j] ); 230 dataList[j].save(); 225 // Copy data to a new sequencedata object. 226 // Just moving the sequencedata object to the other assay sample resulted 227 // in a 'deleted object would be re-saved by cascade' exception 228 229 // Clone the sequencedata object 230 def sd = dataList[ j ]?.clone(); 231 232 if( sd ) 233 otherAssaySample.addToSequenceData( sd ); 234 235 // Remove the old sequencedata object 236 this.removeFromSequenceData( dataList[ j ] ); 231 237 } 232 238 } 239 240 // Copy run properties 241 if( otherAssaySample.run ) { 242 otherAssaySample.run.removeFromAssaySamples( otherAssaySample ); 243 } 244 245 // Remove this sample from the run. 246 if( run ) { 247 def copyRun = run; 248 copyRun.removeFromAssaySamples( this ); 249 copyRun.addToAssaySamples( otherAssaySample ); 250 } else { 251 otherAssaySample.run = null; 252 } 233 253 } 234 254 } -
trunk/grails-app/domain/nl/tno/metagenomics/SequenceData.groovy
r12 r20 57 57 58 58 // Reset statistics of the assay sample, to ensure the deleted files are removed from statistics 59 sample.resetStats(); 59 sample?.resetStats(); 60 } 61 62 public SequenceData clone() { 63 // Copy the files to a new name 64 def permanentDir = fileService.absolutePath( ConfigurationHolder.config.metagenomics.fileDir.toString() ) 65 66 def newSequenceFileName = sequenceFile; 67 if( this.sequenceFile ) { 68 newSequenceFileName = fileService.getUniqueFilename( this.sequenceFile, permanentDir ); 69 fileService.copy( sequenceFile, newSequenceFileName, permanentDir ); 70 } 71 72 def newQualityFileName = qualityFile; 73 if( this.qualityFile ) { 74 newQualityFileName = fileService.getUniqueFilename( this.qualityFile, permanentDir ); 75 fileService.copy( qualityFile, newQualityFileName, permanentDir ); 76 } 77 78 def sd = new SequenceData( 79 sequenceFile: newSequenceFileName, 80 qualityFile: newQualityFileName, 81 numSequences: this.numSequences, 82 averageQuality: this.averageQuality 83 ); 84 85 if( this.sample ) 86 this.sample.addToSequenceData( sd ); 87 88 return sd; 60 89 } 61 90 } -
trunk/grails-app/services/nl/tno/metagenomics/files/ExcelService.groovy
r7 r20 79 79 80 80 for( def rowNum = startRow; rowNum <= endRow; rowNum++ ) { 81 ArrayList row = []82 81 Row excelRow = sheet.getRow( rowNum ); 83 82 84 for( def colNum = 0; colNum < excelRow.getLastCellNum(); colNum++ ) { 85 Cell c = excelRow.getCell( colNum ); 86 if( c ) { 87 if( c.getCellType() == Cell.CELL_TYPE_NUMERIC ) { 88 row << numberformat.format( c.getNumericCellValue() ); 83 if( !rowIsEmpty( excelRow ) ) { 84 ArrayList row = [] 85 86 for( def colNum = 0; colNum < excelRow.getLastCellNum(); colNum++ ) { 87 Cell c = excelRow.getCell( colNum ); 88 if( c ) { 89 if( c.getCellType() == Cell.CELL_TYPE_NUMERIC ) { 90 row << numberformat.format( c.getNumericCellValue() ); 91 } else { 92 row << df.formatCellValue( c ); 93 } 89 94 } else { 90 row << df.formatCellValue( c );95 row << "" 91 96 } 92 } else { 93 row << "" 97 94 98 } 95 99 100 data << row; 96 101 } 97 98 data << row;99 102 } 100 103 … … 200 203 } 201 204 205 206 /** 207 * Checks whether an excel row is empty 208 * @param row Row from the excel sheet 209 * @return True if all cells in this row are empty or the given row is null. False otherwise 210 */ 211 def rowIsEmpty( Row excelRow ) { 212 if( !excelRow ) 213 return true; 214 215 def df = new DataFormatter(); 216 for( int i = excelRow.getFirstCellNum(); i < excelRow.getLastCellNum(); i++ ) { 217 Cell cell = excelRow.getCell( i ); 218 219 try { 220 def value = df.formatCellValue(cell) 221 if( value ) 222 return false 223 } catch (NumberFormatException nfe) { 224 // If the number can't be formatted, the row isn't empty 225 return false; 226 } 227 } 228 229 return true; 230 } 231 232 202 233 /** 203 234 * Return the given workbook for download -
trunk/grails-app/services/nl/tno/metagenomics/files/FileService.groovy
r13 r20 110 110 def File get( String filename, File directory = null ) { 111 111 if( directory == null ) 112 directory = getUploadDir()112 directory = getUploadDir() 113 113 114 114 return new File( directory, filename ); … … 120 120 def boolean fileExists( String filename, File directory = null ) { 121 121 if( directory == null ) 122 directory = getUploadDir()122 directory = getUploadDir() 123 123 124 124 return new File( directory, filename ).exists(); … … 130 130 def boolean delete( String filename, File directory = null ) { 131 131 if( directory == null ) 132 directory = getUploadDir()132 directory = getUploadDir() 133 133 134 134 def f = new File( directory, filename ); … … 136 136 f.delete(); 137 137 } 138 139 return true; 140 } 141 142 def boolean copy( String filename, String newfilename, File directory = null ) { 143 if( directory == null ) 144 directory = getUploadDir() 145 146 def f = new File( directory, filename ); 147 def destination = new File( directory, newfilename ); 148 149 if( f.exists() && !destination.exists() ) { 150 def reader = f.newReader(); 151 destination.withWriter { writer -> 152 writer << reader 153 } 154 reader.close(); 155 } 156 157 return true; 138 158 } 139 159 -
trunk/grails-app/services/nl/tno/metagenomics/integration/TrashService.groovy
r9 r20 27 27 } 28 28 } 29 29 30 30 study.delete(flush:true); 31 31 } … … 185 185 // Move data from this assay sample to the trash version of it 186 186 assaySample.moveValuableDataTo( dummyAssaySample ); 187 188 // Remove the assaySample from its run, since otherwise the statistics of the run (#sequences for example) 189 // are not correct anymore and the assaySample will be resaved after delete 190 dummyAssaySample.run?.removeFromAssaySamples( dummyAssaySample ); 191 187 192 dummyAssaySample.save(); 193 } 194 } 195 196 // Remove all assaysamples from this assay from their run 197 assay.assaySamples?.each { assaySample -> 198 assaySample.run?.removeFromAssaySamples( assaySample ); 199 } 200 201 // Remove this assay from the runs, since otherwise the samples will be resaved upon delete 202 if( assay.runs ) { 203 def l = [] + assay.runs 204 l.each { 205 it.removeFromAssays( assay ); 188 206 } 189 207 } … … 232 250 // Move data from this assay sample to the trash version of it 233 251 assaySample.moveValuableDataTo( dummyAssaySample ); 252 253 // Remove the assaySample from its run, since otherwise the statistics of the run (#sequences for example) 254 // are not correct anymore 255 dummyAssaySample.run?.removeFromAssaySamples( dummyAssaySample ); 256 234 257 dummyAssaySample.save(); 235 258 } 259 } 260 261 // Remove all assaysamples from this assay from their run 262 sample.assaySamples?.each { assaySample -> 263 assaySample.run?.removeFromAssaySamples( assaySample ); 236 264 } 237 265 }
Note: See TracChangeset
for help on using the changeset viewer.