Skip to content

Commit 5210929

Browse files
committed
for the fix for biojava#91 to work I believe we need to be more careful with CompoundSets
1 parent 75ff1ab commit 5210929

4 files changed

Lines changed: 24 additions & 4 deletions

File tree

biojava3-core/src/main/java/org/biojava3/core/sequence/CDSSequence.java

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

2525

26+
import org.biojava3.core.sequence.compound.DNACompoundSet;
2627
import org.biojava3.core.sequence.compound.NucleotideCompound;
2728
import org.biojava3.core.sequence.template.CompoundSet;
2829

@@ -52,6 +53,7 @@ public CDSSequence(TranscriptSequence parentSequence, int bioBegin, int bioEnd,
5253
setBioBegin(bioBegin);
5354
setBioEnd(bioEnd);
5455
this.phase = phase;
56+
this.setCompoundSet(DNACompoundSet.getDNACompoundSet());
5557

5658
}
5759

@@ -86,6 +88,7 @@ public Strand getStrand() {
8688
*/
8789
public String getCodingSequence() {
8890
String sequence = this.getSequenceAsString(getBioBegin(), getBioEnd(), getStrand());
91+
8992
if (getStrand() == Strand.NEGATIVE) {
9093
//need to take complement of sequence because it is negative and we are returning a coding sequence
9194
StringBuilder b = new StringBuilder(getLength());

biojava3-core/src/main/java/org/biojava3/core/sequence/GeneSequence.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.util.Collections;
2727
import java.util.LinkedHashMap;
2828
import java.util.logging.Logger;
29+
30+
import org.biojava3.core.sequence.compound.DNACompoundSet;
2931
import org.biojava3.core.sequence.compound.NucleotideCompound;
3032
import org.biojava3.core.sequence.template.CompoundSet;
3133

@@ -66,6 +68,7 @@ public GeneSequence(ChromosomeSequence parentSequence, int begin, int end, Stran
6668
setBioBegin(begin);
6769
setBioEnd(end);
6870
setStrand(strand);
71+
this.setCompoundSet(DNACompoundSet.getDNACompoundSet());
6972
}
7073

7174
/**

biojava3-core/src/main/java/org/biojava3/core/sequence/TranscriptSequence.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Collections;
2727
import java.util.LinkedHashMap;
2828

29+
import org.biojava3.core.sequence.compound.DNACompoundSet;
2930
import org.biojava3.core.sequence.transcription.TranscriptionEngine;
3031

3132
/**
@@ -52,6 +53,7 @@ public TranscriptSequence(GeneSequence parentDNASequence, int begin, int end) {
5253
this.parentGeneSequence = parentDNASequence;
5354
setBioBegin(begin);
5455
setBioEnd(end);
56+
this.setCompoundSet(DNACompoundSet.getDNACompoundSet());
5557

5658
}
5759

@@ -188,8 +190,9 @@ public ArrayList<ProteinSequence> getProteinCDSSequences() {
188190
public DNASequence getDNACodingSequence() {
189191
StringBuilder sb = new StringBuilder();
190192
for (CDSSequence cdsSequence : cdsSequenceList) {
191-
sb.append(cdsSequence.getCodingSequence());
193+
sb.append(cdsSequence.getCodingSequence());
192194
}
195+
193196
DNASequence dnaSequence = new DNASequence(sb.toString().toUpperCase());
194197
dnaSequence.setAccession(new AccessionID(this.getAccession().getID()));
195198
return dnaSequence;
@@ -213,6 +216,7 @@ public ProteinSequence getProteinSequence(TranscriptionEngine engine) {
213216
RNASequence rnaCodingSequence = dnaCodingSequence.getRNASequence(engine);
214217
ProteinSequence proteinSequence = rnaCodingSequence.getProteinSequence(engine);
215218
proteinSequence.setAccession(new AccessionID(this.getAccession().getID()));
219+
216220
return proteinSequence;
217221
}
218222

biojava3-core/src/main/java/org/biojava3/core/sequence/template/AbstractSequence.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,19 @@ private SequenceReader<C> getSequenceStorage() {
499499
if (sequenceStorage != null) {
500500
return sequenceStorage;
501501
}
502-
/*
503502
if (parentSequence != null) {
504-
return parentSequence.getSequenceStorage();
503+
504+
//return parentSequence.getSequenceStorage();
505+
506+
if ( this.compoundSet.equals(parentSequence.getCompoundSet())){
507+
sequenceStorage = new ArrayListSequenceReader<C>();
508+
sequenceStorage.setCompoundSet(this.getCompoundSet());
509+
sequenceStorage.setContents(parentSequence.getSequenceAsString());
510+
return sequenceStorage;
511+
}
512+
505513
}
506-
*/
514+
507515
return null;
508516
}
509517

@@ -515,6 +523,7 @@ private SequenceReader<C> getSequenceStorage() {
515523
* @return
516524
*/
517525
public String getSequenceAsString(Integer bioStart, Integer bioEnd, Strand strand) {
526+
518527
Location loc = new SimpleLocation(bioStart, bioEnd, strand);
519528
return loc.getSubSequence(this).getSequenceAsString();
520529
}
@@ -542,6 +551,7 @@ public List<C> getAsList() {
542551
* @return
543552
*/
544553
public C getCompoundAt(int position) {
554+
545555
return getSequenceStorage().getCompoundAt(position);
546556
}
547557

0 commit comments

Comments
 (0)