Skip to content

Commit b648835

Browse files
committed
test defaultAAIndexProvider
1 parent d303a16 commit b648835

3 files changed

Lines changed: 34 additions & 6 deletions

File tree

biojava-core/src/main/java/org/biojava/nbio/core/alignment/matrices/AAIndexProvider.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,11 @@
2626

2727
public interface AAIndexProvider {
2828

29-
public SubstitutionMatrix<AminoAcidCompound> getMatrix(String matrixName);
29+
/**
30+
* Gets a substitution matrix by its name. The matrices are defined in
31+
{@code}src/main/resources/matrices/AAINDEX.txt{@code}
32+
* @param matrixName
33+
* @return The @{code}SubstitutionMatrix{@code} or null if not exists
34+
*/
35+
SubstitutionMatrix<AminoAcidCompound> getMatrix(String matrixName);
3036
}

biojava-core/src/main/java/org/biojava/nbio/core/alignment/matrices/DefaultAAIndexProvider.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ public class DefaultAAIndexProvider implements AAIndexProvider {
4242

4343
public DefaultAAIndexProvider(){
4444

45-
4645
InputStream inStream = getInputStreamToAAindexFile();
47-
4846
AAIndexFileParser parser = new AAIndexFileParser();
4947

5048
try {
@@ -54,14 +52,11 @@ public DefaultAAIndexProvider(){
5452
}
5553

5654
matrices = parser.getMatrices();
57-
5855
}
5956

6057
@Override
6158
public SubstitutionMatrix<AminoAcidCompound> getMatrix(String matrixName) {
62-
6359
return matrices.get(matrixName);
64-
6560
}
6661

6762
public InputStream getInputStreamToAAindexFile(){
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.biojava.nbio.core.alignment.matrices;
2+
3+
import org.biojava.nbio.core.alignment.template.SubstitutionMatrix;
4+
import org.biojava.nbio.core.sequence.compound.AminoAcidCompound;
5+
import org.biojava.nbio.core.sequence.compound.AminoAcidCompoundSet;
6+
import org.biojava.nbio.core.sequence.compound.NucleotideCompound;
7+
import org.junit.jupiter.api.Test;
8+
9+
import static org.junit.jupiter.api.Assertions.*;
10+
11+
class DefaultAAIndexProviderTest {
12+
13+
private static final String BENS940102 = "BENS940102";
14+
15+
DefaultAAIndexProvider provider = new DefaultAAIndexProvider();
16+
@Test
17+
void newAAIndexProviderReturnsNullIfNotExists(){
18+
assertNull(provider.getMatrix("unknown"));
19+
}
20+
21+
@Test
22+
void aaIndexProviderGetByName(){
23+
SubstitutionMatrix<AminoAcidCompound> matrix = provider.getMatrix(BENS940102);
24+
assertNotNull(matrix);
25+
assertEquals(BENS940102, matrix.getName());
26+
}
27+
}

0 commit comments

Comments
 (0)