OSDN Git Service

git-svn-id: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core@3022 ae02f08e...
[xerial/xerial-core.git] / src / test / java / org / xerial / lens / LensTest.java
1 /*--------------------------------------------------------------------------
2  *  Copyright 2009 Taro L. Saito
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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 //--------------------------------------
17 // XerialJ
18 //
19 // LensTest.java
20 // Since: Feb 23, 2009 6:02:27 PM
21 //
22 // $URL$
23 // $Author$
24 //--------------------------------------
25 package org.xerial.lens;
26
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNotNull;
29
30 import java.io.IOException;
31 import java.util.ArrayList;
32 import java.util.List;
33 import java.util.Map;
34
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;
43
44 public class LensTest
45 {
46     private static Logger _logger = Logger.getLogger(LensTest.class);
47
48     @Before
49     public void setUp() throws Exception
50     {}
51
52     @After
53     public void tearDown() throws Exception
54     {}
55
56     static class GeneTableOneToMany
57     {
58         public String trackName;
59         public Map<Coordinate, List<Gene>> sequenceTable;
60     }
61
62     /**
63      * Example of showing that adder with two arguments corresponds to a
64      * Map<Key, Collection<Value>> parameter.
65      * 
66      * @author leo
67      * 
68      */
69     static class GeneTableWithMapAdder
70     {
71         private Map<Coordinate, List<Gene>> sequenceTable;
72
73         @OneToMany(key = "coordinate", value = "gene")
74         public void add(Coordinate coordinate, Gene gene)
75         {
76             List<Gene> geneList = sequenceTable.get(coordinate);
77             if (geneList == null)
78             {
79                 geneList = new ArrayList<Gene>();
80                 sequenceTable.put(coordinate, geneList);
81             }
82             geneList.add(gene);
83         }
84     }
85
86     static class GeneTableOneToOne
87     {
88         public List<Pair<Coordinate, Gene>> geneList;
89     }
90
91     static class GeneTableOneToOneWithAdder
92     {
93         public List<Pair<Coordinate, Gene>> geneList;
94
95         @OneToMany(key = "coordinate", value = "gene")
96         public void add(Coordinate coordinate, Gene gene)
97         {
98             geneList.add(Pair.newPair(coordinate, gene));
99         }
100     }
101
102     static class Gene
103     {
104         private String name;
105         private long start;
106         private String strand;
107         private String sequence;
108     }
109
110     @Test
111     public void testTranslateSilk() throws IOException, XerialException
112     {
113         GeneTableOneToMany g = Lens.translateSilk(FileResource.find(LensTest.class, "../silk/sequence.silk"),
114                 GeneTableOneToMany.class);
115
116         assertNotNull(g);
117         assertEquals(2, g.sequenceTable.size());
118
119     }
120
121     @Test
122     public void testMapping() throws Exception
123     {
124         Coordinate c = Lens.translateSilk(FileResource.find(SilkUtilTest.class, "../silk/sequence.silk"),
125                 Coordinate.class);
126         _logger.info(c);
127         assertNotNull(c);
128         assertEquals("utgb", c.group);
129         assertEquals("human", c.species);
130         assertEquals("hg18", c.revision);
131         assertEquals("chr1", c.name);
132
133     }
134 }