Skip to content

Commit b756496

Browse files
committed
FastaWriter was throwing Exception instead of IOException
1 parent 821b410 commit b756496

File tree

3 files changed

+22
-37
lines changed

3 files changed

+22
-37
lines changed

biojava-core/src/main/java/org/biojava/nbio/core/sequence/io/FastaWriter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.io.BufferedOutputStream;
3434
import java.io.FileInputStream;
3535
import java.io.FileOutputStream;
36+
import java.io.IOException;
3637
import java.io.OutputStream;
3738
import java.util.Collection;
3839
import java.util.LinkedHashMap;
@@ -90,7 +91,7 @@ public void setLineSeparator(String lineSeparator){
9091
lineSep = lineSeparator.getBytes();
9192
}
9293

93-
public void process() throws Exception {
94+
public void process() throws IOException {
9495
// boolean closeit = false;
9596

9697

@@ -152,7 +153,7 @@ public static void main(String[] args) {
152153
fileOutputStream.close();
153154

154155

155-
} catch (Exception e) {
156+
} catch (IOException e) {
156157
logger.warn("Exception: ", e);
157158
}
158159
}

biojava-phylo/src/main/java/org/biojava/nbio/phylo/DistanceMatrixCalculator.java

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package org.biojava.nbio.phylo;
22

3+
import java.io.IOException;
34
import java.util.List;
45

5-
import org.biojava.nbio.core.alignment.matrices.SubstitutionMatrixHelper;
66
import org.biojava.nbio.core.alignment.template.SubstitutionMatrix;
77
import org.biojava.nbio.core.sequence.MultipleSequenceAlignment;
8-
import org.biojava.nbio.core.sequence.compound.AminoAcidCompound;
98
import org.biojava.nbio.core.sequence.template.Compound;
109
import org.biojava.nbio.core.sequence.template.Sequence;
1110
import org.forester.evoinference.distance.PairwiseDistanceCalculator;
@@ -17,10 +16,7 @@
1716

1817
/**
1918
* The DistanceMatrixCalculator methods generate a {@link DistanceMatrix} from a
20-
* {@link MultipleSequenceAlignment}.
21-
* <p>
22-
* The implementations differ in the information required to calculate the
23-
* distances. Thus, the difference resides in their constructor.
19+
* {@link MultipleSequenceAlignment} or other indirect distance infomation (RMSD).
2420
*
2521
* @author Aleix Lafita
2622
* @since 4.1.1
@@ -51,17 +47,12 @@ private DistanceMatrixCalculator() {
5147
* @param msa
5248
* MultipleSequenceAlignment
5349
* @return DistanceMatrix
50+
* @throws Exception
5451
*/
5552
public static <C extends Sequence<D>, D extends Compound> DistanceMatrix fractionalDissimilarity(
56-
MultipleSequenceAlignment<C, D> msa) {
57-
58-
Msa fMsa = null;
59-
try {
60-
fMsa = ForesterWrapper.convert(msa);
61-
} catch (Exception e) {
62-
logger.warn("Could not convert BioJava MSA to forester MSA", e);
63-
}
53+
MultipleSequenceAlignment<C, D> msa) throws IOException {
6454

55+
Msa fMsa = ForesterWrapper.convert(msa);
6556
DistanceMatrix DM = PairwiseDistanceCalculator
6657
.calcFractionalDissimilarities(fMsa);
6758

@@ -83,17 +74,12 @@ public static <C extends Sequence<D>, D extends Compound> DistanceMatrix fractio
8374
* @param msa
8475
* MultipleSequenceAlignment
8576
* @return DistanceMatrix
77+
* @throws IOException
8678
*/
8779
public static <C extends Sequence<D>, D extends Compound> DistanceMatrix poissonDistance(
88-
MultipleSequenceAlignment<C, D> msa) {
89-
90-
Msa fMsa = null;
91-
try {
92-
fMsa = ForesterWrapper.convert(msa);
93-
} catch (Exception e) {
94-
logger.warn("Could not convert BioJava MSA to forester MSA", e);
95-
}
80+
MultipleSequenceAlignment<C, D> msa) throws IOException {
9681

82+
Msa fMsa = ForesterWrapper.convert(msa);
9783
DistanceMatrix DM = PairwiseDistanceCalculator
9884
.calcPoissonDistances(fMsa);
9985

@@ -120,17 +106,12 @@ public static <C extends Sequence<D>, D extends Compound> DistanceMatrix poisson
120106
* @param msa
121107
* MultipleSequenceAlignment
122108
* @return DistanceMatrix
109+
* @throws IOException
123110
*/
124111
public static <C extends Sequence<D>, D extends Compound> DistanceMatrix kimuraDistance(
125-
MultipleSequenceAlignment<C, D> msa) {
126-
127-
Msa fMsa = null;
128-
try {
129-
fMsa = ForesterWrapper.convert(msa);
130-
} catch (Exception e) {
131-
logger.warn("Could not convert BioJava MSA to forester MSA", e);
132-
}
112+
MultipleSequenceAlignment<C, D> msa) throws IOException {
133113

114+
Msa fMsa = ForesterWrapper.convert(msa);
134115
DistanceMatrix DM = PairwiseDistanceCalculator
135116
.calcPoissonDistances(fMsa);
136117

@@ -388,8 +369,7 @@ public static <C extends Sequence<D>, D extends Compound> DistanceMatrix pamMLdi
388369
MultipleSequenceAlignment<C, D> msa) {
389370

390371
// Need to import PAM1 matrix to biojava TODO
391-
SubstitutionMatrix<AminoAcidCompound> PAM1 = SubstitutionMatrixHelper
392-
.getPAM250();
372+
//SubstitutionMatrix<AminoAcidCompound> PAM1 = SubstitutionMatrixHelper.getPAM250();
393373

394374
return null;
395375
}
@@ -437,6 +417,7 @@ public static <C extends Sequence<D>, D extends Compound> DistanceMatrix structu
437417
* Math.log((rmsdMax * rmsdMax - rmsd0 * rmsd0)
438418
/ (rmsdMax * rmsdMax - rmsdMat[i][j]
439419
* rmsdMat[i][j]));
420+
d = Math.max(d, 0.0);
440421
DM.setValue(i, j, d);
441422
DM.setValue(j, i, d);
442423
}

biojava-phylo/src/main/java/org/biojava/nbio/phylo/ForesterWrapper.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.biojava.nbio.phylo;
22

33
import java.io.ByteArrayOutputStream;
4+
import java.io.IOException;
45
import java.io.OutputStream;
56

67
import org.biojava.nbio.core.sequence.MultipleSequenceAlignment;
@@ -36,11 +37,12 @@ private ForesterWrapper() {
3637
* @param msa
3738
* BioJava MultipleSequenceAlignment
3839
* @return forester Msa object
40+
* @throws IOException
3941
* @throws Exception
4042
* if the conversion was not possible
4143
*/
4244
public static <C extends Sequence<D>, D extends Compound> Msa convert(
43-
MultipleSequenceAlignment<C, D> msa) throws Exception {
45+
MultipleSequenceAlignment<C, D> msa) throws IOException {
4446

4547
// Convert the biojava MSA to a FASTA String
4648
OutputStream os = new ByteArrayOutputStream();
@@ -52,6 +54,7 @@ public String getHeader(C sequence) {
5254
return sequence.getAccession().toString();
5355
};
5456
});
57+
5558
fastaW.process();
5659
String fastaMSA = os.toString();
5760

@@ -68,10 +71,10 @@ public String getHeader(C sequence) {
6871
* @param writeDistances
6972
* write the branch lengths if true
7073
* @return
71-
* @throws Exception
74+
* @throws IOException
7275
*/
7376
public static String getNewickString(Phylogeny phylo,
74-
boolean writeDistances) throws Exception {
77+
boolean writeDistances) throws IOException {
7578

7679
PhylogenyWriter w = new PhylogenyWriter();
7780
StringBuffer newickString = w.toNewHampshire(phylo, writeDistances);

0 commit comments

Comments
 (0)