Clover icon

Coverage Report

  1. Project Clover database Mon Sep 2 2024 17:57:51 BST
  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
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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  1 toggle @BeforeClass(alwaysRun = true)
47    public void setUp()
48    {
49  1 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  1 toggle @Test(groups = "Functional")
60    public void testParse() throws MalformedURLException, IOException
61    {
62  1 File dataFile = new File("test/jalview/io/J03321.gb");
63  1 FileParse fp = new FileParse(dataFile.getAbsolutePath(),
64    DataSourceType.FILE);
65  1 EMBLLikeFlatFile parser = new GenBankFile(fp, "GenBankTest");
66  1 List<SequenceI> seqs = parser.getSeqs();
67   
68  1 assertEquals(seqs.size(), 1);
69  1 SequenceI seq = seqs.get(0);
70  1 assertEquals(seq.getName(), "GenBankTest|J03321");
71  1 assertEquals(seq.getLength(), 7502);
72  1 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  1 Set<String> featureTypes = seq.getFeatures().getFeatureTypes();
79  1 assertEquals(featureTypes.size(), 1);
80  1 assertTrue(featureTypes.contains("CDS"));
81   
82    /*
83    * inspect some features (sorted just for convenience of test assertions)
84    */
85  1 List<SequenceFeature> features = seq.getFeatures()
86    .getAllFeatures("CDS");
87  1 SequenceFeatures.sortFeatures(features, true);
88  1 assertEquals(features.size(), 9);
89   
90  1 SequenceFeature sf = features.get(0);
91  1 assertEquals(sf.getBegin(), 1);
92  1 assertEquals(sf.getEnd(), 437);
93  1 assertEquals(sf.getDescription(),
94    "Exon 2 for protein EMBLCDS:AAA91567.1");
95  1 assertEquals(sf.getFeatureGroup(), "GenBankTest");
96  1 assertEquals(sf.getEnaLocation(), "join(7022..7502,1..437)");
97  1 assertEquals(sf.getPhase(), "0");
98  1 assertEquals(sf.getStrand(), 1);
99  1 assertEquals(sf.getValue("note"), "pGP7-D");
100    // this is the second exon of circular CDS!
101  1 assertEquals(sf.getValue("exon number"), 2);
102  1 assertEquals(sf.getValue("product"), "hypothetical protein");
103  1 assertEquals(sf.getValue("transl_table"), "11");
104   
105  1 sf = features.get(1);
106  1 assertEquals(sf.getBegin(), 488);
107  1 assertEquals(sf.getEnd(), 1480);
108  1 assertEquals(sf.getDescription(),
109    "Exon 1 for protein EMBLCDS:AAA91568.1");
110  1 assertEquals(sf.getFeatureGroup(), "GenBankTest");
111  1 assertEquals(sf.getEnaLocation(), "complement(488..1480)");
112  1 assertEquals(sf.getPhase(), "0");
113  1 assertEquals(sf.getStrand(), -1); // reverse strand!
114  1 assertEquals(sf.getValue("note"), "pGP8-D");
115  1 assertEquals(sf.getValue("exon number"), 1);
116  1 assertEquals(sf.getValue("product"), "hypothetical protein");
117   
118  1 sf = features.get(7);
119  1 assertEquals(sf.getBegin(), 6045);
120  1 assertEquals(sf.getEnd(), 6788);
121  1 assertEquals(sf.getDescription(),
122    "Exon 1 for protein EMBLCDS:AAA91574.1");
123  1 assertEquals(sf.getFeatureGroup(), "GenBankTest");
124  1 assertEquals(sf.getEnaLocation(), "6045..6788");
125  1 assertEquals(sf.getPhase(), "0");
126  1 assertEquals(sf.getStrand(), 1);
127  1 assertEquals(sf.getValue("note"), "pGP6-D (gtg start codon)");
128  1 assertEquals(sf.getValue("exon number"), 1);
129  1 assertEquals(sf.getValue("product"), "hypothetical protein");
130   
131    /*
132    * CDS at 7022-7502 is the first exon of the circular CDS
133    */
134  1 sf = features.get(8);
135  1 assertEquals(sf.getBegin(), 7022);
136  1 assertEquals(sf.getEnd(), 7502);
137  1 assertEquals(sf.getDescription(),
138    "Exon 1 for protein EMBLCDS:AAA91567.1");
139  1 assertEquals(sf.getFeatureGroup(), "GenBankTest");
140  1 assertEquals(sf.getEnaLocation(), "join(7022..7502,1..437)");
141  1 assertEquals(sf.getPhase(), "0");
142  1 assertEquals(sf.getStrand(), 1);
143  1 assertEquals(sf.getValue("note"), "pGP7-D");
144  1 assertEquals(sf.getValue("exon number"), 1);
145  1 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  1 List<DBRefEntry> dbrefs = seq.getDBRefs();
154   
155  1 assertEquals(dbrefs.size(), 9);
156    // xref to 'self':
157  1 DBRefEntry selfRef = new DBRefEntry("GENBANKTEST", "1", "J03321");
158  1 int[] range = new int[] { 1, seq.getLength() };
159  1 selfRef.setMap(new Mapping(null, range, range, 1, 1));
160  1 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  1 DBRefEntry dbref = dbrefs.get(0);
168  1 assertEquals(dbref.getSource(), "GENBANKTEST");
169  1 assertEquals(dbref.getAccessionId(), "J03321");
170  1 Mapping mapping = dbref.getMap();
171  1 assertNull(mapping.getTo());
172  1 MapList map = mapping.getMap();
173  1 assertEquals(map.getFromLowest(), 1);
174  1 assertEquals(map.getFromHighest(), 7502);
175  1 assertEquals(map.getToLowest(), 1);
176  1 assertEquals(map.getToHighest(), 7502);
177  1 assertEquals(map.getFromRatio(), 1);
178  1 assertEquals(map.getToRatio(), 1);
179   
180    // dbref to inferred EMBLCDSPROTEIN for first CDS
181  1 dbref = dbrefs.get(1);
182  1 assertEquals(dbref.getSource(), "EMBLCDSPROTEIN");
183  1 assertEquals(dbref.getAccessionId(), "AAA91567.1");
184  1 mapping = dbref.getMap();
185  1 SequenceI mapTo = mapping.getTo();
186  1 assertEquals(mapTo.getName(), "AAA91567.1");
187    // the /product qualifier transfers to protein product description
188  1 assertEquals(mapTo.getDescription(), "hypothetical protein");
189  1 String seqString = mapTo.getSequenceAsString();
190  1 assertEquals(seqString.length(), 305);
191  1 assertTrue(seqString.startsWith("MGSMAF"));
192  1 assertTrue(seqString.endsWith("QTPTIL"));
193  1 map = mapping.getMap();
194  1 assertEquals(map.getFromLowest(), 1);
195  1 assertEquals(map.getFromHighest(), 7502);
196  1 assertEquals(map.getToLowest(), 1);
197  1 assertEquals(map.getToHighest(), 305);
198  1 assertEquals(map.getFromRatio(), 3);
199  1 assertEquals(map.getToRatio(), 1);
200   
201    // dbref to inferred EMBLCDSPROTEIN for last CDS
202  1 dbref = dbrefs.get(8);
203  1 assertEquals(dbref.getSource(), "EMBLCDSPROTEIN");
204  1 assertEquals(dbref.getAccessionId(), "AAA91574.1");
205  1 mapping = dbref.getMap();
206  1 mapTo = mapping.getTo();
207  1 assertEquals(mapTo.getName(), "AAA91574.1");
208    // the /product qualifier transfers to protein product description
209  1 assertEquals(mapTo.getDescription(), "hypothetical protein");
210  1 seqString = mapTo.getSequenceAsString();
211  1 assertEquals(seqString.length(), 247);
212  1 assertTrue(seqString.startsWith("MNKLK"));
213  1 assertTrue(seqString.endsWith("FKQKS"));
214  1 map = mapping.getMap();
215  1 assertEquals(map.getFromLowest(), 6045);
216  1 assertEquals(map.getFromHighest(), 6785); // excludes stop at 6788
217  1 assertEquals(map.getToLowest(), 1);
218  1 assertEquals(map.getToHighest(), 247);
219  1 assertEquals(map.getFromRatio(), 3);
220  1 assertEquals(map.getToRatio(), 1);
221    }
222    }