[med-svn] [Git][med-team/jebl2][master] 7 commits: New upstream version 0.1+git20190308.a98448e

Pierre Gruet gitlab at salsa.debian.org
Thu Jul 23 21:15:57 BST 2020



Pierre Gruet pushed to branch master at Debian Med / jebl2


Commits:
a8569cac by Pierre Gruet at 2020-04-23T22:38:54+02:00
New upstream version 0.1+git20190308.a98448e
- - - - -
d7883297 by Andreas Tille at 2020-04-24T22:17:23+02:00
New upstream version 0.1+git20190308.a98448e
- - - - -
79f5e87a by Pierre Gruet at 2020-07-23T17:57:08+02:00
New upstream version 0.1+git20200723.3a2ead5
- - - - -
4e68f51e by Pierre Gruet at 2020-07-23T17:57:09+02:00
Update upstream source from tag 'upstream/0.1+git20200723.3a2ead5'

Update to upstream version '0.1+git20200723.3a2ead5'
with Debian dir afe1a9a9e170cf1af79e2fe365dd677512db91a6
- - - - -
f44a2949 by Pierre Gruet at 2020-07-23T21:48:32+02:00
Compat-level set to 13

- - - - -
5659d795 by Pierre Gruet at 2020-07-23T21:49:14+02:00
Preparing changelog

- - - - -
d530b6f2 by Pierre Gruet at 2020-07-23T22:04:40+02:00
Forwarding Javadoc patch to upstream developers

- - - - -


9 changed files:

- debian/changelog
- debian/control
- debian/patches/javadoc.patch
- src/jebl/evolution/io/NewickExporter.java
- src/jebl/evolution/io/NexusExporter.java
- src/jebl/evolution/io/PHYLIPExporter.java
- src/jebl/evolution/io/TreeExporter.java
- src/jebl/evolution/sequences/Sequence.java
- src/jebl/evolution/trees/RootedSubtree.java


Changes:

=====================================
debian/changelog
=====================================
@@ -1,3 +1,10 @@
+jebl2 (0.1+git20200723.3a2ead5-1) UNRELEASED; urgency=medium
+
+  * New upstream version 0.1+git20200723.3a2ead5
+  * Compat-level set to 13
+
+ -- Pierre Gruet <pgtdebian at free.fr>  Thu, 23 Jul 2020 21:48:44 +0200
+
 jebl2 (0.1+git20190308-1) unstable; urgency=medium
 
   * New upstream version 0.1+git20190308


=====================================
debian/control
=====================================
@@ -4,7 +4,7 @@ Uploaders: Andreas Tille <tille at debian.org>,
            Pierre Gruet <pgtdebian at free.fr>
 Section: java
 Priority: optional
-Build-Depends: debhelper-compat (= 12),
+Build-Depends: debhelper-compat (= 13),
                javahelper
 Build-Depends-Indep: default-jdk,
                      default-jdk-doc,


=====================================
debian/patches/javadoc.patch
=====================================
@@ -1,6 +1,7 @@
 Author: Andreas Tille <tille at debian.org>
 Last-Update: Thu, 10 Feb 2011 10:26:38 +0100
 Description: Add javadoc
+Forwarded: https://github.com/rambaut/jebl2/issues/2
 
 --- /dev/null
 +++ b/javadoc.xml


=====================================
src/jebl/evolution/io/NewickExporter.java
=====================================
@@ -4,6 +4,7 @@ import jebl.evolution.trees.Tree;
 import jebl.evolution.trees.Utils;
 import jebl.evolution.trees.RootedTree;
 
+import java.io.PrintWriter;
 import java.io.Writer;
 import java.io.IOException;
 import java.io.BufferedWriter;
@@ -16,7 +17,7 @@ import java.util.Collection;
  */
 public class NewickExporter implements TreeExporter {
     public NewickExporter(Writer writer) {
-        this.writer = writer;
+        this.writer = new PrintWriter(writer);
     }
 
     /**
@@ -25,7 +26,7 @@ public class NewickExporter implements TreeExporter {
      * @param tree
      * @throws java.io.IOException
      */
-    public void exportTree(Tree tree) throws IOException {
+    public void exportTree(Tree tree) {
         writeTree(tree);
     }
 
@@ -35,15 +36,20 @@ public class NewickExporter implements TreeExporter {
      * @param trees
      * @throws java.io.IOException
      */
-    public void exportTrees(Collection<? extends Tree> trees) throws IOException {
+    public void exportTrees(Collection<? extends Tree> trees) {
         for (Tree tree : trees) {
             writeTree(tree);
         }
     }
 
-    private void writeTree(Tree tree) throws IOException {
-        writer.write(Utils.toNewick(Utils.rootTheTree(tree)));
+    @Override
+    public void close() {
+        writer.close();
     }
 
-    private final Writer writer;
+    private void writeTree(Tree tree) {
+        writer.println(Utils.toNewick(Utils.rootTheTree(tree)));
+    }
+
+    private final PrintWriter writer;
 }


=====================================
src/jebl/evolution/io/NexusExporter.java
=====================================
@@ -30,16 +30,16 @@ import java.util.List;
 
 public class NexusExporter implements AlignmentExporter, SequenceExporter, TreeExporter {
 
-	public NexusExporter(Writer writer) {
-		this(writer, true);
-	}
+    public NexusExporter(Writer writer) {
+        this(writer, true);
+    }
 
-	/**
+    /**
      *
      * @param writer where export text goes
      */
     public NexusExporter(Writer writer, boolean writeMetaComments) {
-		this(writer, writeMetaComments, false);
+        this(writer, writeMetaComments, false);
     }
 
     /**
@@ -47,7 +47,7 @@ public class NexusExporter implements AlignmentExporter, SequenceExporter, TreeE
      * @param writer where export text goes
      */
     public NexusExporter(Writer writer, boolean writeMetaComments, boolean interleave) {
-		this.writeMetaComments = writeMetaComments;
+        this.writeMetaComments = writeMetaComments;
         this.interleave = interleave;
         this.writer = new PrintWriter(writer);
         this.writer.println("#NEXUS");
@@ -56,14 +56,18 @@ public class NexusExporter implements AlignmentExporter, SequenceExporter, TreeE
     /**
      * exportAlignment.
      */
-    public void exportAlignment(Alignment alignment) throws IOException {
-    	exportSequences(alignment.getSequences());
+    public void exportAlignment(Alignment alignment) {
+        exportSequences(alignment.getSequences());
     }
 
     /**
      * export alignment.
      */
-    public void exportSequences(Collection<? extends Sequence> sequences) throws IOException, IllegalArgumentException {
+    public void exportSequences(Collection<? extends Sequence> sequences) throws IllegalArgumentException {
+
+        if (treesBlockOpen) {
+            endWriteTrees();
+        }
 
         establishSequenceTaxa(sequences);
 
@@ -77,7 +81,7 @@ public class NexusExporter implements AlignmentExporter, SequenceExporter, TreeE
             if (seqType == null) {
                 seqType = sequence.getSequenceType();
             } else if( seqType != sequence.getSequenceType() ) {
-               throw new IllegalArgumentException("All seqeuences must have the same type");
+                throw new IllegalArgumentException("All seqeuences must have the same type");
             }
         }
 
@@ -113,58 +117,25 @@ public class NexusExporter implements AlignmentExporter, SequenceExporter, TreeE
         }
     }
 
+    private boolean treesBlockOpen = false;
+
     /**
      * Export a single tree
      *
      * @param tree
      * @throws java.io.IOException
      */
-    public void exportTree(Tree tree) throws IOException {
+    public void exportTree(Tree tree) {
         List<Tree> trees = new ArrayList<Tree>();
         trees.add(tree);
         exportTrees(trees);
     }
 
-    private void writeTrees(Collection<? extends Tree> trees, boolean checkTaxa) throws IOException {
-        int nt = 0;
-        for( Tree t : trees ) {
-            if( checkTaxa && !establishTreeTaxa(t) ) {
-                throw new IllegalArgumentException();
-            }
-            final boolean isRooted = t instanceof RootedTree;
-            final RootedTree rtree = isRooted ? (RootedTree)t : Utils.rootTheTree(t);
-
-            final Object name = t.getAttribute(treeNameAttributeKey);
-
-            ++nt;
-            final String treeName = (name != null) ? NexusImporter.makeIntoAllowableIdentifier(name.toString()) : "tree_" + nt;
-
-            StringBuilder builder = new StringBuilder("\ttree ");
-
-            builder.append(treeName);
-            builder.append(" = ");
-
-            // TREE & UTREE are depreciated in the NEXUS format in favour of a metacomment
-            // [&U] or [&R] after the TREE command. Andrew.
-            // TT: The [&U], [&R] should actually come *after* the " = " and be uppercase, see
-            // e.g. tree_rest in http://www.cs.nmsu.edu/~epontell/nexus/nexus_grammar .
-            // Before 2008-05-05 we incorrectly inserted it before the treeName.
-            builder.append(isRooted && !rtree.conceptuallyUnrooted() ? "[&R] " : "[&U] ");
-
-            appendAttributes(rtree, exportExcludeKeys, builder);
-
-            appendTree(rtree, rtree.getRootNode(), builder);
-            builder.append(";");
-
-            writer.println(builder);
-        }
-    }
-
-    public void exportTrees(Collection<? extends Tree> trees) throws IOException {
+    public void exportTrees(Collection<? extends Tree> trees) {
         exportTrees(trees, false);
     }
 
-    public void exportTrees(Collection<? extends Tree> trees, boolean writeTaxa) throws IOException {
+    public void exportTrees(Collection<? extends Tree> trees, boolean writeTaxa) {
         if (writeTaxa) {
             TreeSet<Taxon> taxa = new TreeSet<Taxon>();
             for (Tree tree : trees) {
@@ -174,26 +145,88 @@ public class NexusExporter implements AlignmentExporter, SequenceExporter, TreeE
             establishTaxa(taxa);
         }
 
-        writer.println("begin trees;");
+        if (!treesBlockOpen) {
+            startWriteTrees(null);
+        }
+        writeTrees(trees, false);
+    }
+
+    public void exportTreesWithTranslation(Collection<? extends Tree> trees, Map<String, String> translationMap) throws IOException {
+        if (!treesBlockOpen) {
+            startWriteTrees(translationMap);
+        }
         writeTrees(trees, false);
-        writer.println("end;");
     }
 
-    public void exportTreesWithTranslation(Collection<? extends Tree> trees, Map<String, String> t) throws IOException {
+    public void close() {
+        if (treesBlockOpen) {
+            endWriteTrees();
+        }
+        writer.close();
+    }
+
+    private void startWriteTrees(Map<String, String> translationMap) {
         writer.println("begin trees;");
-        writer.println("\ttranslate");
-        boolean first = true;
-        for( Map.Entry<String, String> e : t.entrySet() ) {
-            writer.print((first ? "" : ",\n") + "\t\t" + safeName(e.getKey()) + " " + safeName(e.getValue()));
-            first = false;
+        if (translationMap != null) {
+            writer.println("\ttranslate");
+            boolean first = true;
+            for (Map.Entry<String, String> e : translationMap.entrySet()) {
+                writer.print((first ? "" : ",\n") + "\t\t" + safeName(e.getKey()) + " " + safeName(e.getValue()));
+                first = false;
+            }
+            writer.println("\n\t;");
         }
-        writer.println("\n\t;");
+        treesBlockOpen = true;
+    }
 
-        writeTrees(trees, false);
+    private void endWriteTrees() {
         writer.println("end;");
     }
 
+    private void writeTrees(Collection<? extends Tree> trees, boolean checkTaxa) {
+        for (Tree tree : trees) {
+            writeTree(tree, checkTaxa);
+        }
+    }
+
+    private void writeTree(Tree tree, boolean checkTaxa) {
+        int nt = 0;
+        if( checkTaxa && !establishTreeTaxa(tree) ) {
+            throw new IllegalArgumentException();
+        }
+        final boolean isRooted = tree instanceof RootedTree;
+        final RootedTree rtree = isRooted ? (RootedTree)tree : Utils.rootTheTree(tree);
+
+        final Object name = tree.getAttribute(treeNameAttributeKey);
+
+        ++nt;
+        final String treeName = (name != null) ? NexusImporter.makeIntoAllowableIdentifier(name.toString()) : "tree_" + nt;
+
+        StringBuilder builder = new StringBuilder("\ttree ");
+
+        builder.append(treeName);
+        builder.append(" = ");
+
+        // TREE & UTREE are depreciated in the NEXUS format in favour of a metacomment
+        // [&U] or [&R] after the TREE command. Andrew.
+        // TT: The [&U], [&R] should actually come *after* the " = " and be uppercase, see
+        // e.g. tree_rest in http://www.cs.nmsu.edu/~epontell/nexus/nexus_grammar .
+        // Before 2008-05-05 we incorrectly inserted it before the treeName.
+        builder.append(isRooted && !rtree.conceptuallyUnrooted() ? "[&R] " : "[&U] ");
+
+        appendAttributes(rtree, exportExcludeKeys, builder);
+
+        appendTree(rtree, rtree.getRootNode(), builder);
+        builder.append(";");
+
+        writer.println(builder);
+    }
+
     public void exportMatrix(final DistanceMatrix distanceMatrix) {
+        if (treesBlockOpen) {
+            endWriteTrees();
+        }
+
         final List<Taxon> taxa = distanceMatrix.getTaxa();
         establishTaxa(taxa);
         writer.println("begin distances;");
@@ -365,9 +398,9 @@ public class NexusExporter implements AlignmentExporter, SequenceExporter, TreeE
     }
 
     private StringBuilder appendAttributes(Attributable item, String[] excludeKeys, StringBuilder builder) {
-	    if (!writeMetaComments) {
-		    return builder;
-	    }
+        if (!writeMetaComments) {
+            return builder;
+        }
 
         boolean first = true;
         for( String key : item.getAttributeNames() ) {
@@ -445,7 +478,7 @@ public class NexusExporter implements AlignmentExporter, SequenceExporter, TreeE
 
     private Set<Taxon> taxa = null;
     protected final PrintWriter writer;
-	private boolean writeMetaComments;
+    private boolean writeMetaComments;
     private boolean interleave;
     public static final int MAX_ROW_LENGTH = 60;
 }


=====================================
src/jebl/evolution/io/PHYLIPExporter.java
=====================================
@@ -104,15 +104,20 @@ public class PHYLIPExporter implements AlignmentExporter, TreeExporter {
 
     // Should call those only after the alignment
 
-    public void exportTree(Tree tree) throws IOException {
+    public void exportTree(Tree tree) {
         final RootedTree rtree = Utils.rootTheTree(tree);
         writer.print(Utils.toNewick(rtree));
         writer.println(";");
     }
 
-    public void exportTrees(Collection<? extends Tree> trees) throws IOException {
+    public void exportTrees(Collection<? extends Tree> trees) {
        for( Tree t : trees ) {
            exportTree(t);
        }
     }
+
+    @Override
+    public void close() {
+        writer.close();
+    }
 }


=====================================
src/jebl/evolution/io/TreeExporter.java
=====================================
@@ -19,12 +19,14 @@ public interface TreeExporter {
      * @param tree
      * @throws IOException
      */
-    void exportTree(Tree tree) throws IOException;
+    void exportTree(Tree tree);
 
     /**
      * Export a collection of trees
      * @param trees
      * @throws IOException
      */
-    void exportTrees(Collection<? extends Tree> trees) throws IOException;
+    void exportTrees(Collection<? extends Tree> trees);
+
+    void close();
 }


=====================================
src/jebl/evolution/sequences/Sequence.java
=====================================
@@ -95,18 +95,17 @@ public interface Sequence extends Attributable, Comparable {
 		return new BasicSequence(sequence.getSequenceType(), sequence.getTaxon(), states);
 	}
 
-	static Sequence trimSequence(Sequence sequence, State[] trimStates) {
-		Set<State> trimSet = new HashSet<>(Arrays.asList(trimStates));
+	static Sequence trimSequence(Sequence sequence, List<State> trimStates) {
 		State[] sourceStates = sequence.getStates();
 		int i = 0;
-		while (i < sourceStates.length && trimSet.contains(sourceStates[i])) {
+		while (i < sourceStates.length && trimStates.contains(sourceStates[i])) {
 			i++;
 		}
 		if (i < sourceStates.length) {
 			Sequence sequence1 = getSubSequence(sequence, i, sourceStates.length - 1);
 			sourceStates = sequence1.getStates();
 			i = sourceStates.length - 1;
-			while (i > 0 && trimSet.contains(sourceStates[i])) {
+			while (i > 0 && trimStates.contains(sourceStates[i])) {
 				i--;
 			}
 			return getSubSequence(sequence1, 0, i);
@@ -132,7 +131,8 @@ public interface Sequence extends Attributable, Comparable {
 	 * @return an array of states
 	 */
 	static Sequence stripStates(final Sequence sequence, final List<State> stripStates) {
-		return new BasicSequence(sequence.getSequenceType(), sequence.getTaxon(), jebl.evolution.sequences.Utils.stripStates(sequence.getStates(), stripStates));
+		return new BasicSequence(sequence.getSequenceType(), sequence.getTaxon(),
+				jebl.evolution.sequences.Utils.stripStates(sequence.getStates(), stripStates));
 	}
 
 	/**


=====================================
src/jebl/evolution/trees/RootedSubtree.java
=====================================
@@ -52,23 +52,26 @@ final public class RootedSubtree implements RootedTree {
                     children.add(newChild);
                 }
             }
-            if (children.size() >= 2) {
+            if (children.size() > 1) {
                 newNode = createInternalNode(children);
 
-                for( Map.Entry<String, Object> e : node.getAttributeMap().entrySet() ) {
-                    newNode.setAttribute(e.getKey(), e.getValue());
-                }
-
-                setHeight(newNode, tree.getHeight(node));
             } else if (children.size() == 1) {
 
-                newNode = children.get(0);
+                // just return the single child
+                return children.get(0);
             } else {
 
                 newNode = null;
             }
         }
 
+        if (newNode != null) {
+            for( Map.Entry<String, Object> e : node.getAttributeMap().entrySet() ) {
+                newNode.setAttribute(e.getKey(), e.getValue());
+            }
+            setHeight(newNode, tree.getHeight(node));
+        }
+
         return newNode;
     }
 



View it on GitLab: https://salsa.debian.org/med-team/jebl2/-/compare/1d5876e50927d6d9af7c6899568ae96f5de18546...d530b6f28fac936e0651f222ead924966e71f452

-- 
View it on GitLab: https://salsa.debian.org/med-team/jebl2/-/compare/1d5876e50927d6d9af7c6899568ae96f5de18546...d530b6f28fac936e0651f222ead924966e71f452
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20200723/7fae7a4f/attachment-0001.html>


More information about the debian-med-commit mailing list