X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fio%2Fwriters%2FSequenceWriter.java;h=8e6ef959bdff145501e4f31d0ab7b2431523d65c;hb=7a7a89b113566b2749f1e8e4fbb3064241145201;hp=0477cd2dc90796c431e7bc2a790421a9f709ebde;hpb=29575d635845a5e0e43286b08ac9086b6dbc1700;p=jalview.git diff --git a/forester/java/src/org/forester/io/writers/SequenceWriter.java b/forester/java/src/org/forester/io/writers/SequenceWriter.java index 0477cd2..8e6ef95 100644 --- a/forester/java/src/org/forester/io/writers/SequenceWriter.java +++ b/forester/java/src/org/forester/io/writers/SequenceWriter.java @@ -15,30 +15,9 @@ public class SequenceWriter { } public static StringBuilder toFasta( final Sequence seq, final int width ) { - final StringBuilder sb = new StringBuilder(); - sb.append( ">" ); - sb.append( seq.getIdentifier().toString() ); - sb.append( ForesterUtil.LINE_SEPARATOR ); - if ( ( width < 1 ) || ( width >= seq.getLength() ) ) { - sb.append( seq.getMolecularSequence() ); - } - else { - final int lines = seq.getLength() / width; - final int rest = seq.getLength() - ( lines * width ); - for( int i = 0; i < lines; ++i ) { - sb.append( seq.getMolecularSequence(), i * width, width ); - if ( i < ( lines - 1 ) ) { - sb.append( ForesterUtil.LINE_SEPARATOR ); - } - } - if ( rest > 0 ) { - sb.append( ForesterUtil.LINE_SEPARATOR ); - sb.append( seq.getMolecularSequence(), lines * width, rest ); - } - } - return sb; + return toFasta( seq.getIdentifier(), seq.getMolecularSequenceAsString(), width ); } - + public static StringBuilder toFasta( final String name, final String mol_seq, final int width ) { final StringBuilder sb = new StringBuilder(); sb.append( ">" ); @@ -49,16 +28,16 @@ public class SequenceWriter { } else { final int lines = mol_seq.length() / width; - final int rest =mol_seq.length() - ( lines * width ); + final int rest = mol_seq.length() - ( lines * width ); for( int i = 0; i < lines; ++i ) { - sb.append( mol_seq, i * width, width ); + sb.append( mol_seq, i * width, ( i + 1 ) * 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 ); + sb.append( mol_seq, lines * width, mol_seq.length() ); } } return sb;