5759 |
26 Sep 11 |
nicklas |
1 |
/* |
5759 |
26 Sep 11 |
nicklas |
$Id$ |
5759 |
26 Sep 11 |
nicklas |
3 |
|
5759 |
26 Sep 11 |
nicklas |
BioArray Software Environment (BASE) - http://base.thep.lu.se/ |
5759 |
26 Sep 11 |
nicklas |
Copyright (C) 2007 Johan Enell, Nicklas Nordborg |
5759 |
26 Sep 11 |
nicklas |
6 |
|
5759 |
26 Sep 11 |
nicklas |
This file is part of BASE. |
5759 |
26 Sep 11 |
nicklas |
8 |
|
5759 |
26 Sep 11 |
nicklas |
BASE is free software; you can redistribute it and/or |
5759 |
26 Sep 11 |
nicklas |
modify it under the terms of the GNU General Public License |
5759 |
26 Sep 11 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5759 |
26 Sep 11 |
nicklas |
of the License, or (at your option) any later version. |
5759 |
26 Sep 11 |
nicklas |
13 |
|
5759 |
26 Sep 11 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5759 |
26 Sep 11 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5759 |
26 Sep 11 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5759 |
26 Sep 11 |
nicklas |
GNU General Public License for more details. |
5759 |
26 Sep 11 |
nicklas |
18 |
|
5759 |
26 Sep 11 |
nicklas |
You should have received a copy of the GNU General Public License |
5759 |
26 Sep 11 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5759 |
26 Sep 11 |
nicklas |
21 |
*/ |
5759 |
26 Sep 11 |
nicklas |
22 |
import java.io.InputStream; |
5759 |
26 Sep 11 |
nicklas |
23 |
import java.util.regex.Pattern; |
5759 |
26 Sep 11 |
nicklas |
24 |
|
5759 |
26 Sep 11 |
nicklas |
25 |
import net.sf.basedb.util.FileUtil; |
5759 |
26 Sep 11 |
nicklas |
26 |
import net.sf.basedb.util.gtf.GtfInputStream; |
5759 |
26 Sep 11 |
nicklas |
27 |
import net.sf.basedb.util.parser.FlatFileParser; |
5759 |
26 Sep 11 |
nicklas |
28 |
|
5759 |
26 Sep 11 |
nicklas |
29 |
public class TestGtfInputStream |
5759 |
26 Sep 11 |
nicklas |
30 |
{ |
5759 |
26 Sep 11 |
nicklas |
31 |
|
5759 |
26 Sep 11 |
nicklas |
32 |
static boolean ok = true; |
5759 |
26 Sep 11 |
nicklas |
33 |
public static void main(String[] args) |
5759 |
26 Sep 11 |
nicklas |
34 |
{ |
5759 |
26 Sep 11 |
nicklas |
35 |
TestUtil.checkArgs(args); |
5759 |
26 Sep 11 |
nicklas |
36 |
TestUtil.begin(); |
5759 |
26 Sep 11 |
nicklas |
37 |
ok = test_all(); |
5759 |
26 Sep 11 |
nicklas |
38 |
TestUtil.stop(); |
5759 |
26 Sep 11 |
nicklas |
39 |
} |
5759 |
26 Sep 11 |
nicklas |
40 |
|
5759 |
26 Sep 11 |
nicklas |
41 |
static boolean test_all() |
5759 |
26 Sep 11 |
nicklas |
42 |
{ |
5759 |
26 Sep 11 |
nicklas |
43 |
write("++Testing GTFInputStream"); |
5759 |
26 Sep 11 |
nicklas |
44 |
|
5759 |
26 Sep 11 |
nicklas |
45 |
test_parse("data/test.gtf", |
5770 |
29 Sep 11 |
nicklas |
46 |
"\\<transcript_id>\\@\\<seqname>\\", "\\<source>\\", "\\<gene_id>\\", "\\<gene_name2>\\"); |
5759 |
26 Sep 11 |
nicklas |
47 |
|
5759 |
26 Sep 11 |
nicklas |
48 |
write("++Testing GTFInputStream "+(ok ? "OK" : "Failed")+"\n"); |
5759 |
26 Sep 11 |
nicklas |
49 |
return ok; |
5759 |
26 Sep 11 |
nicklas |
50 |
} |
5759 |
26 Sep 11 |
nicklas |
51 |
|
5759 |
26 Sep 11 |
nicklas |
52 |
static void write(String message) |
5759 |
26 Sep 11 |
nicklas |
53 |
{ |
5759 |
26 Sep 11 |
nicklas |
54 |
System.out.println(message); |
5759 |
26 Sep 11 |
nicklas |
55 |
} |
5759 |
26 Sep 11 |
nicklas |
56 |
|
5759 |
26 Sep 11 |
nicklas |
57 |
static void test_parse(String file, String... mappings) |
5759 |
26 Sep 11 |
nicklas |
58 |
{ |
5759 |
26 Sep 11 |
nicklas |
59 |
try |
5759 |
26 Sep 11 |
nicklas |
60 |
{ |
5759 |
26 Sep 11 |
nicklas |
61 |
FlatFileParser ffp = new FlatFileParser(); |
5759 |
26 Sep 11 |
nicklas |
62 |
ffp.setDataHeaderRegexp(Pattern.compile("\\<seqname\\>.*")); |
5759 |
26 Sep 11 |
nicklas |
63 |
ffp.setDataSplitterRegexp(Pattern.compile("\\t")); |
6459 |
27 May 14 |
nicklas |
64 |
ffp.setIgnoreRegexp(Pattern.compile("^#.*")); |
5759 |
26 Sep 11 |
nicklas |
65 |
ffp.setMinDataColumns(4); |
5759 |
26 Sep 11 |
nicklas |
66 |
ffp.setMaxDataColumns(-1); |
5759 |
26 Sep 11 |
nicklas |
67 |
|
5759 |
26 Sep 11 |
nicklas |
68 |
InputStream gtf = new GtfInputStream(FileUtil.getInputStream(new java.io.File(file)), "ISO-8859-1", true); |
5759 |
26 Sep 11 |
nicklas |
69 |
TestFlatFileParser.test_parse(ffp, file, gtf, mappings); |
5759 |
26 Sep 11 |
nicklas |
70 |
if (!TestFlatFileParser.ok) |
5759 |
26 Sep 11 |
nicklas |
71 |
{ |
5759 |
26 Sep 11 |
nicklas |
72 |
ok = false; |
5759 |
26 Sep 11 |
nicklas |
73 |
} |
5759 |
26 Sep 11 |
nicklas |
74 |
} |
5759 |
26 Sep 11 |
nicklas |
75 |
catch (Throwable ex) |
5759 |
26 Sep 11 |
nicklas |
76 |
{ |
5759 |
26 Sep 11 |
nicklas |
77 |
write("--Parse FAILED (" + file + ")"); |
5759 |
26 Sep 11 |
nicklas |
78 |
ex.printStackTrace(); |
5759 |
26 Sep 11 |
nicklas |
79 |
ok = false; |
5759 |
26 Sep 11 |
nicklas |
80 |
} |
5759 |
26 Sep 11 |
nicklas |
81 |
} |
5759 |
26 Sep 11 |
nicklas |
82 |
|
5759 |
26 Sep 11 |
nicklas |
83 |
} |
5759 |
26 Sep 11 |
nicklas |
84 |
|