5093 |
10 Sep 09 |
nicklas |
1 |
/** |
5093 |
10 Sep 09 |
nicklas |
$Id$ |
5093 |
10 Sep 09 |
nicklas |
3 |
|
5093 |
10 Sep 09 |
nicklas |
Copyright (C) 2009 Nicklas Nordborg |
5093 |
10 Sep 09 |
nicklas |
5 |
|
5093 |
10 Sep 09 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5093 |
10 Sep 09 |
nicklas |
Available at http://base.thep.lu.se/ |
5093 |
10 Sep 09 |
nicklas |
8 |
|
5093 |
10 Sep 09 |
nicklas |
BASE is free software; you can redistribute it and/or |
5093 |
10 Sep 09 |
nicklas |
modify it under the terms of the GNU General Public License |
5093 |
10 Sep 09 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5093 |
10 Sep 09 |
nicklas |
of the License, or (at your option) any later version. |
5093 |
10 Sep 09 |
nicklas |
13 |
|
5093 |
10 Sep 09 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5093 |
10 Sep 09 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5093 |
10 Sep 09 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5093 |
10 Sep 09 |
nicklas |
GNU General Public License for more details. |
5093 |
10 Sep 09 |
nicklas |
18 |
|
5093 |
10 Sep 09 |
nicklas |
You should have received a copy of the GNU General Public License |
5093 |
10 Sep 09 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5093 |
10 Sep 09 |
nicklas |
21 |
*/ |
5093 |
10 Sep 09 |
nicklas |
22 |
package net.sf.basedb.util.importer.spotdata; |
5093 |
10 Sep 09 |
nicklas |
23 |
|
5093 |
10 Sep 09 |
nicklas |
24 |
import java.util.List; |
5093 |
10 Sep 09 |
nicklas |
25 |
|
5096 |
14 Sep 09 |
nicklas |
26 |
import net.sf.basedb.util.basefile.BaseFileParser; |
5093 |
10 Sep 09 |
nicklas |
27 |
import net.sf.basedb.util.parser.FlatFileParser; |
5093 |
10 Sep 09 |
nicklas |
28 |
import net.sf.basedb.util.parser.FlatFileParser.Data; |
5093 |
10 Sep 09 |
nicklas |
29 |
|
5093 |
10 Sep 09 |
nicklas |
30 |
/** |
5093 |
10 Sep 09 |
nicklas |
Generic spot intensity parser implementation that |
5093 |
10 Sep 09 |
nicklas |
looks for 'intensity1', ..., 'intensityN' data columns for any |
5093 |
10 Sep 09 |
nicklas |
number of channels. |
5093 |
10 Sep 09 |
nicklas |
34 |
|
5093 |
10 Sep 09 |
nicklas |
@author Nicklas |
5093 |
10 Sep 09 |
nicklas |
@version 2.14 |
5093 |
10 Sep 09 |
nicklas |
@base.modified $Date$ |
5093 |
10 Sep 09 |
nicklas |
38 |
*/ |
5093 |
10 Sep 09 |
nicklas |
39 |
public class GenericIntensityParser |
5093 |
10 Sep 09 |
nicklas |
40 |
implements SpotIntensityParser |
5093 |
10 Sep 09 |
nicklas |
41 |
{ |
5093 |
10 Sep 09 |
nicklas |
42 |
|
5093 |
10 Sep 09 |
nicklas |
43 |
private final int channels; |
5093 |
10 Sep 09 |
nicklas |
44 |
private int[] index; |
5093 |
10 Sep 09 |
nicklas |
45 |
|
5093 |
10 Sep 09 |
nicklas |
46 |
/** |
5093 |
10 Sep 09 |
nicklas |
Creates a new parser for the specified number of channels. |
5093 |
10 Sep 09 |
nicklas |
48 |
*/ |
5093 |
10 Sep 09 |
nicklas |
49 |
public GenericIntensityParser(int channels) |
5093 |
10 Sep 09 |
nicklas |
50 |
{ |
5093 |
10 Sep 09 |
nicklas |
51 |
this.channels = channels; |
5093 |
10 Sep 09 |
nicklas |
52 |
} |
5093 |
10 Sep 09 |
nicklas |
53 |
|
5093 |
10 Sep 09 |
nicklas |
54 |
/* |
5093 |
10 Sep 09 |
nicklas |
From the SpotIntensityParser interface |
5093 |
10 Sep 09 |
nicklas |
56 |
-------------------------------------- |
5093 |
10 Sep 09 |
nicklas |
57 |
*/ |
5093 |
10 Sep 09 |
nicklas |
58 |
@Override |
5096 |
14 Sep 09 |
nicklas |
59 |
public boolean hasRequiredAssayFields(BaseFileParser parser, FlatFileParser ffp, |
5093 |
10 Sep 09 |
nicklas |
60 |
List<String> assayFields) |
5093 |
10 Sep 09 |
nicklas |
61 |
{ |
5093 |
10 Sep 09 |
nicklas |
62 |
for (int i = 1; i <= channels; ++i) |
5093 |
10 Sep 09 |
nicklas |
63 |
{ |
5096 |
14 Sep 09 |
nicklas |
64 |
int index = assayFields.indexOf(parser.getRedefinedColumnName("spots", "intensity" + i)); |
5093 |
10 Sep 09 |
nicklas |
65 |
if (index < 0) return false; |
5093 |
10 Sep 09 |
nicklas |
66 |
} |
5093 |
10 Sep 09 |
nicklas |
67 |
return true; |
5093 |
10 Sep 09 |
nicklas |
68 |
} |
5093 |
10 Sep 09 |
nicklas |
69 |
|
5093 |
10 Sep 09 |
nicklas |
70 |
@Override |
5096 |
14 Sep 09 |
nicklas |
71 |
public void beginSection(BaseFileParser parser, FlatFileParser ffp, |
5096 |
14 Sep 09 |
nicklas |
72 |
List<String> assayFields) |
5093 |
10 Sep 09 |
nicklas |
73 |
{ |
5093 |
10 Sep 09 |
nicklas |
74 |
index = new int[channels]; |
5093 |
10 Sep 09 |
nicklas |
75 |
for (int i = 1; i <= channels; ++i) |
5093 |
10 Sep 09 |
nicklas |
76 |
{ |
5096 |
14 Sep 09 |
nicklas |
77 |
index[i-1] = assayFields.indexOf(parser.getRedefinedColumnName("spots", "intensity" + i)); |
5093 |
10 Sep 09 |
nicklas |
78 |
} |
5093 |
10 Sep 09 |
nicklas |
79 |
} |
5093 |
10 Sep 09 |
nicklas |
80 |
|
5093 |
10 Sep 09 |
nicklas |
81 |
@Override |
5093 |
10 Sep 09 |
nicklas |
82 |
public boolean setIntensities(Data data, float[] intensities, int firstIndex) |
5093 |
10 Sep 09 |
nicklas |
83 |
{ |
5093 |
10 Sep 09 |
nicklas |
84 |
for (int i = 0; i < channels; ++i) |
5093 |
10 Sep 09 |
nicklas |
85 |
{ |
7665 |
20 Mar 19 |
nicklas |
86 |
Float value = data.getFloat(index[i] + firstIndex, null, true); |
7665 |
20 Mar 19 |
nicklas |
87 |
if (value == null) return false; |
5093 |
10 Sep 09 |
nicklas |
88 |
intensities[i] = value; |
5093 |
10 Sep 09 |
nicklas |
89 |
} |
5093 |
10 Sep 09 |
nicklas |
90 |
return true; |
5093 |
10 Sep 09 |
nicklas |
91 |
} |
5093 |
10 Sep 09 |
nicklas |
92 |
// --------------------------------------- |
5093 |
10 Sep 09 |
nicklas |
93 |
|
5093 |
10 Sep 09 |
nicklas |
94 |
} |