1 /*--------------------------------------------------------------------------
2 * Copyright 2009 Taro L. Saito
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *--------------------------------------------------------------------------*/
16 //--------------------------------------
20 // Since: Feb 23, 2009 6:02:27 PM
24 //--------------------------------------
25 package org.xerial.lens;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNotNull;
30 import java.io.IOException;
31 import java.util.ArrayList;
32 import java.util.List;
35 import org.junit.After;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.xerial.core.XerialException;
39 import org.xerial.silk.SilkUtilTest;
40 import org.xerial.util.FileResource;
41 import org.xerial.util.Pair;
42 import org.xerial.util.log.Logger;
46 private static Logger _logger = Logger.getLogger(LensTest.class);
49 public void setUp() throws Exception
53 public void tearDown() throws Exception
56 static class GeneTableOneToMany
58 public String trackName;
59 public Map<Coordinate, List<Gene>> sequenceTable;
63 * Example of showing that adder with two arguments corresponds to a
64 * Map<Key, Collection<Value>> parameter.
69 static class GeneTableWithMapAdder
71 private Map<Coordinate, List<Gene>> sequenceTable;
73 @OneToMany(key = "coordinate", value = "gene")
74 public void add(Coordinate coordinate, Gene gene)
76 List<Gene> geneList = sequenceTable.get(coordinate);
79 geneList = new ArrayList<Gene>();
80 sequenceTable.put(coordinate, geneList);
86 static class GeneTableOneToOne
88 public List<Pair<Coordinate, Gene>> geneList;
91 static class GeneTableOneToOneWithAdder
93 public List<Pair<Coordinate, Gene>> geneList;
95 @OneToMany(key = "coordinate", value = "gene")
96 public void add(Coordinate coordinate, Gene gene)
98 geneList.add(Pair.newPair(coordinate, gene));
106 private String strand;
107 private String sequence;
111 public void testTranslateSilk() throws IOException, XerialException
113 GeneTableOneToMany g = Lens.translateSilk(FileResource.find(LensTest.class, "../silk/sequence.silk"),
114 GeneTableOneToMany.class);
117 assertEquals(2, g.sequenceTable.size());
122 public void testMapping() throws Exception
124 Coordinate c = Lens.translateSilk(FileResource.find(SilkUtilTest.class, "../silk/sequence.silk"),
128 assertEquals("utgb", c.group);
129 assertEquals("human", c.species);
130 assertEquals("hg18", c.revision);
131 assertEquals("chr1", c.name);