Skip to content

Commit 5abdc77

Browse files
committed
add CDS>>'coded_by' test for simple example
1 parent 9d5f452 commit 5abdc77

2 files changed

Lines changed: 101 additions & 69 deletions

File tree

biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/GenbankReaderTest.java

Lines changed: 88 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -35,70 +35,102 @@
3535
import org.slf4j.LoggerFactory;
3636

3737
import java.io.InputStream;
38+
import java.util.ArrayList;
3839
import java.util.LinkedHashMap;
40+
import org.biojava.nbio.core.sequence.features.FeatureInterface;
41+
import org.biojava.nbio.core.sequence.template.AbstractSequence;
3942

4043
import static org.junit.Assert.assertNotNull;
4144

4245
/**
4346
*
4447
* @author Scooter Willis <willishf at gmail dot com>
48+
* @author Jacek Grzebyta
4549
*/
4650
public class GenbankReaderTest {
4751

48-
private final static Logger logger = LoggerFactory.getLogger(GenbankReaderTest.class);
49-
50-
public GenbankReaderTest() {
51-
}
52-
53-
@BeforeClass
54-
public static void setUpClass() throws Exception {
55-
}
56-
57-
@AfterClass
58-
public static void tearDownClass() throws Exception {
59-
}
60-
61-
@Before
62-
public void setUp() {
63-
}
64-
65-
@After
66-
public void tearDown() {
67-
}
68-
69-
/**
70-
* Test of process method, of class GenbankReader.
71-
*/
72-
@Test
73-
public void testProcess() throws Exception {
74-
75-
logger.info("process protein");
76-
InputStream inStream = this.getClass().getResourceAsStream("/BondFeature.gb");
77-
assertNotNull(inStream);
78-
79-
GenbankReader<ProteinSequence,AminoAcidCompound> GenbankProtein =
80-
new GenbankReader<ProteinSequence,AminoAcidCompound>(
81-
inStream,
82-
new GenericGenbankHeaderParser<ProteinSequence,AminoAcidCompound>(),
83-
new ProteinSequenceCreator(AminoAcidCompoundSet.getAminoAcidCompoundSet())
84-
);
85-
@SuppressWarnings("unused")
86-
LinkedHashMap<String,ProteinSequence> proteinSequences = GenbankProtein.process();
87-
inStream.close();
88-
89-
logger.info("process DNA");
90-
inStream = this.getClass().getResourceAsStream("/NM_000266.gb");
91-
assertNotNull(inStream);
92-
93-
GenbankReader<DNASequence,NucleotideCompound> GenbankDNA =
94-
new GenbankReader<DNASequence,NucleotideCompound>(
95-
inStream,
96-
new GenericGenbankHeaderParser<DNASequence,NucleotideCompound>(),
97-
new DNASequenceCreator(DNACompoundSet.getDNACompoundSet())
98-
);
99-
@SuppressWarnings("unused")
100-
LinkedHashMap<String,DNASequence> dnaSequences = GenbankDNA.process();
101-
inStream.close();
102-
}
103-
52+
private final static Logger logger = LoggerFactory.getLogger(GenbankReaderTest.class);
53+
54+
public GenbankReaderTest() {
55+
}
56+
57+
@BeforeClass
58+
public static void setUpClass() throws Exception {
59+
}
60+
61+
@AfterClass
62+
public static void tearDownClass() throws Exception {
63+
}
64+
65+
@Before
66+
public void setUp() {
67+
}
68+
69+
@After
70+
public void tearDown() {
71+
}
72+
73+
/**
74+
* Test of process method, of class GenbankReader.
75+
*/
76+
@Test
77+
public void testProcess() throws Exception {
78+
79+
logger.info("process protein");
80+
InputStream inStream = this.getClass().getResourceAsStream("/BondFeature.gb");
81+
assertNotNull(inStream);
82+
83+
GenbankReader<ProteinSequence, AminoAcidCompound> GenbankProtein
84+
= new GenbankReader<ProteinSequence, AminoAcidCompound>(
85+
inStream,
86+
new GenericGenbankHeaderParser<ProteinSequence, AminoAcidCompound>(),
87+
new ProteinSequenceCreator(AminoAcidCompoundSet.getAminoAcidCompoundSet())
88+
);
89+
@SuppressWarnings("unused")
90+
LinkedHashMap<String, ProteinSequence> proteinSequences = GenbankProtein.process();
91+
inStream.close();
92+
93+
logger.info("process DNA");
94+
inStream = this.getClass().getResourceAsStream("/NM_000266.gb");
95+
assertNotNull(inStream);
96+
97+
GenbankReader<DNASequence, NucleotideCompound> GenbankDNA
98+
= new GenbankReader<DNASequence, NucleotideCompound>(
99+
inStream,
100+
new GenericGenbankHeaderParser<DNASequence, NucleotideCompound>(),
101+
new DNASequenceCreator(DNACompoundSet.getDNACompoundSet())
102+
);
103+
@SuppressWarnings("unused")
104+
LinkedHashMap<String, DNASequence> dnaSequences = GenbankDNA.process();
105+
inStream.close();
106+
}
107+
108+
@Test
109+
public void CDStest() throws Exception {
110+
logger.info("CDS test");
111+
112+
InputStream inStream = this.getClass().getResourceAsStream("/BondFeature.gb");
113+
assertNotNull(inStream);
114+
115+
GenbankReader<ProteinSequence, AminoAcidCompound> GenbankProtein
116+
= new GenbankReader<ProteinSequence, AminoAcidCompound>(
117+
inStream,
118+
new GenericGenbankHeaderParser<ProteinSequence, AminoAcidCompound>(),
119+
new ProteinSequenceCreator(AminoAcidCompoundSet.getAminoAcidCompoundSet())
120+
);
121+
@SuppressWarnings("unused")
122+
LinkedHashMap<String, ProteinSequence> proteinSequences = GenbankProtein.process();
123+
inStream.close();
124+
125+
Assert.assertTrue(proteinSequences.size() == 1);
126+
logger.info("protein sequences: {}", proteinSequences);
127+
128+
ProteinSequence protein = new ArrayList<ProteinSequence>(proteinSequences.values()).get(0);
129+
130+
FeatureInterface<AbstractSequence<AminoAcidCompound>, AminoAcidCompound> cdsFeature = protein.getFeaturesByType("CDS").get(0);
131+
String codedBy = cdsFeature.getQualifiers().get("coded_by").getValue();
132+
Assert.assertNotNull(codedBy);
133+
Assert.assertTrue(!codedBy.isEmpty());
134+
}
135+
104136
}

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import java.io.IOException;
3737
import java.util.Arrays;
3838
import java.util.Collection;
39-
import java.util.List;
4039

4140
/**
4241
* Testing example for issue #834
@@ -74,34 +73,35 @@ public static Collection<String[]> getExamples() {
7473
}
7574

7675
@Test
77-
public void biojava3() throws IOException, InterruptedException, CompoundNotFoundException {
76+
public void biojava3() throws IOException, InterruptedException, CompoundNotFoundException {
7877
logger.info("run test for protein: {}", gi);
7978
GenbankProxySequenceReader<AminoAcidCompound> genbankReader
80-
= new GenbankProxySequenceReader<AminoAcidCompound>(System.getProperty("java.io.tmpdir"),
81-
this.gi,
82-
AminoAcidCompoundSet.getAminoAcidCompoundSet());
79+
= new GenbankProxySequenceReader<AminoAcidCompound>(System.getProperty("java.io.tmpdir"),
80+
this.gi,
81+
AminoAcidCompoundSet.getAminoAcidCompoundSet());
8382

8483
// why only tests on protein sequences?
8584
ProteinSequence seq = new ProteinSequence(genbankReader, AminoAcidCompoundSet.getAminoAcidCompoundSet());
8685

8786
Assert.assertNotNull("protein sequence is null", seq);
8887
genbankReader.getHeaderParser().parseHeader(genbankReader.getHeader(), seq);
89-
88+
9089
Assert.assertTrue(seq.getDescription() != null);
9190

9291
Assert.assertFalse(seq.getFeaturesKeyWord().getKeyWords().isEmpty());
9392
Assert.assertFalse(seq.getFeaturesByType("source").get(0).getSource().isEmpty());
94-
93+
9594
logger.info("taxonomy id: {}", seq.getTaxonomy().getID());
9695
Assert.assertNotNull(seq.getTaxonomy().getID());
9796
Assert.assertNotNull(seq.getSequenceAsString());
98-
99-
100-
List<FeatureInterface<AbstractSequence<AminoAcidCompound>, AminoAcidCompound>> codedBy = seq.getFeaturesByType("coded_by");
10197

102-
if (!codedBy.isEmpty()) {
103-
// get parent DNA
104-
Assert.assertNotNull(seq.getParentSequence().getSequenceAsString() != null);
98+
if (seq.getFeaturesByType("CDS").size() > 0) {
99+
FeatureInterface<AbstractSequence<AminoAcidCompound>, AminoAcidCompound> CDS = seq.getFeaturesByType("CDS").get(0);
100+
logger.info("CDS: {}", CDS);
101+
String codedBy = CDS.getQualifiers().get("coded_by").getValue();
102+
Assert.assertNotNull(codedBy);
103+
Assert.assertTrue(!codedBy.isEmpty());
104+
logger.info("\t\tcoded_by: {}", codedBy);
105105
}
106106
}
107107
}

0 commit comments

Comments
 (0)