Changeset 1811


Ignore:
Timestamp:
May 4, 2011, 4:39:01 PM (12 years ago)
Author:
s.h.sikkema@…
Message:

study design inferring in progress

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/dbnp/studycapturing/SimpleWizardController.groovy

    r1794 r1811  
    12301230                return errors
    12311231        }
     1232
     1233    // TEMPORARY ACTION TO TEST CORRECT STUDY DESIGN INFERRING: SHOULD BE REMOVED WHEN DONE
     1234    def testMethod = {
     1235
     1236        def data = [//['sample name',         'subject',         'timepoint'],
     1237                    [ '97___N_151_HAKA_1',    'N_151_HAKA',    '0w'],
     1238                    [ '98___N_163_QUJO_3',    'N_163_QUJO',    '2w'],
     1239                    [ '99___N_151_HAKA_2',    'N_151_HAKA',    '1w'],
     1240                    ['100___N_163_QUJO_4',    'N_163_QUJO',    '3w'],
     1241                    ['101___N_151_HAKA_3',    'N_151_HAKA',    '2w'],
     1242                    ['102___N_163_QUJO_2',    'N_163_QUJO',    '1w'],
     1243                    ['103___U_031_SMGI_1',    'U_031_SMGI',    '0w'],
     1244                    ['104___U_031_SMGI_3',    'U_031_SMGI',    '2w'],
     1245                    ['105___N_163_QUJO_1',    'N_163_QUJO',    '0w'],
     1246                    ['106___U_031_SMGI_4',    'U_031_SMGI',    '3w'],
     1247                    ['107___N_151_HAKA_4',    'N_151_HAKA',    '3w'],
     1248                    ['108___U_031_SMGI_2',    'U_031_SMGI',    '1w'],
     1249                    ['109___N_021_THAA_2',    'N_021_THAA',    '1w'],
     1250                    ['110___U_029_DUJA_2',    'U_029_DUJA',    '1w'],
     1251                    ['111___U_029_DUJA_3',    'U_029_DUJA',    '2w'],
     1252                    ['112___N_021_THAA_3',    'N_021_THAA',    '2w'],
     1253                    ['113___U_029_DUJA_4',    'U_029_DUJA',    '3w'],
     1254                    ['114___N_045_SNSU_1',    'N_045_SNSU',    '0w'],
     1255                    ['115___N_021_THAA_1',    'N_021_THAA',    '0w'],
     1256                    ['116___N_045_SNSU_2',    'N_045_SNSU',    '1w'],
     1257                    ['117___N_045_SNSU_3',    'N_045_SNSU',    '2w'],
     1258                    ['118___N_045_SNSU_4',    'N_045_SNSU',    '3w'],
     1259                    ['119___N_021_THAA_4',    'N_021_THAA',    '3w'],
     1260                    ['120___U_029_DUJA_1',    'U_029_DUJA',    '0w'],
     1261                    ['121___U_060_BRGE_3',    'U_060_BRGE',    '2w'],
     1262                    ['122___N_018_WIHA_1',    'N_018_WIHA',    '0w'],
     1263                    ['123___N_022_HUCA_3',    'N_022_HUCA',    '2w'],
     1264                    ['124___N_022_HUCA_2',    'N_022_HUCA',    '1w']]
     1265
     1266        def sampleTemplate = Template.findByName 'Human blood sample'
     1267        def subjectTemplate = Template.findByName 'Human'
     1268        def samplingEventTemplate = Template.findByName 'Blood extraction'
     1269        def eventTemplate = Template.findByName 'Diet treatment'
     1270
     1271
     1272        // Table is a collection of records. A records contains entities of type
     1273        // Sample, Subject, and SamplingEvent. This mimics the output of
     1274        // importerService.importOrUpdateDataBySampleIdentifier
     1275        def table = data.collect { row ->
     1276
     1277            [       new Sample( name: row[0], template: sampleTemplate),
     1278                    new Subject(name: row[1], template: subjectTemplate),
     1279                    new SamplingEvent(template: samplingEventTemplate).setFieldValue('startTime', row[2])
     1280//                    new Event(template: eventTemplate)
     1281            ]
     1282
     1283        }
     1284
     1285        // collect unique subjects and sampling events from table
     1286        def uniqueSubjects = table.collect{it[1]}.unique()
     1287        def uniqueSamplingEvents = table.collect{it[2]}.unique()
     1288
     1289        // create an event group for each unique sampling event (not much of a group, is it ...)
     1290        def eventGroups = uniqueSamplingEvents.collect{
     1291            def eventGroup = new EventGroup(name: "Sampling_${it.name}_${it.startTime}").addToSamplingEvents(it)
     1292            //study.addToEventGroups eventGroup
     1293            eventGroup
     1294        }
     1295        //TODO: add event groups to study
     1296
     1297//        uniqueSubjects.each {
     1298//            eventGroup.addToSubjects it
     1299//            // study.addToSubject it
     1300//        }
     1301
     1302        table.each{ record ->
     1303
     1304            Sample sample = record[0]
     1305
     1306            // gather all sample related entities
     1307            def correspondingSamplingEvent  = uniqueSamplingEvents.findByStartTime(record[2].startTime)
     1308            def correspondingSubject        = uniqueSubjects.findByName(record[1].name)
     1309            def correspondingEventGroup     = correspondingSamplingEvent.eventGroup
     1310
     1311            correspondingSamplingEvent.addToSamples sample
     1312            correspondingEventGroup.addToSamples    sample
     1313            correspondingEventGroup.addToSubjects   correspondingSubject
     1314            sample.parentSubject =                  correspondingSubject
     1315
     1316
     1317
     1318
     1319            // study.addToSamples sample
     1320            uniqueSamplingEvents.findByStartTime(record[2].startTime).addToSamples(sample)
     1321            sample.addToSubjects(uniqueSubjects.findByName(record[1].name))
     1322
     1323        }
     1324
     1325
     1326        println 'hoi'
     1327        render 'bla'
     1328
     1329    }
    12321330}
Note: See TracChangeset for help on using the changeset viewer.