Changeset 75 for trunk/grails-app/domain
- Timestamp:
- Nov 28, 2011, 9:18:01 AM (12 years ago)
- Location:
- trunk/grails-app/domain/nl/tno/massSequencing
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/domain/nl/tno/massSequencing/AssaySample.groovy
r64 r75 1 1 package nl.tno.massSequencing 2 import nl.tno.massSequencing.classification.* 2 3 3 4 import org.codehaus.groovy.grails.commons.ApplicationHolder as AH … … 12 13 // Grails datasource is used for executing custom SQL statement 13 14 def dataSource 15 def sessionFactory 14 16 15 17 // To be computed at run time (and saved in cache) … … 76 78 */ 77 79 public int numClassifiedSequences() { 78 return Sequence.countByAssaySample( this ); 80 int numSeqs = 0; 81 if( this.sequenceData ) { 82 sequenceData.each { 83 def sequenceDataNum = Sequence.countBySequenceData( it ); 84 numSeqs += sequenceDataNum ?: 0; 85 } 86 } 87 88 return numSeqs 79 89 } 80 90 … … 280 290 otherAssaySample.numSequences = numSequences; 281 291 292 otherAssaySample.save( flush: true ); 293 282 294 // Move attached data 283 295 def dataList = [] + sequenceData?.toList() … … 293 305 // Clone the sequencedata object 294 306 def sd = dataList[ j ]?.clone(); 295 307 296 308 if( sd ) 297 309 otherAssaySample.addToSequenceData( sd ); 298 310 299 311 // Copy all sequence classifications to the new sequenceData 300 Sequence.executeUpdate( "UPDATE Sequence s SET s.sequenceData = :new WHERE s.sequenceData = :old ", [ 'old': dataList[ j ], 'new': sd ] ) 312 //log.debug "Removing sequences from sequencedata " + dataList[ j ]?.id + " to " + sd?.id 313 //Sequence.executeUpdate( "UPDATE Sequence s SET s.sequenceData = :new WHERE s.sequenceData = :old ", [ 'old': dataList[ j ], 'new': sd ] ) 314 //Sequence.executeUpdate( "DELETE FROM Sequence s WHERE s.sequenceData = :old ", [ 'old': dataList[ j ] ] ) 301 315 302 316 // Remove the old sequencedata object … … 310 324 otherAssaySample.run.removeFromAssaySamples( otherAssaySample ); 311 325 } 312 326 313 327 // Remove this sample from the run. 314 328 if( run ) { … … 319 333 otherAssaySample.run = null; 320 334 } 335 321 336 } 322 337 -
trunk/grails-app/domain/nl/tno/massSequencing/Sequence.groovy
r59 r75 3 3 import nl.tno.massSequencing.classification.Taxon 4 4 5 class Sequence {5 class Sequence implements Serializable { 6 6 // Unique name of this sequence 7 7 String name … … 22 22 23 23 static mapping = { 24 id composite: ['name'] 24 25 name index: 'name_idx' 25 26 classification index: 'taxon_idx' 26 sequenceData index: 'sequenceData_idx' 27 sequenceData index: 'sequenceData_idx', cascade: "all-delete-orphan" 28 27 29 } 28 30 } -
trunk/grails-app/domain/nl/tno/massSequencing/classification/Taxon.groovy
r70 r75 169 169 * @return First taxon that is found and matches the criteria or null if nothing is found 170 170 */ 171 public static Taxon findTaxonByPath( def path, int startLevel = 0 ) {171 public static Taxon findTaxonByPath( def path, int startLevel = 0, taxonCache ) { 172 172 if( path.size() == 0 ) 173 173 return null; 174 175 // Check taxon cache 176 def cacheTaxon = findTaxonInCache( taxonCache, path ); 177 if( cacheTaxon ) 178 return cacheTaxon; 174 179 175 180 def leafLevel = path.size() - 1 + startLevel; … … 203 208 } 204 209 210 storeTaxonInCache( taxonCache, path, leaf ); 211 205 212 return leaf; 206 213 } 207 214 208 215 return null; 216 } 217 218 public static emptyTaxonCache() { 219 return [ "top": [:], "sub": [:] ]; 220 } 221 222 protected static Taxon findTaxonInCache( cache, path ) { 223 if( path.size() <= 3 ) { 224 return cache[ "top" ][ cacheKey( path ) ]; 225 } else { 226 def topCacheKey = cacheKey( path[0..2] ); 227 228 if( !cache[ "sub" ][ topCacheKey ] ) 229 return null; 230 231 return findTaxonInCache( cache[ "sub" ][ topCacheKey ], path[ 3..-1] ); 232 } 233 } 234 235 protected static void storeTaxonInCache( cache, path, taxon ) { 236 // Keep a 'layered' cache: the first three levels are kept in this cache. The 237 // next levels are kept in a separate cache, one map for each subtree, so 238 // each map will have a size that we can still deal with 239 // [ 240 // "top": [ "bacteria": x, "bacteria;firmicutes": y ], 241 // "sub": [ "bacteria;firmicutes;abc": 242 // [ "def;ghi" : z, "def;gkl": m ] 243 // ] 244 if( path.size() <= 3 ) { 245 cache[ "top" ][ cacheKey( path ) ] = taxon; 246 } else { 247 def topCacheKey = cacheKey( path[0..2] ); 248 def restPath = path[3..-1] 249 250 if( cache[ "sub" ][ topCacheKey ] == null ) { 251 cache[ "sub" ][ topCacheKey ] = emptyTaxonCache(); 252 } 253 254 storeTaxonInCache( cache[ "sub" ][ topCacheKey ], restPath, taxon ) 255 } 256 257 } 258 259 protected static cacheKey( path ) { 260 return path.join( ";" ); 209 261 } 210 262 … … 215 267 * @param path An array or list with the names of the taxa in the path, ordered by level 216 268 * @param startLevel Which level is the first entry in the list. Defaults to zero. Can be used in order to find taxa 217 * without the whole tree being specified (e.g. without the root element) 269 * without the whole tree being specified (e.g. without the root element) 270 * @param taxonCache Hashmap with cached data about taxa found 218 271 * @return First taxon that is found and matches the criteria or a new taxon if it didn't exist 219 272 */ 220 static Taxon findOrCreateTaxonByPath( def path, int startLevel = 0 ) {221 def taxon = findTaxonByPath( path, startLevel );273 static Taxon findOrCreateTaxonByPath( def path, int startLevel = 0, def taxonCache = null ) { 274 def taxon = findTaxonByPath( path, startLevel, taxonCache ); 222 275 223 276 if( taxon ) … … 233 286 // However, we don't have to check the highest level, so we start at depth - 2 234 287 for( def level = depth - 2; level >= 0 && !found ; level-- ) { 235 parentNode = findTaxonByPath( path[ 0 .. level ], startLevel );288 parentNode = findTaxonByPath( path[ 0 .. level ], startLevel, taxonCache ); 236 289 237 290 // If this taxon is found, it is the highest level
Note: See TracChangeset
for help on using the changeset viewer.