OSDN Git Service

how to mirror to SourceForge.jp
[xerial/xerial-core.git] / src / test / java / org / xerial / silk / schema / SilkSchemaTest.java
1 /*--------------------------------------------------------------------------\r
2  *  Copyright 2009 Taro L. Saito\r
3  *\r
4  *  Licensed under the Apache License, Version 2.0 (the "License");\r
5  *  you may not use this file except in compliance with the License.\r
6  *  You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  *  Unless required by applicable law or agreed to in writing, software\r
11  *  distributed under the License is distributed on an "AS IS" BASIS,\r
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  *  See the License for the specific language governing permissions and\r
14  *  limitations under the License.\r
15  *--------------------------------------------------------------------------*/\r
16 //--------------------------------------j\r
17 // XerialJ\r
18 //\r
19 // SilkSchemaTest.java\r
20 // Since: Jul 3, 2009 3:31:38 PM\r
21 //\r
22 // $URL$\r
23 // $Author$\r
24 //--------------------------------------\r
25 package org.xerial.silk.schema;\r
26 \r
27 import static org.junit.Assert.*;\r
28 \r
29 import org.junit.After;\r
30 import org.junit.Before;\r
31 import org.junit.Test;\r
32 import org.xerial.lens.Lens;\r
33 import org.xerial.lens.relation.Node;\r
34 import org.xerial.lens.relation.query.AmoebaJoinHandlerBase;\r
35 import org.xerial.lens.relation.query.QuerySet;\r
36 import org.xerial.lens.relation.query.StreamAmoebaJoin;\r
37 import org.xerial.lens.relation.schema.Schema;\r
38 import org.xerial.silk.SilkParser;\r
39 import org.xerial.util.FileResource;\r
40 import org.xerial.util.log.Logger;\r
41 \r
42 public class SilkSchemaTest {\r
43 \r
44     private static Logger _logger = Logger.getLogger(SilkSchemaTest.class);\r
45 \r
46     @Before\r
47     public void setUp() throws Exception {}\r
48 \r
49     @After\r
50     public void tearDown() throws Exception {}\r
51 \r
52     @Test\r
53     public void parse() throws Exception {\r
54         SilkSchema schema = SilkSchema\r
55                 .parse(FileResource.open(SilkSchemaTest.class, "schema.silk"));\r
56 \r
57         // confirm module\r
58         SilkModule globalModule = schema.globalModule;\r
59         assertNotNull(globalModule.module);\r
60         assertEquals(1, globalModule.module.size());\r
61         SilkModule m = globalModule.module.get(0);\r
62         assertEquals("org.utgenome", m.name);\r
63 \r
64         // confirm classes\r
65 \r
66         assertNotNull(m.classDef);\r
67         assertEquals(7, m.classDef.size());\r
68         for (SilkClass c : m.classDef) {\r
69             if (c.name.equals("Coordinate")) {\r
70                 assertNull(c.belongsTo);\r
71             }\r
72             else if (c.name.equals("Locus")) {\r
73                 assertEquals("Coordinate", c.belongsTo);\r
74             }\r
75             else if (c.name.equals("Gene")) {\r
76 \r
77             }\r
78             else if (c.name.equals("Exon")) {\r
79                 assertEquals("Gene", c.belongsTo);\r
80             }\r
81             else if (c.name.equals("CDS")) {\r
82                 assertEquals("Gene", c.belongsTo);\r
83             }\r
84             else if (c.name.equals("Reference")) {\r
85 \r
86             }\r
87             else if (c.name.equals("Read")) {\r
88                 assertEquals("Reference", c.belongsTo);\r
89             }\r
90 \r
91         }\r
92 \r
93         // confirm relation\r
94         //        assertNotNull(schema.relation);\r
95         //        assertEquals(1, schema.relation.size());\r
96         //        SilkRelation r = schema.relation.get(0);\r
97         //        assertEquals("Alignment", r.name);\r
98         //        assertEquals(2, r.attribute.size());\r
99 \r
100         _logger.info(Lens.toSilk(schema));\r
101 \r
102         //_logger.info(schema.toGraphviz());\r
103 \r
104     }\r
105 \r
106     @Test\r
107     public void buildQuery() throws Exception {\r
108 \r
109         SilkSchema schema = SilkSchema.parse(FileResource.open(SilkSchemaTest.class, "read.silk"));\r
110 \r
111         _logger.info(Lens.toSilk(schema));\r
112 \r
113         QuerySet qs = schema.buildAmoebaJoinQuery();\r
114 \r
115         _logger.info(qs);\r
116 \r
117         StreamAmoebaJoin aj = new StreamAmoebaJoin(qs, new AmoebaJoinHandlerBase() {\r
118 \r
119             public void leaveNode(Schema schema, Node node) throws Exception {\r
120                 _logger.trace(String.format("leave %s in %s", node, schema));\r
121             }\r
122 \r
123             public void newAmoeba(Schema schema, Node coreNode, Node attributeNode)\r
124                     throws Exception {\r
125                 _logger.trace(String.format("amoeba (%s, %s)", coreNode, attributeNode));\r
126             }\r
127 \r
128             public void text(Schema schema, Node coreNode, Node textNode, String text)\r
129                     throws Exception {\r
130                 _logger.trace(String.format("text (%s, %s:%s)", coreNode, textNode, text));\r
131             }\r
132         });\r
133 \r
134         aj.sweep(new SilkParser(FileResource.open(SilkSchemaTest.class, "../scaffold5001.silk")));\r
135 \r
136     }\r
137 \r
138 }\r