783 |
18 Sep 08 |
jari |
1 |
/* |
783 |
18 Sep 08 |
jari |
$Id$ |
783 |
18 Sep 08 |
jari |
3 |
|
783 |
18 Sep 08 |
jari |
Copyright (C) 2006 Johan Enell |
783 |
18 Sep 08 |
jari |
5 |
|
783 |
18 Sep 08 |
jari |
This file is part of the se.lu.onk.MergeBioAssay plug-in for |
783 |
18 Sep 08 |
jari |
BASE. Available at http://baseplugins.thep.lu.se/ and BASE web |
783 |
18 Sep 08 |
jari |
site is http://base.thep.lu.se |
783 |
18 Sep 08 |
jari |
9 |
|
783 |
18 Sep 08 |
jari |
This is free software; you can redistribute it and/or modify it |
783 |
18 Sep 08 |
jari |
under the terms of the GNU General Public License as published by |
783 |
18 Sep 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
783 |
18 Sep 08 |
jari |
(at your option) any later version. |
783 |
18 Sep 08 |
jari |
14 |
|
783 |
18 Sep 08 |
jari |
The software is distributed in the hope that it will be useful, but |
783 |
18 Sep 08 |
jari |
WITHOUT ANY WARRANTY; without even the implied warranty of |
783 |
18 Sep 08 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
783 |
18 Sep 08 |
jari |
General Public License for more details. |
783 |
18 Sep 08 |
jari |
19 |
|
783 |
18 Sep 08 |
jari |
You should have received a copy of the GNU General Public License |
783 |
18 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
783 |
18 Sep 08 |
jari |
22 |
*/ |
149 |
10 Aug 06 |
enell |
23 |
package mergebioassay.mergers; |
149 |
10 Aug 06 |
enell |
24 |
|
149 |
10 Aug 06 |
enell |
25 |
import mergebioassay.BioAssay; |
149 |
10 Aug 06 |
enell |
26 |
|
149 |
10 Aug 06 |
enell |
27 |
import java.util.Vector; |
149 |
10 Aug 06 |
enell |
28 |
|
149 |
10 Aug 06 |
enell |
29 |
|
149 |
10 Aug 06 |
enell |
30 |
/** |
149 |
10 Aug 06 |
enell |
* @author Johan Enell |
149 |
10 Aug 06 |
enell |
32 |
* |
149 |
10 Aug 06 |
enell |
* An subclass of BioAssays. It implements a parse methode used to goup BioAssays |
149 |
10 Aug 06 |
enell |
34 |
*/ |
149 |
10 Aug 06 |
enell |
35 |
public class Merge_assay extends BioAssay |
149 |
10 Aug 06 |
enell |
36 |
{ |
149 |
10 Aug 06 |
enell |
// v[0-9] - reserved for variabels %0 - %9 |
149 |
10 Aug 06 |
enell |
// v[10] - reserved for annotation value |
149 |
10 Aug 06 |
enell |
// v[11] - reserved for ratio value |
149 |
10 Aug 06 |
enell |
40 |
public String[] v = new String[12]; |
149 |
10 Aug 06 |
enell |
41 |
|
149 |
10 Aug 06 |
enell |
42 |
/** |
149 |
10 Aug 06 |
enell |
* Creates a new Merge_assay. |
149 |
10 Aug 06 |
enell |
44 |
* |
149 |
10 Aug 06 |
enell |
* @param id - the id of the BioAssay |
149 |
10 Aug 06 |
enell |
* @param name - the name of the BioAssay |
149 |
10 Aug 06 |
enell |
47 |
*/ |
149 |
10 Aug 06 |
enell |
48 |
public Merge_assay(String id, String name) |
149 |
10 Aug 06 |
enell |
49 |
{ |
149 |
10 Aug 06 |
enell |
50 |
super(id, name); |
149 |
10 Aug 06 |
enell |
51 |
} |
149 |
10 Aug 06 |
enell |
52 |
|
149 |
10 Aug 06 |
enell |
53 |
/** |
149 |
10 Aug 06 |
enell |
* This method will parse the name of the BioAssay using the input string as pattern. The |
149 |
10 Aug 06 |
enell |
* pattern consists of variable numbers, %0-%9, and some characters dividing them. |
149 |
10 Aug 06 |
enell |
56 |
* |
149 |
10 Aug 06 |
enell |
* @param pattern - the pattern used for the parsing |
149 |
10 Aug 06 |
enell |
* @return tru if the parsing was done without any error |
149 |
10 Aug 06 |
enell |
59 |
*/ |
149 |
10 Aug 06 |
enell |
60 |
public boolean parse_name(String pattern) throws BadPatternException |
149 |
10 Aug 06 |
enell |
61 |
{ |
149 |
10 Aug 06 |
enell |
62 |
Vector<String> tokens = new Vector<String>(); |
149 |
10 Aug 06 |
enell |
63 |
int start = 0; |
149 |
10 Aug 06 |
enell |
64 |
|
149 |
10 Aug 06 |
enell |
65 |
for (int i = pattern.indexOf('%', start); i != -1; i = pattern.indexOf('%', start)) |
149 |
10 Aug 06 |
enell |
66 |
{ |
149 |
10 Aug 06 |
enell |
67 |
tokens.add(pattern.substring(start, i)); |
149 |
10 Aug 06 |
enell |
68 |
if (pattern.charAt(i + 1) >= 48 && pattern.charAt(i + 1) <= 57) |
149 |
10 Aug 06 |
enell |
69 |
{ |
149 |
10 Aug 06 |
enell |
70 |
tokens.add("%" + pattern.charAt(i + 1)); |
149 |
10 Aug 06 |
enell |
71 |
} |
149 |
10 Aug 06 |
enell |
72 |
else |
149 |
10 Aug 06 |
enell |
73 |
{ |
149 |
10 Aug 06 |
enell |
74 |
throw new BadPatternException("A % in the assayname must be followed by a number 0-9"); |
149 |
10 Aug 06 |
enell |
75 |
} |
149 |
10 Aug 06 |
enell |
76 |
start = i + 2; |
149 |
10 Aug 06 |
enell |
77 |
} |
149 |
10 Aug 06 |
enell |
78 |
if (start < pattern.length()) tokens.add(pattern.substring(start, pattern.length())); |
149 |
10 Aug 06 |
enell |
79 |
|
149 |
10 Aug 06 |
enell |
80 |
start = 0; |
149 |
10 Aug 06 |
enell |
81 |
int end = 0; |
149 |
10 Aug 06 |
enell |
82 |
for (int i = 0; i < tokens.size(); i++) |
149 |
10 Aug 06 |
enell |
83 |
{ |
149 |
10 Aug 06 |
enell |
84 |
String tok = tokens.get(i); |
149 |
10 Aug 06 |
enell |
85 |
|
149 |
10 Aug 06 |
enell |
86 |
if (tok.startsWith("%")) |
149 |
10 Aug 06 |
enell |
87 |
{ |
149 |
10 Aug 06 |
enell |
88 |
if (i < tokens.size() - 1) |
149 |
10 Aug 06 |
enell |
89 |
{ |
149 |
10 Aug 06 |
enell |
90 |
end = name.indexOf(tokens.get(i + 1), start); |
149 |
10 Aug 06 |
enell |
91 |
|
149 |
10 Aug 06 |
enell |
92 |
if (end == -1) { return false; } |
149 |
10 Aug 06 |
enell |
93 |
} |
149 |
10 Aug 06 |
enell |
94 |
else |
149 |
10 Aug 06 |
enell |
95 |
{ |
149 |
10 Aug 06 |
enell |
96 |
end = name.length(); |
149 |
10 Aug 06 |
enell |
97 |
} |
149 |
10 Aug 06 |
enell |
98 |
|
149 |
10 Aug 06 |
enell |
99 |
v[tok.charAt(1) - 48] = name.substring(start, end); |
149 |
10 Aug 06 |
enell |
100 |
start = end; |
149 |
10 Aug 06 |
enell |
101 |
} |
149 |
10 Aug 06 |
enell |
102 |
else if (name.substring(start, start + tok.length()).equals(tok)) |
149 |
10 Aug 06 |
enell |
103 |
{ |
149 |
10 Aug 06 |
enell |
104 |
start += tok.length(); |
149 |
10 Aug 06 |
enell |
105 |
} |
149 |
10 Aug 06 |
enell |
106 |
else |
149 |
10 Aug 06 |
enell |
107 |
{ |
149 |
10 Aug 06 |
enell |
108 |
return false; |
149 |
10 Aug 06 |
enell |
109 |
} |
149 |
10 Aug 06 |
enell |
110 |
} |
149 |
10 Aug 06 |
enell |
111 |
return true; |
149 |
10 Aug 06 |
enell |
112 |
} |
149 |
10 Aug 06 |
enell |
113 |
} |