Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 17:01:39 GMT
  2. Package jalview.io

File GenBankFileTest.java

 

Code metrics

0
115
2
1
222
151
2
0.02
57.5
2
1

Classes

Class Line # Actions
GenBankFileTest 44 115 2
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.io;
22   
23    import static org.testng.Assert.assertEquals;
24    import static org.testng.Assert.assertTrue;
25    import static org.testng.AssertJUnit.assertNull;
26   
27    import java.io.File;
28    import java.io.IOException;
29    import java.net.MalformedURLException;
30    import java.util.List;
31    import java.util.Set;
32   
33    import org.testng.annotations.BeforeClass;
34    import org.testng.annotations.Test;
35   
36    import jalview.bin.Console;
37    import jalview.datamodel.DBRefEntry;
38    import jalview.datamodel.Mapping;
39    import jalview.datamodel.SequenceFeature;
40    import jalview.datamodel.SequenceI;
41    import jalview.datamodel.features.SequenceFeatures;
42    import jalview.util.MapList;
43   
 
44    public class GenBankFileTest
45    {
 
46  0 toggle @BeforeClass(alwaysRun = true)
47    public void setUp()
48    {
49  0 Console.initLogger();
50    }
51   
52    /**
53    * A fairly tough test, using J03321 (circular DNA), which has 8 CDS features,
54    * one of them reverse strand
55    *
56    * @throws MalformedURLException
57    * @throws IOException
58    */
 
59  0 toggle @Test(groups = "Functional")
60    public void testParse() throws MalformedURLException, IOException
61    {
62  0 File dataFile = new File("test/jalview/io/J03321.gb");
63  0 FileParse fp = new FileParse(dataFile.getAbsolutePath(),
64    DataSourceType.FILE);
65  0 EMBLLikeFlatFile parser = new GenBankFile(fp, "GenBankTest");
66  0 List<SequenceI> seqs = parser.getSeqs();
67   
68  0 assertEquals(seqs.size(), 1);
69  0 SequenceI seq = seqs.get(0);
70  0 assertEquals(seq.getName(), "GenBankTest|J03321");
71  0 assertEquals(seq.getLength(), 7502);
72  0 assertEquals(seq.getDescription(),
73    "Chlamydia trachomatis plasmid pCHL1, complete sequence");
74   
75    /*
76    * should be 9 CDS features (one is a 'join' of two exons)
77    */
78  0 Set<String> featureTypes = seq.getFeatures().getFeatureTypes();
79  0 assertEquals(featureTypes.size(), 1);
80  0 assertTrue(featureTypes.contains("CDS"));
81   
82    /*
83    * inspect some features (sorted just for convenience of test assertions)
84    */
85  0 List<SequenceFeature> features = seq.getFeatures()
86    .getAllFeatures("CDS");
87  0 SequenceFeatures.sortFeatures(features, true);
88  0 assertEquals(features.size(), 9);
89   
90  0 SequenceFeature sf = features.get(0);
91  0 assertEquals(sf.getBegin(), 1);
92  0 assertEquals(sf.getEnd(), 437);
93  0 assertEquals(sf.getDescription(),
94    "Exon 2 for protein EMBLCDS:AAA91567.1");
95  0 assertEquals(sf.getFeatureGroup(), "GenBankTest");
96  0 assertEquals(sf.getEnaLocation(), "join(7022..7502,1..437)");
97  0 assertEquals(sf.getPhase(), "0");
98  0 assertEquals(sf.getStrand(), 1);
99  0 assertEquals(sf.getValue("note"), "pGP7-D");
100    // this is the second exon of circular CDS!
101  0 assertEquals(sf.getValue("exon number"), 2);
102  0 assertEquals(sf.getValue("product"), "hypothetical protein");
103  0 assertEquals(sf.getValue("transl_table"), "11");
104   
105  0 sf = features.get(1);
106  0 assertEquals(sf.getBegin(), 488);
107  0 assertEquals(sf.getEnd(), 1480);
108  0 assertEquals(sf.getDescription(),
109    "Exon 1 for protein EMBLCDS:AAA91568.1");
110  0 assertEquals(sf.getFeatureGroup(), "GenBankTest");
111  0 assertEquals(sf.getEnaLocation(), "complement(488..1480)");
112  0 assertEquals(sf.getPhase(), "0");
113  0 assertEquals(sf.getStrand(), -1); // reverse strand!
114  0 assertEquals(sf.getValue("note"), "pGP8-D");
115  0 assertEquals(sf.getValue("exon number"), 1);
116  0 assertEquals(sf.getValue("product"), "hypothetical protein");
117   
118  0 sf = features.get(7);
119  0 assertEquals(sf.getBegin(), 6045);
120  0 assertEquals(sf.getEnd(), 6788);
121  0 assertEquals(sf.getDescription(),
122    "Exon 1 for protein EMBLCDS:AAA91574.1");
123  0 assertEquals(sf.getFeatureGroup(), "GenBankTest");
124  0 assertEquals(sf.getEnaLocation(), "6045..6788");
125  0 assertEquals(sf.getPhase(), "0");
126  0 assertEquals(sf.getStrand(), 1);
127  0 assertEquals(sf.getValue("note"), "pGP6-D (gtg start codon)");
128  0 assertEquals(sf.getValue("exon number"), 1);
129  0 assertEquals(sf.getValue("product"), "hypothetical protein");
130   
131    /*
132    * CDS at 7022-7502 is the first exon of the circular CDS
133    */
134  0 sf = features.get(8);
135  0 assertEquals(sf.getBegin(), 7022);
136  0 assertEquals(sf.getEnd(), 7502);
137  0 assertEquals(sf.getDescription(),
138    "Exon 1 for protein EMBLCDS:AAA91567.1");
139  0 assertEquals(sf.getFeatureGroup(), "GenBankTest");
140  0 assertEquals(sf.getEnaLocation(), "join(7022..7502,1..437)");
141  0 assertEquals(sf.getPhase(), "0");
142  0 assertEquals(sf.getStrand(), 1);
143  0 assertEquals(sf.getValue("note"), "pGP7-D");
144  0 assertEquals(sf.getValue("exon number"), 1);
145  0 assertEquals(sf.getValue("product"), "hypothetical protein");
146   
147    /*
148    * GenBank doesn't declare accession or CDS xrefs;
149    * dbrefs are added by Jalview for
150    * xref to self : 1
151    * protein products: 8
152    */
153  0 List<DBRefEntry> dbrefs = seq.getDBRefs();
154   
155  0 assertEquals(dbrefs.size(), 9);
156    // xref to 'self':
157  0 DBRefEntry selfRef = new DBRefEntry("GENBANKTEST", "1", "J03321");
158  0 int[] range = new int[] { 1, seq.getLength() };
159  0 selfRef.setMap(new Mapping(null, range, range, 1, 1));
160  0 assertTrue(dbrefs.contains(selfRef));
161   
162    /*
163    * dna should have dbref to itself, and to EMBLCDSPROTEIN
164    * for each /protein_id (synthesized as no UNIPROT xref)
165    */
166    // TODO check if we should synthesize EMBLCDSPROTEIN dbrefs
167  0 DBRefEntry dbref = dbrefs.get(0);
168  0 assertEquals(dbref.getSource(), "GENBANKTEST");
169  0 assertEquals(dbref.getAccessionId(), "J03321");
170  0 Mapping mapping = dbref.getMap();
171  0 assertNull(mapping.getTo());
172  0 MapList map = mapping.getMap();
173  0 assertEquals(map.getFromLowest(), 1);
174  0 assertEquals(map.getFromHighest(), 7502);
175  0 assertEquals(map.getToLowest(), 1);
176  0 assertEquals(map.getToHighest(), 7502);
177  0 assertEquals(map.getFromRatio(), 1);
178  0 assertEquals(map.getToRatio(), 1);
179   
180    // dbref to inferred EMBLCDSPROTEIN for first CDS
181  0 dbref = dbrefs.get(1);
182  0 assertEquals(dbref.getSource(), "EMBLCDSPROTEIN");
183  0 assertEquals(dbref.getAccessionId(), "AAA91567.1");
184  0 mapping = dbref.getMap();
185  0 SequenceI mapTo = mapping.getTo();
186  0 assertEquals(mapTo.getName(), "AAA91567.1");
187    // the /product qualifier transfers to protein product description
188  0 assertEquals(mapTo.getDescription(), "hypothetical protein");
189  0 String seqString = mapTo.getSequenceAsString();
190  0 assertEquals(seqString.length(), 305);
191  0 assertTrue(seqString.startsWith("MGSMAF"));
192  0 assertTrue(seqString.endsWith("QTPTIL"));
193  0 map = mapping.getMap();
194  0 assertEquals(map.getFromLowest(), 1);
195  0 assertEquals(map.getFromHighest(), 7502);
196  0 assertEquals(map.getToLowest(), 1);
197  0 assertEquals(map.getToHighest(), 305);
198  0 assertEquals(map.getFromRatio(), 3);
199  0 assertEquals(map.getToRatio(), 1);
200   
201    // dbref to inferred EMBLCDSPROTEIN for last CDS
202  0 dbref = dbrefs.get(8);
203  0 assertEquals(dbref.getSource(), "EMBLCDSPROTEIN");
204  0 assertEquals(dbref.getAccessionId(), "AAA91574.1");
205  0 mapping = dbref.getMap();
206  0 mapTo = mapping.getTo();
207  0 assertEquals(mapTo.getName(), "AAA91574.1");
208    // the /product qualifier transfers to protein product description
209  0 assertEquals(mapTo.getDescription(), "hypothetical protein");
210  0 seqString = mapTo.getSequenceAsString();
211  0 assertEquals(seqString.length(), 247);
212  0 assertTrue(seqString.startsWith("MNKLK"));
213  0 assertTrue(seqString.endsWith("FKQKS"));
214  0 map = mapping.getMap();
215  0 assertEquals(map.getFromLowest(), 6045);
216  0 assertEquals(map.getFromHighest(), 6785); // excludes stop at 6788
217  0 assertEquals(map.getToLowest(), 1);
218  0 assertEquals(map.getToHighest(), 247);
219  0 assertEquals(map.getFromRatio(), 3);
220  0 assertEquals(map.getToRatio(), 1);
221    }
222    }