Ignore:
Timestamp:
Feb 7, 2011, 4:07:54 PM (10 years ago)
Author:
robert@…
Message:
  • Number of seconds for the rest controller to keep data in cache is now a configuration option
  • After searching, it is possible to choose which action to perform on the search results.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/groovy/dbnp/query/SampleSearch.groovy

    r1482 r1501  
    6262         */
    6363        @Override
    64         void execute() {
    65                 super.execute();
    66 
     64        void executeAnd() {
    6765                // If no criteria are found, return all samples
    6866                if( !criteria || criteria.size() == 0 ) {
     
    8078                        def studies = Study.findAll().findAll { it.canRead( this.user ) };
    8179
    82                         studies = filterOnStudyCriteria( studies );
     80                        studies = filterStudiesOnStudyCriteria( studies );
    8381
    8482                        if( studies.size() == 0 ) {
     
    116114
    117115        /**
    118          * Filters the given list of samples on the sample criteria
    119          * @param samples       Original list of samples
    120          * @return                      List with all samples that match the Sample-criteria
    121          */
    122         protected List filterOnStudyCriteria( List studies ) {
     116        * Searches for samples based on the given criteria. Only one of the criteria have to be satisfied and
     117        * criteria for the different entities are satisfied as follows:
     118        *
     119        *               Sample.title = 'abc'
     120        *                               Samples are returned from studies with title 'abc'
     121        *
     122        *               Subject.species = 'human'
     123        *                               Samples are returned from subjects with species = 'human'
     124        *
     125        *               Sample.name = 'sample 1'
     126        *                               Samples are returned with name = 'sample 1'
     127        *
     128        *               Event.startTime = '0s'
     129        *                               Samples are returned from subjects that have had an event with start time = '0s'
     130        *
     131        *               SamplingEvent.startTime = '0s'
     132        *                               Samples are returned that have originated from a sampling event with start time = '0s'
     133        *
     134        *               Assay.module = 'metagenomics'
     135        *                               Samples are returned that have been processed in an assay with module = metagenomics
     136        *
     137        * When searching for more than one criterion per entity, these are taken separately. Searching for
     138        *
     139        *               Subject.species = 'human'
     140        *               Subject.name = 'Jan'
     141        *
     142        *  will result in all samples from a human subject or a subject named 'Jan'. Samples from a mouse subject
     143        *  named 'Jan' or a human subject named 'Kees' will also satisfy the criteria.
     144        *
     145        */
     146   @Override
     147   void executeOr() {
     148           // We expect the sample criteria to be the most discriminative, and discard
     149           // the most samples. (e.g. by searching on sample title of sample type). For
     150           // that reason we first look through the list of studies. However, when the
     151           // user didn't enter any sample criteria, this will be an extra step, but doesn't
     152           // cost much time to process.
     153           def samples = []
     154           def allSamples = Sample.list().findAll { it.parent?.canRead( this.user ) }.toList();
     155
     156           // If no criteria are found, return all samples
     157           if( !criteria || criteria.size() == 0 ) {
     158                   results = allSamples
     159                   return;
     160           }
     161           
     162           samples = ( samples + filterSamplesOnStudyCriteria( allSamples - samples ) ).unique();
     163           samples = ( samples + filterOnSubjectCriteria( allSamples - samples ) ).unique();
     164           samples = ( samples + filterOnSampleCriteria( allSamples - samples ) ).unique();
     165           samples = ( samples + filterOnEventCriteria( allSamples - samples ) ).unique();
     166           samples = ( samples + filterOnSamplingEventCriteria( allSamples - samples ) ).unique();
     167           samples = ( samples + filterOnAssayCriteria( allSamples - samples ) ).unique();
     168           
     169           samples = ( samples + filterOnModuleCriteria( allSamples - samples ) ).unique();
     170           
     171           // Save matches
     172           results = samples;
     173   }
     174       
     175        /**
     176         * Filters the given list of studies on the study criteria
     177         * @param studies       Original list of studies
     178         * @return                      List with all samples that match the Study-criteria
     179         */
     180        protected List filterStudiesOnStudyCriteria( List studies ) {
    123181                return filterOnTemplateEntityCriteria(studies, "Study", { study, criterion -> return criterion.getFieldValue( study ) })
    124182        }
     183       
     184        /**
     185        * Filters the given list of samples on the sample criteria
     186        * @param samples        Original list of samples
     187        * @return                       List with all samples that match the Study-criteria
     188        */
     189   protected List filterSamplesOnStudyCriteria( List samples ) {
     190           return filterOnTemplateEntityCriteria(samples, "Study", { study, criterion ->
     191                   return criterion.getFieldValue( study.parent )
     192           })
     193   }
     194
    125195
    126196        /**
     
    180250                        return [];
    181251
    182                 if( getEntityCriteria( 'Assay' ).size() == 0 )
    183                         return samples
    184 
    185252                // There is no sample.assays property, so we have to look for assays another way: just find
    186253                // all assays that match the criteria
    187254                def criteria = getEntityCriteria( 'Assay' );
     255               
     256                if( getEntityCriteria( 'Assay' ).size() == 0 ) {
     257                        if( searchMode == SearchMode.and )
     258                                return samples
     259                        else if( searchMode == SearchMode.or )
     260                                return [];
     261                }
     262
    188263                def assays = filterEntityList( Assay.list(), criteria, { assay, criterion ->
    189264                        if( !assay )
    190265                                return false
    191266
    192                         return criterion.matchOne( assay );
     267                        return criterion.matchEntity( assay );
    193268                });
    194269
     
    197272                        return [];
    198273
    199                 // Save sample data for later use
    200                 saveResultFields( samples, criteria, { sample, criterion ->
    201                         def sampleAssays = Assay.findByStudy( sample.parent ).findAll { it.samples?.contains( sample ) };
    202                         if( sampleAssays && sampleAssays.size() > 0 )
    203                                 return sampleAssays.collect( criterion.getFieldValue( it ) )
    204                         else
    205                                 return null
    206                 });
    207 
    208274                // Now filter the samples on whether they are attached to the filtered assays
    209                 return samples.findAll { sample ->
     275                def matchingSamples = samples.findAll { sample ->
    210276                        if( !sample.parent )
    211277                                return false;
     
    222288                        return false;
    223289                }
     290               
     291                // Save sample data for later use
     292                println samples
     293                println "Find values for " + matchingSamples + " and " + criteria
     294                saveResultFields( matchingSamples, criteria, { sample, criterion ->
     295                        println "Find value for " + sample + " and " + criterion
     296                        def sampleAssays = Assay.findByParent( sample.parent ).findAll { it.samples?.contains( sample ) };
     297                        if( sampleAssays && sampleAssays.size() > 0 )
     298                                return sampleAssays.collect { criterion.getFieldValue( it ) }
     299                        else
     300                                return null
     301                });
     302       
     303                return matchingSamples;
    224304        }
    225305
Note: See TracChangeset for help on using the changeset viewer.