source: trunk/grails-app/domain/nl/tno/metagenomics/Run.groovy @ 7

Last change on this file since 7 was 7, checked in by robert@…, 12 years ago
  • Created tests for the synchronization and trash
  • Improved synchronizationservice and trash
  • Put authorization checks in several pages
File size: 2.3 KB
Line 
1package nl.tno.metagenomics
2
3import org.codehaus.groovy.grails.commons.ConfigurationHolder
4
5/**
6 * Holds data belonging to a sequencing run
7 *
8 * @author Robert Horlings (robert@isdat.nl)
9 *
10 */
11class Run {
12        def fileService
13
14        String  name
15        Date    date
16        String  machine
17        String  supplier
18        String  parameterFile
19
20        static hasMany = [assaySamples: AssaySample, assays: Assay]
21        static belongsTo = Assay        // Only used to determine the owner of the many-to-many relationship assay-run
22
23        static mapping = {
24                columns {
25                        name index:'runname_idx'
26                }
27        }
28        static constraints = {
29                name(unique:true)
30                date(nullable:true)
31                machine(nullable:true)
32                supplier(nullable:true)
33                parameterFile(nullable:true)
34        }
35
36        def beforeDelete = {
37                // Remove the file if the object is deleted
38                if( this.parameterFile )
39                        fileService.delete( this.parameterFile, fileService.absolutePath( ConfigurationHolder.config.metagenomics.fileDir ) )
40        }
41
42        /**
43         * Sets the properties of this run from a form
44         * @param params
45         * @return
46         */
47        public setPropertiesFromForm( params ) {
48                this.properties = params.run
49
50                // Enter date or default NULL
51                if( params.run_date ) {
52                        this.date = Date.parse( "yyyy-mm-dd", params.run_date );
53                } else {
54                        this.date = null
55                }
56
57                // Enter filename if needed
58                if( params.parameterFile ) {
59                        this.parameterFile = fileService.handleUploadedFile(
60                                        fileService.get( params.parameterFile ),
61                                        "",
62                                        fileService.absolutePath( ConfigurationHolder.config.metagenomics.fileDir )
63                                        );
64                }
65        }
66
67        /**
68         * Returns the number of files in the system, belonging to this run
69         *
70         * @return
71         */
72        public int numFiles() {
73                if( !assaySamples )
74                        return 0
75
76                int numFiles = 0;
77                assaySamples.each { numFiles += it.numFiles() }
78
79                return numFiles;
80        }
81
82        /**
83         * Returns the number of sequences in the files in the system, belonging to this run
84         *
85         * @return
86         */
87        public long numSequences() {
88                if( !assaySamples )
89                        return 0
90
91                long numSequences = 0;
92                assaySamples.each { numSequences += it.numSequences() }
93
94                return numSequences;
95        }
96
97        /**
98         * Returns the assaySamples associated with this run
99         *
100         * @return
101         */
102        public ArrayList samples( def assayId ) {
103                if( !assaySamples )
104                        return []
105
106                def list = []
107                assaySamples.each {
108                        if( it.assay.id == assayId )
109                                list << it
110                }
111
112                return list.unique().toList();
113        }
114}
Note: See TracBrowser for help on using the repository browser.