Skip to content

Commit a16d533

Browse files
authored
Merge pull request biojava#998 from richarda23/biojava#944-testcoverage
biojava#944 testcoverage
2 parents 351490b + 3c045a7 commit a16d533

23 files changed

+864
-76
lines changed

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.biojava.nbio.core.util.Hashcoder;
2727

2828
/**
29-
* Used in Sequences as the unique indentifier. If possible, set the {@link DataSource} to know the
29+
* Used in Sequences as the unique identifier. If possible, set the {@link DataSource} to know the
3030
* source of the id. This allows a SequenceProxy to gather features or related sequences
3131
* Protein->Gene as an example. When parsing a Blast file it is also possible
3232
* to identify the type of ID
@@ -42,26 +42,21 @@ public class AccessionID {
4242
private String identifier = null;
4343

4444
/**
45-
*
45+
* Default constructor sets id t empty string
4646
*/
47-
4847
public AccessionID(){
4948
id = "";
50-
5149
}
5250

5351
/**
54-
*
55-
* @param id
52+
* Creates an id with default DataSource.LOCAL source
53+
* @param id non-null
5654
*/
5755
public AccessionID(String id) {
58-
this.id = id.trim();
59-
this.source = DataSource.LOCAL;
56+
this(id, DataSource.LOCAL);
6057
}
6158

62-
6359
/**
64-
*
6560
* @param id
6661
* @param source
6762
*/
@@ -114,11 +109,6 @@ public int hashCode() {
114109
return r;
115110
}
116111

117-
// public void setDataSource(DataSource dataSource){
118-
// source = dataSource;
119-
// }
120-
121-
122112
/**
123113
* In case if the {@link #getID() } is not unique keeps the id version.
124114
* @return the version
@@ -132,10 +122,8 @@ public void setVersion(Integer version) {
132122
}
133123

134124
/**
135-
* In case if {@link #getID() } in not unique keeps the alternative id, eg. NCBI GI number.
136-
*
137-
* This may null.
138-
*
125+
* In case if {@link #getID() } is not unique, keeps the alternative id, e.g. NCBI GI number.
126+
* This may be null.
139127
* @return
140128
*/
141129
public String getIdentifier() {

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/ChromosomeSequence.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,11 @@ public GeneSequence removeGeneSequence(String accession) {
125125
* which actually contains the sequence data. Strand is important for positive and negative
126126
* direction where negative strand means we need reverse complement. If negative strand then
127127
* bioBegin will be greater than bioEnd
128-
*
129-
*
130128
* @param accession
131-
* @param begin
132-
* @param end
129+
* @param bioBegin
130+
* @param bioEnd
133131
* @param strand
134-
* @return
132+
* @return A GeneSequence
135133
*/
136134
public GeneSequence addGene(AccessionID accession, int bioBegin, int bioEnd, Strand strand) {
137135
GeneSequence geneSequence = new GeneSequence(this, bioBegin, bioEnd, strand);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929

3030
/**
31-
* Sort Exon where it is a little confusing if exons shoud always be ordered left to right
31+
* Sort Exon where it is a little confusing if exons should always be ordered left to right
3232
* where a negative stranded gene should go the other direction. Need to think about this?
3333
* @author Scooter Willis <willishf at gmail dot com>
3434
*/
@@ -37,7 +37,6 @@ public class ExonComparator implements Comparator<ExonSequence>, Serializable{
3737

3838
@Override
3939
public int compare(ExonSequence o1, ExonSequence o2) {
40-
4140
return o1.getBioBegin() - o2.getBioBegin();
4241
}
4342

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

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

25-
25+
import org.biojava.nbio.core.exceptions.CompoundNotFoundException;
26+
import org.biojava.nbio.core.sequence.compound.DNACompoundSet;
2627

2728
/**
2829
* A gene contains a collection of Exon sequences
2930
* @author Scooter Willis
3031
*/
3132
public class ExonSequence extends DNASequence {
3233

33-
//private static final Logger log = Logger.getLogger(ExonSequence.class.getName());
3434

3535
/**
3636
* Need a parent gene sequence and the bioBegin and bioEnd. An Exon sequence doesn't actually imply what the
@@ -44,6 +44,12 @@ public class ExonSequence extends DNASequence {
4444
* @param bioEnd
4545
*/
4646
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+
}
4753
this.setParentSequence(parentGeneSequence);
4854
setBioBegin(bioBegin);
4955
setBioEnd(bioEnd);

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

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,29 @@ public class GeneSequence extends DNASequence {
5050
private Strand strand = Strand.UNDEFINED;
5151
private ChromosomeSequence chromosomeSequence;
5252

53+
/**
54+
* Use GeneSequence(ChromosomeSequence parentSequence, AccessionID accessionId, int begin, int end, Strand strand)
55+
* which mandates an accessionID.
56+
* @param parentSequence
57+
* @param begin
58+
* @param end inclusive of end
59+
* @param strand force a gene to have strand and transcription sequence will inherit
60+
* @deprecated
61+
*/
62+
public GeneSequence(ChromosomeSequence parentSequence, int begin, int end, Strand strand) {
63+
setCompoundSet(DNACompoundSet.getDNACompoundSet());
64+
try {
65+
initSequenceStorage(parentSequence.getSequenceAsString());
66+
} catch (CompoundNotFoundException e) {
67+
throw new IllegalArgumentException(e);
68+
}
69+
chromosomeSequence = parentSequence;
70+
setParentSequence(parentSequence);
71+
setBioBegin(begin);
72+
setBioEnd(end);
73+
setStrand(strand);
74+
}
75+
5376
/**
5477
* A class that keeps track of the details of a GeneSequence which is difficult to properly model. Two important concepts that is difficult
5578
* to make everything flexible but still work. You can have GFF features that only describe Exons or Exons/Introns or CDS regions and one
@@ -60,18 +83,15 @@ public class GeneSequence extends DNASequence {
6083
*
6184
* This is also a key class in the biojava-3-genome module for reading and writing GFF3 files
6285
*
63-
* @param parentDNASequence
86+
* @param parentSequence
87+
* @param accessionId An identifier for the gene.
6488
* @param begin
65-
* @param end inclusive of end
89+
* @param end
6690
* @param strand force a gene to have strand and transcription sequence will inherit
6791
*/
68-
public GeneSequence(ChromosomeSequence parentSequence, int begin, int end, Strand strand) {
69-
chromosomeSequence = parentSequence;
70-
setParentSequence(parentSequence);
71-
setBioBegin(begin);
72-
setBioEnd(end);
73-
setStrand(strand);
74-
this.setCompoundSet(DNACompoundSet.getDNACompoundSet());
92+
public GeneSequence(ChromosomeSequence parentSequence, AccessionID accessionId, int begin, int end, Strand strand) {
93+
this(parentSequence,begin,end,strand);
94+
setAccession(accessionId);
7595
}
7696

7797
/**
@@ -116,7 +136,8 @@ public void addIntronsUsingExons() throws Exception {
116136
for (int i = 0; i < exonSequenceList.size() - 1; i++) {
117137
ExonSequence exon1 = exonSequenceList.get(i);
118138
ExonSequence exon2 = exonSequenceList.get(i + 1);
119-
this.addIntron(new AccessionID(this.getAccession().getID() + "-" + "intron" + intronIndex), exon1.getBioEnd() - shift, exon2.getBioBegin() + shift);
139+
AccessionID intronId= new AccessionID(this.getAccession().getID() + "-" + "intron" + intronIndex);
140+
this.addIntron(intronId, exon1.getBioEnd() - shift, exon2.getBioBegin() + shift);
120141
intronIndex++;
121142
}
122143

@@ -168,8 +189,6 @@ public LinkedHashMap<String, TranscriptSequence> getTranscripts() {
168189
* @return transcriptsequence
169190
*/
170191
public TranscriptSequence removeTranscript(String accession) {
171-
172-
173192
return transcriptSequenceHashMap.remove(accession);
174193
}
175194

@@ -194,7 +213,7 @@ public TranscriptSequence addTranscript(AccessionID accession, int begin, int en
194213
/**
195214
* Remove the intron by accession
196215
* @param accession
197-
* @return intron sequence
216+
* @return the removed intron sequence, or null if no intron with that accession exists.
198217
*/
199218
public IntronSequence removeIntron(String accession) {
200219
for (IntronSequence intronSequence : intronSequenceList) {
@@ -272,25 +291,25 @@ public ExonSequence addExon(AccessionID accession, int begin, int end) {
272291
}
273292

274293
/**
275-
* Get the exons as an ArrayList
294+
* Get the exons as an ArrayList. Modifying this list will not modify the underlying collection
276295
* @return exons
277296
*/
278297
public ArrayList<ExonSequence> getExonSequences() {
279-
return exonSequenceList;
298+
return new ArrayList<>(exonSequenceList);
280299
}
281300

282301
/**
283-
* Get the introns as an ArrayList
302+
* Get the introns as an ArrayList. Modifying this list will not modify the underlying collection
284303
* @return introns
285304
*/
286305
public ArrayList<IntronSequence> getIntronSequences() {
287-
return intronSequenceList;
306+
return new ArrayList<>(intronSequenceList);
288307
}
289308

290309
/**
291310
* Try to give method clarity where you want a DNASequence coding in the 5' to 3' direction
292311
* Returns the DNASequence representative of the 5' and 3' reading based on strand
293-
* @return dna sequence
312+
* @return dna sequence or null if sequence could not be generated.
294313
*/
295314
public DNASequence getSequence5PrimeTo3Prime() {
296315
String sequence = getSequenceAsString(this.getBioBegin(), this.getBioEnd(), this.getStrand());
@@ -308,11 +327,11 @@ public DNASequence getSequence5PrimeTo3Prime() {
308327
DNASequence dnaSequence = null;
309328
try {
310329
dnaSequence = new DNASequence(sequence.toUpperCase());
330+
dnaSequence.setAccession(new AccessionID(this.getAccession().getID()));
311331
} catch (CompoundNotFoundException e) {
312332
// this should not happen, the sequence is DNA originally, if it does, there's a bug somewhere
313333
logger.error("Could not create new DNA sequence in getSequence5PrimeTo3Prime(). Error: {}",e.getMessage());
314334
}
315-
dnaSequence.setAccession(new AccessionID(this.getAccession().getID()));
316335
return dnaSequence;
317336
}
318337
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public String toString() {
180180
// helper methods
181181

182182
/**
183-
* Helper method that does all the formating work
183+
* Helper method that does all the formatting work
184184
* @param width
185185
* @param header
186186
* @param idFormat

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public RNASequence(String seqString, CompoundSet<NucleotideCompound> compoundSet
7272
}
7373

7474
/**
75-
* Create a RNA sequence from a proxy reader and user defined RNA compound set
75+
* Create a RNA sequence from a proxy reader and user-defined RNA compound set
7676
* @param proxyLoader
7777
* @param compoundSet
7878
*/
@@ -86,7 +86,7 @@ public RNASequence(ProxySequenceReader<NucleotideCompound> proxyLoader,
8686
* @return
8787
*/
8888
public SequenceView<NucleotideCompound> getReverseComplement() {
89-
return new ComplementSequenceView<NucleotideCompound>(getInverse());
89+
return new ComplementSequenceView<>(getInverse());
9090
}
9191

9292
/**
@@ -97,15 +97,15 @@ public SequenceView<NucleotideCompound> getReverseComplement() {
9797
*/
9898
@Override
9999
public SequenceView<NucleotideCompound> getInverse() {
100-
return new ReversedSequenceView<NucleotideCompound>(this);
100+
return new ReversedSequenceView<>(this);
101101
}
102102

103103
/**
104104
* Get the complement view of the RNA sequence
105105
* @return
106106
*/
107107
public SequenceView<NucleotideCompound> getComplement() {
108-
return new ComplementSequenceView<NucleotideCompound>(this);
108+
return new ComplementSequenceView<>(this);
109109
}
110110

111111
/**
@@ -117,7 +117,7 @@ public ProteinSequence getProteinSequence() {
117117
}
118118

119119
/**
120-
* Get the ProteinSequene from the RNA sequence with user defined
120+
* Get the ProteinSequence from the RNA sequence with user-defined
121121
* transcription engine
122122
*
123123
* @param engine

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import java.util.Comparator;
2929

3030
/**
31-
* Used to sort sequences
31+
* Used to sort sequences in ascending order of bioBegin property.
3232
* @author Scooter Willis <willishf at gmail dot com>
3333
*/
3434
public class SequenceComparator implements Comparator<AbstractSequence<?>>, Serializable{

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@
2626
/**
2727
* A sequence can be associated with a species or Taxonomy ID
2828
* @author Scooter Willis
29+
*
2930
*/
3031
public class TaxonomyID {
31-
32+
//TODO this should implement equals and hashcode if is value object?
3233

3334
private String id = null;
3435
DataSource dataSource = DataSource.UNKNOWN;
3536

3637
public TaxonomyID(String id, DataSource dataSource) {
38+
// TODO should throw IAE if null args?
3739
this.id = id;
3840
this.dataSource = dataSource;
3941
}

0 commit comments

Comments
 (0)