in progress
authorcmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Thu, 24 Jan 2013 07:01:08 +0000 (07:01 +0000)
committercmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Thu, 24 Jan 2013 07:01:08 +0000 (07:01 +0000)
forester/java/src/org/forester/archaeopteryx/TreePanel.java
forester/java/src/org/forester/io/writers/SequenceWriter.java

index 740e0d0..18128a0 100644 (file)
@@ -100,6 +100,7 @@ import org.forester.archaeopteryx.phylogeny.data.RenderableVector;
 import org.forester.archaeopteryx.tools.Blast;
 import org.forester.archaeopteryx.tools.ImageLoader;
 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
+import org.forester.io.writers.SequenceWriter;
 import org.forester.phylogeny.Phylogeny;
 import org.forester.phylogeny.PhylogenyMethods;
 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
@@ -5064,7 +5065,14 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                     StringBuilder sb = new StringBuilder();
                     if ( n.getNodeData().isHasSequence()
                             && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
-                        data.add( n.getNodeData().getSequence().getMolecularSequence() );
+                        if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
+                            sb.append( SequenceWriter.toFasta( n.getNodeData().getSequence().getName(),  n.getNodeData().getSequence().getMolecularSequence(), 60 )  );
+                        }
+                        else {
+                            sb.append( SequenceWriter.toFasta( n.getName(),  n.getNodeData().getSequence().getMolecularSequence(), 60 )  );
+                             
+                        }
+                        data.add( sb.toString() + "\n" );
                     }
                     break;
                 case SEQUENCE_ACC:
index 327f955..0477cd2 100644 (file)
@@ -38,6 +38,31 @@ public class SequenceWriter {
         }
         return sb;
     }
+    
+    public static StringBuilder toFasta( final String name, final String mol_seq, final int width ) {
+        final StringBuilder sb = new StringBuilder();
+        sb.append( ">" );
+        sb.append( name );
+        sb.append( ForesterUtil.LINE_SEPARATOR );
+        if ( ( width < 1 ) || ( width >= mol_seq.length() ) ) {
+            sb.append( mol_seq );
+        }
+        else {
+            final int lines = mol_seq.length() / width;
+            final int rest =mol_seq.length() - ( lines * width );
+            for( int i = 0; i < lines; ++i ) {
+                sb.append( mol_seq, i * width, width );
+                if ( i < ( lines - 1 ) ) {
+                    sb.append( ForesterUtil.LINE_SEPARATOR );
+                }
+            }
+            if ( rest > 0 ) {
+                sb.append( ForesterUtil.LINE_SEPARATOR );
+                sb.append( mol_seq, lines * width, rest );
+            }
+        }
+        return sb;
+    }
 
     public static void toFasta( final Sequence seq, final Writer w, final int width ) throws IOException {
         w.write( ">" );