From 29575d635845a5e0e43286b08ac9086b6dbc1700 Mon Sep 17 00:00:00 2001 From: cmzmasek Date: Thu, 24 Jan 2013 07:01:08 +0000 Subject: [PATCH] in progress --- .../src/org/forester/archaeopteryx/TreePanel.java | 10 +++++++- .../org/forester/io/writers/SequenceWriter.java | 25 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/forester/java/src/org/forester/archaeopteryx/TreePanel.java b/forester/java/src/org/forester/archaeopteryx/TreePanel.java index 740e0d0..18128a0 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreePanel.java +++ b/forester/java/src/org/forester/archaeopteryx/TreePanel.java @@ -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: diff --git a/forester/java/src/org/forester/io/writers/SequenceWriter.java b/forester/java/src/org/forester/io/writers/SequenceWriter.java index 327f955..0477cd2 100644 --- a/forester/java/src/org/forester/io/writers/SequenceWriter.java +++ b/forester/java/src/org/forester/io/writers/SequenceWriter.java @@ -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( ">" ); -- 1.7.10.2