Skip to content

Commit cff87dd

Browse files
committed
initialise sequrnce storage, throwing IAE
1 parent 451b559 commit cff87dd

File tree

8 files changed

+48
-15
lines changed

8 files changed

+48
-15
lines changed

biojava-core/src/main/java/org/biojava/nbio/core/sequence/CDSSequence.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package org.biojava.nbio.core.sequence;
2424

2525

26+
import org.biojava.nbio.core.exceptions.CompoundNotFoundException;
2627
import org.biojava.nbio.core.sequence.compound.DNACompoundSet;
2728
import org.biojava.nbio.core.sequence.compound.NucleotideCompound;
2829
import org.biojava.nbio.core.sequence.template.CompoundSet;
@@ -46,8 +47,15 @@ public class CDSSequence extends DNASequence {
4647
* @param bioBegin
4748
* @param bioEnd
4849
* @param phase
50+
* @throws IllegalArgumentException if parentSequence is incompatible with DNACompoundSet
4951
*/
5052
public CDSSequence(TranscriptSequence parentSequence, int bioBegin, int bioEnd, int phase) {
53+
setCompoundSet(DNACompoundSet.getDNACompoundSet());
54+
try {
55+
initSequenceStorage(parentSequence.getSequenceAsString());
56+
} catch (CompoundNotFoundException e) {
57+
throw new IllegalArgumentException(e);
58+
}
5159
parentTranscriptSequence = parentSequence;
5260
this.setParentSequence(parentTranscriptSequence);
5361
setBioBegin(bioBegin);

biojava-core/src/main/java/org/biojava/nbio/core/sequence/ExonSequence.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
*/
2323
package org.biojava.nbio.core.sequence;
2424

25+
import org.biojava.nbio.core.exceptions.CompoundNotFoundException;
26+
import org.biojava.nbio.core.sequence.compound.DNACompoundSet;
27+
2528
/**
2629
* A gene contains a collection of Exon sequences
2730
* @author Scooter Willis
@@ -41,6 +44,12 @@ public class ExonSequence extends DNASequence {
4144
* @param bioEnd
4245
*/
4346
public ExonSequence(GeneSequence parentGeneSequence, int bioBegin, int bioEnd) {
47+
setCompoundSet(DNACompoundSet.getDNACompoundSet());
48+
try {
49+
initSequenceStorage(parentGeneSequence.getSequenceAsString());
50+
} catch (CompoundNotFoundException e) {
51+
throw new IllegalArgumentException(e);
52+
}
4453
this.setParentSequence(parentGeneSequence);
4554
setBioBegin(bioBegin);
4655
setBioEnd(bioEnd);

biojava-core/src/main/java/org/biojava/nbio/core/sequence/GeneSequence.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,18 @@ public class GeneSequence extends DNASequence {
6565
* @param end inclusive of end
6666
* @param strand force a gene to have strand and transcription sequence will inherit
6767
*/
68-
public GeneSequence(ChromosomeSequence parentSequence, int begin, int end, Strand strand) {
68+
public GeneSequence(ChromosomeSequence parentSequence, int begin, int end, Strand strand) {
69+
setCompoundSet(DNACompoundSet.getDNACompoundSet());
70+
try {
71+
initSequenceStorage(parentSequence.getSequenceAsString());
72+
} catch (CompoundNotFoundException e) {
73+
throw new IllegalArgumentException(e);
74+
}
6975
chromosomeSequence = parentSequence;
7076
setParentSequence(parentSequence);
7177
setBioBegin(begin);
7278
setBioEnd(end);
7379
setStrand(strand);
74-
this.setCompoundSet(DNACompoundSet.getDNACompoundSet());
7580
}
7681

7782
/**

biojava-core/src/main/java/org/biojava/nbio/core/sequence/TranscriptSequence.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,19 @@ public class TranscriptSequence extends DNASequence {
5252
* @param parentDNASequence
5353
* @param begin
5454
* @param end inclusive of end
55+
* @throws IllegalArgumentException if the parentDNASequence is incompatible with DNACompoundSet
5556
*/
5657
public TranscriptSequence(GeneSequence parentDNASequence, int begin, int end) {
58+
setCompoundSet(DNACompoundSet.getDNACompoundSet());
59+
try {
60+
initSequenceStorage(parentDNASequence.getSequenceAsString());
61+
} catch (CompoundNotFoundException e) {
62+
throw new IllegalArgumentException(e);
63+
}
5764
setParentSequence(parentDNASequence);
5865
this.parentGeneSequence = parentDNASequence;
5966
setBioBegin(begin);
6067
setBioEnd(end);
61-
this.setCompoundSet(DNACompoundSet.getDNACompoundSet());
6268
}
6369

6470
@Override

biojava-core/src/main/java/org/biojava/nbio/core/sequence/template/AbstractSequence.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ public AbstractSequence() {
8888
*/
8989
public AbstractSequence(String seqString, CompoundSet<C> compoundSet) throws CompoundNotFoundException {
9090
setCompoundSet(compoundSet);
91+
initSequenceStorage(seqString);
92+
}
93+
94+
// so it can be called from subclass constructors
95+
protected void initSequenceStorage(String seqString) throws CompoundNotFoundException {
9196
sequenceStorage = new ArrayListSequenceReader<C>();
9297
sequenceStorage.setCompoundSet(this.getCompoundSet());
9398
sequenceStorage.setContents(seqString);

biojava-core/src/test/java/org/biojava/nbio/core/sequence/ExonSequenceTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ void createExon() throws CompoundNotFoundException {
1616
}
1717

1818
@Test
19-
@Disabled("getAsList throws NPE in AbstractSequence#equals")
20-
void equalsAndHaschcode() throws CompoundNotFoundException {
19+
void equalsAndHashcode() throws CompoundNotFoundException {
2120
GeneSequence gene = anyGeneSequence();
2221
ExonSequence es = new ExonSequence(gene, 30, 40);
2322
ExonSequence es2 = new ExonSequence(gene, 30, 40);

biojava-core/src/test/java/org/biojava/nbio/core/sequence/GeneSequenceTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,9 @@ void addRemoveExon() throws Exception {
113113
assertEquals(2, geneSequence.getExonSequences().size());
114114
geneSequence.removeExon("unknown");
115115
assertEquals(2, geneSequence.getExonSequences().size());
116-
// this causes NPE in equals() methods as sequence proxy loader isn't set.
117-
// either call super constructor in GeneSequence (which will require adding exception)
118-
// or alter equals() in AbstractSequence not to use properties like sequenceStorage, that may be null.
119-
// geneSequence.removeExon("b");
120-
// assertEquals(1, geneSequence.getExonSequences().size());
116+
117+
geneSequence.removeExon("c");
118+
assertEquals(1, geneSequence.getExonSequences().size());
121119
}
122120

123121
@Test

biojava-core/src/test/java/org/biojava/nbio/core/sequence/TranscriptSequenceTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,19 @@ void CDSListIsEmpty() {
4242
}
4343

4444
@Test
45-
@Disabled("NPE thrown from AbstractSequence 'getAsList'")
45+
// whether it's -ve or +ve doesn't affect equals?
4646
void equals() {
47-
assertFalse(transcriptSeq.equals(transcriptNegativeSeq));
47+
assertTrue(transcriptSeq.equals(transcriptSeq));
48+
}
49+
50+
// whether it's -ve or +ve doesn't affect equals?
51+
void equalsDoesntDependOnStrand() {
52+
assertTrue(transcriptSeq.equals(transcriptNegativeSeq));
4853
}
4954

5055
@Test
51-
@Disabled("NPE thrown from AbstractSequence 'getAsList'")
5256
void hashcode() {
53-
assertFalse(transcriptSeq.hashCode() == (transcriptNegativeSeq.hashCode()));
57+
assertTrue(transcriptSeq.hashCode() == (transcriptNegativeSeq.hashCode()));
5458
}
5559
}
5660

@@ -89,7 +93,6 @@ void getCDNASeqNegativeStrand() throws Exception {
8993
}
9094

9195
@Test
92-
@Disabled("Can't remove, as NPE thrown from equals()")
9396
void removeCDS() throws Exception {
9497
transcriptSeq.addCDS(new AccessionID("a"), 50, 60, 1);
9598
assertEquals(1, transcriptSeq.getCDSSequences().size());

0 commit comments

Comments
 (0)