From: kjvdheide Date: Wed, 8 Nov 2017 17:46:52 +0000 (+0000) Subject: JAL-2795 created static class for forester conversions X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=a7f361e7a052e96f4c6a4a570fd4a374f8b022c0;p=jalview.git JAL-2795 created static class for forester conversions --- diff --git a/src/jalview/ext/forester/ForesterConversions.java b/src/jalview/ext/forester/ForesterConversions.java new file mode 100644 index 0000000..e35132c --- /dev/null +++ b/src/jalview/ext/forester/ForesterConversions.java @@ -0,0 +1,80 @@ +package jalview.ext.forester; + +import jalview.datamodel.SequenceI; +import jalview.math.MatrixI; + +import org.forester.evoinference.matrix.distance.DistanceMatrix; +import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException; + +public final class ForesterConversions +{ + public static org.forester.phylogeny.data.Sequence createForesterSequence( + SequenceI jalviewSequence) + { + org.forester.phylogeny.data.Sequence foresterSeq = new org.forester.phylogeny.data.Sequence(); + if (jalviewSequence.getDescription() != null) + { + foresterSeq.setName(jalviewSequence.getDescription()); + } + foresterSeq.setMolecularSequenceAligned(true); // all tree sequences should + // be aligned already + foresterSeq.setMolecularSequence(jalviewSequence.getSequenceAsString()); + if (jalviewSequence.isProtein()) // add checks for DNA or RNA (infer from + // forester itself?) + { + try + { + foresterSeq.setType("protein"); + } catch (final PhyloXmlDataFormatException ignore) + { + // do nothing + } + + } + + return foresterSeq; + + } + + + // public static org.forester.phylogeny.data.Accession + // createForesterAccession( + // SequenceI jalviewSequence) + // { + // + // + // org.forester.phylogeny.data.Accession foresterAcs = new + // org.forester.phylogeny.data.Accession(); + // + // return foresterAcs; + // } + + public static DistanceMatrix createForesterDistanceMatrix( + final MatrixI jalviewInputMatrix, + final String[] matrixIdentifiers) + { + if (jalviewInputMatrix.width() != jalviewInputMatrix.height()) + { + // some kind of warning? + } + + DistanceMatrix foresterMatrix = new ForesterMatrix(jalviewInputMatrix, + matrixIdentifiers); + return foresterMatrix; + + } + + public static DistanceMatrix createForesterDistanceMatrix( + final MatrixI jalviewInputMatrix, + final SequenceI[] matrixSequences) + { + if (jalviewInputMatrix.width() != jalviewInputMatrix.height()) + { + // some kind of warning? + } + DistanceMatrix foresterMatrix = new ForesterMatrix(jalviewInputMatrix, + matrixSequences); + return foresterMatrix; + + } +} diff --git a/src/jalview/ext/forester/ForesterMatrix.java b/src/jalview/ext/forester/ForesterMatrix.java index a1381be..7d3d295 100644 --- a/src/jalview/ext/forester/ForesterMatrix.java +++ b/src/jalview/ext/forester/ForesterMatrix.java @@ -31,7 +31,6 @@ public class ForesterMatrix implements DistanceMatrix this.identifiers = new String[matrixSequences.length]; int i = 0; - for (SequenceI sequence : matrixSequences) { identifiers[i] = sequence.getName(); @@ -167,13 +166,8 @@ public class ForesterMatrix implements DistanceMatrix final MatrixI jalviewInputMatrix, final SequenceI[] matrixSequences) { - if (jalviewInputMatrix.width() != jalviewInputMatrix.height()) - { - // some kind of warning? - } - DistanceMatrix foresterMatrix = new ForesterMatrix(jalviewInputMatrix, - matrixSequences); - return foresterMatrix; + return ForesterConversions.createForesterDistanceMatrix( + jalviewInputMatrix, matrixSequences); } @@ -181,14 +175,8 @@ public class ForesterMatrix implements DistanceMatrix final MatrixI jalviewInputMatrix, final String[] matrixIdentifiers) { - if (jalviewInputMatrix.width() != jalviewInputMatrix.height()) - { - // some kind of warning? - } - - DistanceMatrix foresterMatrix = new ForesterMatrix(jalviewInputMatrix, - matrixIdentifiers); - return foresterMatrix; + return ForesterConversions.createForesterDistanceMatrix( + jalviewInputMatrix, matrixIdentifiers); }