1 /*--------------------------------------------------------------------------
\r
2 * Copyright 2009 Taro L. Saito
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
19 // SilkSchemaTest.java
\r
20 // Since: Jul 3, 2009 3:31:38 PM
\r
24 //--------------------------------------
\r
25 package org.xerial.silk.schema;
\r
27 import static org.junit.Assert.*;
\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
42 public class SilkSchemaTest {
\r
44 private static Logger _logger = Logger.getLogger(SilkSchemaTest.class);
\r
47 public void setUp() throws Exception {}
\r
50 public void tearDown() throws Exception {}
\r
53 public void parse() throws Exception {
\r
54 SilkSchema schema = SilkSchema
\r
55 .parse(FileResource.open(SilkSchemaTest.class, "schema.silk"));
\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
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
72 else if (c.name.equals("Locus")) {
\r
73 assertEquals("Coordinate", c.belongsTo);
\r
75 else if (c.name.equals("Gene")) {
\r
78 else if (c.name.equals("Exon")) {
\r
79 assertEquals("Gene", c.belongsTo);
\r
81 else if (c.name.equals("CDS")) {
\r
82 assertEquals("Gene", c.belongsTo);
\r
84 else if (c.name.equals("Reference")) {
\r
87 else if (c.name.equals("Read")) {
\r
88 assertEquals("Reference", c.belongsTo);
\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
100 _logger.info(Lens.toSilk(schema));
\r
102 //_logger.info(schema.toGraphviz());
\r
107 public void buildQuery() throws Exception {
\r
109 SilkSchema schema = SilkSchema.parse(FileResource.open(SilkSchemaTest.class, "read.silk"));
\r
111 _logger.info(Lens.toSilk(schema));
\r
113 QuerySet qs = schema.buildAmoebaJoinQuery();
\r
117 StreamAmoebaJoin aj = new StreamAmoebaJoin(qs, new AmoebaJoinHandlerBase() {
\r
119 public void leaveNode(Schema schema, Node node) throws Exception {
\r
120 _logger.trace(String.format("leave %s in %s", node, schema));
\r
123 public void newAmoeba(Schema schema, Node coreNode, Node attributeNode)
\r
125 _logger.trace(String.format("amoeba (%s, %s)", coreNode, attributeNode));
\r
128 public void text(Schema schema, Node coreNode, Node textNode, String text)
\r
130 _logger.trace(String.format("text (%s, %s:%s)", coreNode, textNode, text));
\r
134 aj.sweep(new SilkParser(FileResource.open(SilkSchemaTest.class, "../scaffold5001.silk")));
\r