Skip to content

Commit 4bcab7d

Browse files
committed
GenbankProxySequenceReader throws error if GI is for not protein sequence sequence whereas AminoAcidCompoundSet is declared
added additional test
1 parent a8bc59b commit 4bcab7d

File tree

3 files changed

+66
-10
lines changed

3 files changed

+66
-10
lines changed

biojava-core/src/main/java/org/biojava/nbio/core/sequence/loader/GenbankProxySequenceReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public GenbankProxySequenceReader(
8888
header = genbankParser.getHeader();
8989
features = genbankParser.getFeatures();
9090

91-
if (compoundSet.equals(AminoAcidCompoundSet.class)) {
91+
if (compoundSet.getClass().equals(AminoAcidCompoundSet.class)) {
9292
if (!genbankParser.getCompoundType().equals(compoundSet)) {
9393
logger.error("Declared compount type {} does not mach the real: {}", genbankParser.getCompoundType().toString(), compoundSet.toString());
9494
throw new IOException("Wrong declared compound type for: " + accessionID);

biojava-core/src/test/java/org/biojava/nbio/core/sequence/loader/GenbankProxySequenceReaderTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,10 @@ public static Collection<String[]> getExamples() {
6262
String[][] out = new String[][]{
6363
{"399235158"},
6464
{"7525057"},
65-
{"34567"},
6665
{"379015144"},
6766
{"381353147"},
6867
{"381353148"},
6968
{"152970917"},
70-
{"7856885"},
7169
{"381353149"},
7270
{"254839678"}
7371
};
@@ -87,24 +85,25 @@ public void testFeatures() throws IOException, InterruptedException, CompoundNot
8785
ProteinSequence seq = new ProteinSequence(genbankReader);
8886

8987
Assert.assertNotNull("protein sequence is null", seq);
90-
88+
9189
/*
92-
parse description from header. There is no separate interface/abstract class for method getHeader()
93-
so it should be done here (manualy).
94-
*/
90+
parse description from header. There is no separate interface/abstract class for method getHeader()
91+
so it should be done here (manualy).
92+
*/
9593
genbankReader.getHeaderParser().parseHeader(genbankReader.getHeader(), seq);
96-
94+
9795
// test description
9896
Assert.assertTrue(seq.getDescription() != null);
99-
97+
10098
// test accession Id
10199
logger.info("accession id: {}", seq.getAccession().getID());
102100
Assert.assertNotNull(seq.getAccession().getID());
103101

104102
// test taxonomy id
105103
logger.info("taxonomy id: {}", seq.getTaxonomy().getID());
106104
Assert.assertNotNull(seq.getTaxonomy().getID());
107-
105+
Assert.assertNotNull(Integer.decode(seq.getTaxonomy().getID().split(":")[1]));
106+
108107
// test taxonomy name
109108
String taxonName = seq.getFeaturesByType("source").get(0).getQualifiers().get("organism").getValue();
110109
logger.info("taxonomy name '{}'", taxonName);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* BioJava development code
3+
*
4+
* This code may be freely distributed and modified under the
5+
* terms of the GNU Lesser General Public Licence. This should
6+
* be distributed with the code. If you do not have a copy,
7+
* see:
8+
*
9+
* http://www.gnu.org/copyleft/lesser.html
10+
*
11+
* Copyright for this code is held jointly by the individual
12+
* authors. These should be listed in @author doc comments.
13+
*
14+
* For more information on the BioJava project and its aims,
15+
* or to join the biojava-l mailing list, visit the home page
16+
* at:
17+
*
18+
* http://www.biojava.org/
19+
*
20+
*/
21+
package org.biojava.nbio.core.sequence.loader;
22+
23+
import java.io.IOException;
24+
import org.biojava.nbio.core.sequence.ProteinSequence;
25+
import org.biojava.nbio.core.sequence.compound.AminoAcidCompound;
26+
import org.biojava.nbio.core.sequence.compound.AminoAcidCompoundSet;
27+
import org.junit.Test;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
30+
31+
32+
/**
33+
* Testing example for issue #834
34+
*
35+
* @author Jacek Grzebyta
36+
* @author Paolo Pavan
37+
* @see InfoTask
38+
*/
39+
public class SimpleGenbankProxySequenceReaderTest {
40+
41+
42+
private final static Logger logger = LoggerFactory.getLogger(SimpleGenbankProxySequenceReaderTest.class);
43+
44+
@Test(expected = IOException.class)
45+
public void testWrongSequence() throws Exception {
46+
logger.info("test wrong sequence");
47+
48+
String wrongGi = "34567";
49+
50+
GenbankProxySequenceReader<AminoAcidCompound> genbankReader
51+
= new GenbankProxySequenceReader<AminoAcidCompound>(System.getProperty("java.io.tmpdir"),
52+
wrongGi,
53+
AminoAcidCompoundSet.getAminoAcidCompoundSet());
54+
55+
ProteinSequence seq = new ProteinSequence(genbankReader);
56+
}
57+
}

0 commit comments

Comments
 (0)