1 | package nl.tno.metagenomics |
---|
2 | |
---|
3 | /** |
---|
4 | * Represents a samples that is used in an assay. |
---|
5 | * |
---|
6 | * @author Robert Horlings (robert@isdat.nl) |
---|
7 | * |
---|
8 | */ |
---|
9 | class AssaySample { |
---|
10 | // To be computed in run time |
---|
11 | private long _numSequences = -1; |
---|
12 | private float _averageQuality = -1.0; |
---|
13 | |
---|
14 | Integer numUniqueSequences // Number of unique sequences / OTUs. Is only available after preprocessing |
---|
15 | |
---|
16 | String oligoNumber // Oligonumber used to identify the sample |
---|
17 | String tagSequence // Tag originally used to identify the sample |
---|
18 | |
---|
19 | static belongsTo = [ assay: Assay, sample: Sample ] |
---|
20 | static hasMany = [ sequenceData: SequenceData ] |
---|
21 | |
---|
22 | static constraints = { |
---|
23 | numUniqueSequences(nullable: true) |
---|
24 | oligoNumber(nullable: true) |
---|
25 | tagSequence(nullable: true) |
---|
26 | } |
---|
27 | |
---|
28 | static mapping = { |
---|
29 | columns { |
---|
30 | numSequences index:'numsequences_idx' |
---|
31 | } |
---|
32 | } |
---|
33 | |
---|
34 | /** |
---|
35 | * Returns the number of files in the system, belonging to this |
---|
36 | * assay-sample combination. |
---|
37 | * |
---|
38 | * @return |
---|
39 | */ |
---|
40 | public int numFiles() { |
---|
41 | if( !sequenceData ) |
---|
42 | return 0 |
---|
43 | |
---|
44 | int numFiles = 0; |
---|
45 | sequenceData.each { numFiles += it.numFiles() } |
---|
46 | |
---|
47 | return numFiles; |
---|
48 | } |
---|
49 | |
---|
50 | /** |
---|
51 | * Returns the number of sequences in the files on the system, belonging to this |
---|
52 | * assay-sample combination. |
---|
53 | * |
---|
54 | * @return |
---|
55 | */ |
---|
56 | public long numSequences() { |
---|
57 | if( _numSequences > -1 ) |
---|
58 | return _numSequences; |
---|
59 | |
---|
60 | if( !sequenceData ) |
---|
61 | return 0 |
---|
62 | |
---|
63 | long numSequences = 0; |
---|
64 | sequenceData.each { numSequences += it.numSequences } |
---|
65 | |
---|
66 | // Save as cache |
---|
67 | _numSequences = numSequences; |
---|
68 | |
---|
69 | return numSequences; |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | * Returns the average quality of the sequences in the files on the system, |
---|
74 | * belonging to this assay-sample combination. |
---|
75 | * |
---|
76 | * @return |
---|
77 | */ |
---|
78 | public float averageQuality() { |
---|
79 | if( _averageQuality > -1 ) |
---|
80 | return _averageQuality; |
---|
81 | |
---|
82 | if( !sequenceData ) |
---|
83 | return 0.0 |
---|
84 | |
---|
85 | int numSequences = 0; |
---|
86 | float averageQuality = 0.0; |
---|
87 | |
---|
88 | sequenceData.each { |
---|
89 | numSequences += it.numSequences |
---|
90 | averageQuality = averageQuality + ( it.averageQuality - averageQuality ) / numSequences * it.numSequences; |
---|
91 | } |
---|
92 | |
---|
93 | // Save as cache |
---|
94 | _averageQuality = averageQuality; |
---|
95 | |
---|
96 | return averageQuality; |
---|
97 | } |
---|
98 | } |
---|