Changeset 835


Ignore:
Timestamp:
Aug 24, 2010, 5:26:25 PM (13 years ago)
Author:
keesvb
Message:

added metabolomics assay examples, cleaned up RestController?, changed assay show link for SAM

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/conf/BootStrapStudies.groovy

    r834 r835  
    388388                .setFieldValue('Fasting period','8h');
    389389
    390 
    391                 def bloodSamplingEvent = new SamplingEvent(
     390                def bloodSamplingEventBefore = new SamplingEvent(
     391                        startTime: 0,
     392                        template: bloodSamplingEventTemplate,
     393                        sampleTemplate: humanBloodSampleTemplate)
     394                .setFieldValue('Sample volume',4.5F);
     395
     396                def bloodSamplingEventAfter = new SamplingEvent(
    392397                        startTime: 3 * 24 * 3600 + 30 * 3600,
    393398                        template: bloodSamplingEventTemplate,
     
    396401
    397402                rootGroup.addToEvents fastingEvent
    398                 rootGroup.addToSamplingEvents bloodSamplingEvent
     403                rootGroup.addToSamplingEvents bloodSamplingEventBefore
     404                rootGroup.addToSamplingEvents bloodSamplingEventAfter
    399405                rootGroup.save()
    400406
     
    424430                                template: humanBloodSampleTemplate,
    425431                                parentSubject: currentSubject,
    426                                 parentEvent: bloodSamplingEvent
     432                                parentEvent: bloodSamplingEventBefore
     433                        );
     434
     435                        humanStudy.addToSamples(currentSample)
     436                        currentSample.with { if (!validate()) { errors.each { println it} } else save()}
     437                        currentSample.setFieldValue( "Text on vial", "T" + (Math.random() * 100L) )
     438
     439                        currentSample = new Sample(
     440                                name: currentSubject.name + '_A',
     441                                material: bloodTerm,
     442                                template: humanBloodSampleTemplate,
     443                                parentSubject: currentSubject,
     444                                parentEvent: bloodSamplingEventAfter
    427445                        );
    428446
     
    433451
    434452                humanStudy.addToEvents(fastingEvent)
    435                 humanStudy.addToSamplingEvents(bloodSamplingEvent)
     453                humanStudy.addToSamplingEvents(bloodSamplingEventBefore)
     454                humanStudy.addToSamplingEvents(bloodSamplingEventAfter)
    436455                humanStudy.addToEventGroups rootGroup
    437456
     
    446465                println ".adding assay references to mouse example study..."
    447466
    448                 // Add SAM assay references
     467                // Add SAM assay reference
    449468                def clinicalModule = new AssayModule(
    450469                        name: 'SAM module for clinical data',
     
    453472                ).with { if (!validate()) { errors.each { println it} } else save()}
    454473
     474                // Add metabolomics assay reference
     475                def metabolomicsModule = new AssayModule(
     476                        name: 'Metabolomics module',
     477                        platform: 'GCMS/LCMS',
     478                        url: 'http://localhost:8080/nmcdsp'
     479                ).with { if (!validate()) { errors.each { println it} } else save()}
     480
    455481                def lipidAssayRef = new Assay(
    456482                        name: 'Lipid profiling',
     
    459485                )
    460486
     487                def metAssayRef = new Assay(
     488                        name: 'Lipidomics profile',
     489                        module: metabolomicsModule,
     490                        externalAssayID: 'PPS3_Lipidomics'
     491                )
     492
    461493                mouseStudy.samples*.each {
    462494                        lipidAssayRef.addToSamples(it)
     495                        metAssayRef.addToSamples(it)
    463496                }
    464497
    465498                mouseStudy.addToAssays(lipidAssayRef);
    466                 mouseStudy.save()
    467 
    468                 //lipidAssayRef.with { if (!validate()) { errors.each { println it} } else save()}
     499                mouseStudy.addToAssays(metAssayRef);
     500                mouseStudy.save(flush:true)
    469501
    470502                println ".adding assay references to human example study..."
    471503
    472                 def  glucoseAssay2Ref = new Assay(
    473                         name: 'Glucose assay 2',
     504                def  glucoseAssayBRef = new Assay(
     505                        name: 'Glucose assay before',
    474506                        module: clinicalModule,
    475                         externalAssayID: 'PPSH-2'
    476                 )
    477 
    478                 def  glucoseAssay3Ref = new Assay(
    479                         name: 'Glucose assay 3',
     507                        externalAssayID: 'PPSH-Glu-B'
     508                )
     509
     510                def  glucoseAssayARef = new Assay(
     511                        name: 'Glucose assay after',
    480512                        module: clinicalModule,
    481                         externalAssayID: 'PPSH-3'
    482                 )
    483 
     513                        externalAssayID: 'PPSH-Glu-A'
     514                )
     515
     516                def metAssayRefB = new Assay(
     517                        name: 'Lipidomics profile before',
     518                        module: metabolomicsModule,
     519                        externalAssayID: 'PPSH_Lipidomics_start'
     520                )
     521
     522                def metAssayRefA = new Assay(
     523                        name: 'Lipidomics profile after',
     524                        module: metabolomicsModule,
     525                        externalAssayID: 'PPSH_Lipidomics_end'
     526                )
    484527                humanStudy.samples*.each {
    485                         glucoseAssay2Ref.addToSamples(it)
    486                         glucoseAssay3Ref.addToSamples(it)
     528                        if (it.parentEvent.startTime == 0) {
     529                                glucoseAssayBRef.addToSamples(it)
     530                                metAssayRefB.addToSamples(it)
     531                        }
     532                        else {
     533                                glucoseAssayARef.addToSamples(it)
     534                                metAssayRefA.addToSamples(it)
     535                        }
    487536                }
    488537
    489538
    490                 humanStudy.addToAssays(glucoseAssay2Ref)
    491                 humanStudy.addToAssays(glucoseAssay3Ref)
    492                 humanStudy.save()
    493                
    494                 //glucoseAssay2Ref.with { if (!validate()) { errors.each { println it} } else save()}
    495                 //glucoseAssay3Ref.with { if (!validate()) { errors.each { println it} } else save()}
     539                humanStudy.addToAssays(glucoseAssayARef)
     540                humanStudy.addToAssays(glucoseAssayBRef)
     541                humanStudy.addToAssays(metAssayRefA)
     542                humanStudy.addToAssays(metAssayRefB)
     543                humanStudy.save(flush:true)
    496544
    497545        }
  • trunk/grails-app/controllers/RestController.groovy

    r834 r835  
    3131
    3232        def authService
    33         def beforeInterceptor = [action:this.&auth]
     33        def beforeInterceptor = [action:this.&auth,except:["isUser"]]
    3434        def credentials
    3535        def requestUser
    36 // defined as a regular method so its private
    3736
    3837        /**
     
    4241         * @return
    4342         */
    44         def auth() {
     43        private def auth() {
    4544            credentials = BasicAuthentication.credentialsFromRequest(request)
    4645                requestUser = authService.authUser(credentials.u,credentials.p)
     
    5453        }
    5554
    56 
     55        /**
     56        * REST resource for data modules.
     57        * Username and password should be supplied via HTTP Basic Authentication.
     58        * Determines whether the given user/password combination is a valid GSCF account.
     59        *
     60        * @return bool True when user/password is a valid GSCF account, false otherwise.
     61        */
     62        def isUser= {
     63                boolean isUser
     64                def reqUser = authService.authUser(credentials.u,credentials.p)
     65                if (reqUser) {
     66                        isUser = true
     67                }
     68                else {
     69                        isUser = false
     70                }
     71                render isUser as JSON
     72        }
    5773
    5874        /**
    59         * REST resource for the Simple Assay Module.
    60         * Provide a list of all studies.
     75        * REST resource for data modules.
     76        * Username and password should be supplied via HTTP Basic Authentication.
     77        * Provide a list of all studies owned by the supplied user.
    6178        *
    62         *
    63         * @return as JSON object list of members externalStudyID, and title for all studies
     79        * @return JSON object list containing 'externalStudyID', and 'name' (title) for each study
    6480        */
    6581        def getStudies = {
     
    7389
    7490        /**
    75         * REST resource for the Simple Assay Module.
    76         * Provide a list of all subjects belonging to a study.
     91        * REST resource for data modules.
     92        * Username and password should be supplied via HTTP Basic Authentication.
     93        * Provide a list of all subjects belonging to a study.
    7794        *
    78         * @param  externalStudyID
    79         * @return as JSON object list of subject names
     95        * @param externalStudyID String The external study id (code) of the target GSCF Study object
     96        * @return JSON object list of subject names
    8097        */
    8198        def getSubjects = {
     
    91108
    92109        /**
    93         * REST resource for the Simple Assay Module.
     110        * REST resource for data modules.
     111        * Username and password should be supplied via HTTP Basic Authentication.
    94112        * Provide a list of all assays for a given study
    95113        *
    96114        * Example call of the getAssays REST resource: http://localhost:8080/gscf/rest/getAssays?externalStudyID=PPSH&moduleURL=http://localhost:8182/sam
    97115        *
    98         * @param externalStudyID The external study id (code) of the target GSCF Study object
    99         * @param moduleURL The base URL of the calling dbNP module
    100         * @return list of assays in the study as JSON object, filtered to only contain assays for the specified module
     116        * @param externalStudyID String The external study id (code) of the target GSCF Study object
     117        * @param moduleURL String The base URL of the calling dbNP module
     118        * @return list of assays in the study as JSON object list, filtered to only contain assays for the specified module, with 'externalAssayID' and 'name' for each assay
    101119        */
    102120        def getAssays = {
     
    116134
    117135        /**
    118         * REST resource for the Simple Assay Module.
    119         * Provide all samples of a given Assay. The result is an enriched list with additional informatin on a sample.
     136        * REST resource for data modules.
     137        * Username and password should be supplied via HTTP Basic Authentication.
     138        * Provide all samples of a given Assay. The result is an enriched list with additional information for each sample.
    120139        *
    121         * @param  assayID (externalAssayID of some Assay in GSCF)
    122         * @return list of element of  Sample.name x Sample.material x Sample.subject.name x Sample.Event.name x Sample.Event.time
     140        * @param externalAssayID String (externalAssayID of some Assay in GSCF)
     141        * @return As a JSON object list, for each sample in that assay:
     142        * @return 'name' (Sample name, which is unique)
     143        * @return 'material' (Sample material)
     144        * @return 'subject' (The name of the subject from which the sample was taken)
     145        * @return 'event' (the name of the template of the SamplingEvent describing the sampling)
     146        * @return 'startTime' (the time the sample was taken relative to the start of the study, as a string)
    123147        */
    124148        def getSamples = {
     
    132156                                        'subject'             : sample.parentSubject.name,
    133157                                        'event'               : sample.parentEvent.template.name,
    134                                         'startTime'           : sample.parentEvent.getStartTimeString(),
    135                                         'externalSampleId': sample.externalSampleId
    136                                 ]
     158                                        'startTime'           : sample.parentEvent.getStartTimeString()
     159                                ]
    137160                                items.push item
    138161                        }
     
    142165
    143166
    144 
    145 
    146 
    147        /****************************/
    148       /** Rest resources for DSP **/
    149      /****************************/
    150    
    151        
    152         /* still not complete!! */
    153 
    154         /**
    155         * REST resource for DSP.
    156         * call: gscf/rest/isUser/?username=username&password=password
    157         *
    158         * @param  String username   
    159         * @param  String password
    160         * @return bool
    161         */
    162         def isUser= {
    163                 def isUser = isVerifiedUser( params )
    164                 render isUser as JSON
    165         }
    166 
    167 
    168         /* still not complete!! */
    169         /**
    170         * REST resource for DSP.
    171         * call: gscf/rest/listStudies/?username=username&password=password
    172         *
    173         * @param  String username
    174         * @param  String password
    175         * @return list of studies
    176         */
    177         def listStudies = {
    178 
    179                 if( !isVerifiedUser( params ) ) {
    180                         render [:] as JSON
    181                         return
    182                 }
    183 
    184                 List studies = []
    185 
    186                 // add code for filtering studies that belong to given user
    187                 // (use Study.findAll( ... ) 
    188                 // ...
    189                 Study.list().each {
    190                         def map = ["study_token":it.code, "name":it.name]
    191                         studies.add( map )
    192                 }
    193                
    194                 render studies as JSON
    195         }
    196 
    197 
    198 
    199         /* still not complete!! */
    200         /**
    201         * REST resource for DSP.
    202         * call: gscf/rest/getStudy/?username=username&password=password&study_token=studytoken
    203         *
    204         * @param  String username
    205         * @param  String password
    206         * @param  String study_token
    207         * @return list of studies
    208         */
    209         def getStudy = {
    210 
    211                 if( !isVerifiedUser( params ) ) {
    212                         render [:] as JSON
    213                         return
    214                 }
    215 
    216                 List studyResult = [:]
    217                 def code   = params.study_token
    218 
    219                 def query = "from Study as s where s.code = ?"
    220                 def study = Study.find( query, code )
    221                 studyResult = [ 'study_token' : study.code, 'name' : study.name ]
    222                         /*  still not complete!!
    223                                 Add features
    224                                         ... study_token:”GHyJeR#g”,
    225                                         ... created: “20/06/2010 22:34:52”,
    226                                         ... meta: [
    227                                         ... greenhouse_id: “GH010938.AB.5”,
    228                                         ... greenhouse_type: “lean-to, detached, and ridge and gutter connected” ]
    229                         */
    230                
    231                 render studyResult as JSON
    232         }
    233 
    234 
    235 
    236 
    237         /* still not complete!! */
    238         /**
    239         * REST resource for DSP.
    240         * call: gscf/rest/listStudySamples/?username=username&password=password&study_token=studytoken
    241         *
    242         * @param  String user name
    243         * @param  String password
    244         * @param  String a valid GSCF Study.code
    245         * @return List of pairs; each pair is a map with keys sample_token and name and values Study.code and Sample.name.
    246         */
    247         def listStudySamples = {
    248 
    249                 if( !isVerifiedUser( params ) ) {
    250                         render [:] as JSON
    251                         return
    252                 }
    253 
    254                 List samples = [:]
    255                 def code = params.study_token
    256                 def query = "from Samples as s where s.study = ?"
    257                 def study = Study.find( query, code )
    258                 if(study) study.samples.each { sample ->
    259                         def map = [ sample_token:code, name:sample.name ]
    260                         samples.add( map )
    261                 }
    262                
    263                 render samples as JSON
    264         }
    265 
    266 
    267 
    268         /* still not complete!! */
    269         /**
    270         * REST resource for DSP.
    271         * call: getStudySample/?username=me&password=123&study_token=GHyJeR#g&sample_name=”AHVJwR”)
    272         *
    273         * @param  String username
    274         * @param  String password
    275         * @param  String study_token
    276         * @param  String sample_name
    277         * @return list of studies
    278         */
    279         def getStudySample = {
    280 
    281                 if( !isVerifiedUser( params ) ) {
    282                         render [:] as JSON
    283                         return
    284                 }
    285 
    286                 List sample = [:]
    287                 def code = params.study_token
    288                 def name = params.sample_name
    289 
    290                 def query = "from Sample as s where s.name = ? AND s.parentStudy "
    291                 def study = Sample.find( query, name )
    292                 sample = [ 'study_token' : sample.code, 'name' : sample.name ]
    293                 // samples will have unique identifier strings
    294                 /*  still not complete!!
    295                                 Add features
    296                                 [
    297                                         study_token:”GHyJeR#g”,
    298                                         sample_token:”AHVJwR”,
    299                                         name: “Sample SMPL002”,
    300                                         created: “25/06/2010 09:14:32”,
    301                                         meta: [ subject: “SUB000294-34942.A”, subject_bmi: “29.3”, ... study_token:”GHyJeR#g”,
    302                                         ... created: “20/06/2010 22:34:52”, greenhouse_id: “GH010938.AB.5”,
    303                                         greenhouse_type: “lean-to, detached, and ridge and gutter connected”
    304                                 ]
    305                         */
    306                 render sample as JSON
    307         }
    308 
    309 
    310 
    311 
    312         /* still not complete!! */
    313         /** Convenience method for isUser and listStudies.
    314         *   Verify user and password.
    315         *   @param  params object with two map keys: (1) 'username', (2) 'password'
    316         *   @param  String password
    317         *   @return bool
    318         */
    319         private isVerifiedUser( params ) {
    320                 def isVerified = false
    321                 def user = params?.username
    322                 def pass = params?.password
    323 
    324                 if( user && pass ) {
    325                         // insert code for verification of user and
    326                         // ...
    327                         isVerified = true
    328                 }
    329                 return isVerified
    330         }
    331 
    332 
    333 
    334167    /* this is just for testing! */
    335     def test = {
     168    /*def test = {
    336169                render( dbnp.rest.common.CommunicationManager.getQueryResultWithOperator("Insulin",">",200) )
    337     }
     170    }*/
    338171}
  • trunk/grails-app/views/study/show.gsp

    r830 r835  
    616616                  <th width="100">Assay Name</th>
    617617                  <th width="100">Module</th>
    618                   <th>Type</th>
    619618                  <th width="150">Platform</th>
    620                   <th>Url</th>
     619                  <th>Link</th>
    621620                  <th>Samples</th>
    622621                </tr>
     
    635634                    <td>${assay.module.name}</td>
    636635                    <td>${assay.module.platform}</td>
    637                     <td>${assay.module.url}</td>
     636                    <td><a href="${dbnp.rest.common.CommunicationManager.getAssayShowURL(assay.externalAssayID)}">view</a></td>
    638637                    <td>
    639638                      <% sortedAssaySamples = assay.samples.sort( { a, b -> a.name <=> b.name } as Comparator )  %>
  • trunk/src/groovy/dbnp/rest/common/CommunicationManager.groovy

    r773 r835  
    173173                // register method that links to the SAM view for showing a SimpleAssay
    174174        // parameters: externalAssayID
    175                 addViewWrapper( 'getAssayShowURL', url, 'simpleAssay/show', ['externalAssayID'] )
     175                addViewWrapper( 'getAssayShowURL', url, 'simpleAssay/showByExternalID', ['externalAssayID'] )
    176176
    177177                // register method that links to the SAM view for editing a SimpleAssay
Note: See TracChangeset for help on using the changeset viewer.