From: cmzmasek@gmail.com Date: Tue, 3 Dec 2013 01:11:01 +0000 (+0000) Subject: inprogress X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8d7714f05175781a79428b01bd6125ec3dc66538;p=jalview.git inprogress --- diff --git a/forester/java/src/org/forester/application/check_fasta.java b/forester/java/src/org/forester/application/check_fasta.java index 2bac934..dd312e8 100644 --- a/forester/java/src/org/forester/application/check_fasta.java +++ b/forester/java/src/org/forester/application/check_fasta.java @@ -96,10 +96,15 @@ public final class check_fasta { try { final List seqs = FastaParser.parse( new FileInputStream( infile ) ); final Map names = new HashMap(); + int duplicates = 0; for( final Sequence seq : seqs ) { - procSeq( infile.toString(), names, seq ); + if ( procSeq( infile.toString(), names, seq ) ) { + ++duplicates; + } + } + if ( duplicates > 0 ) { + SequenceWriter.writeSeqs( seqs, outfile, SEQ_FORMAT.FASTA, 60 ); } - SequenceWriter.writeSeqs( seqs, outfile, SEQ_FORMAT.FASTA, 60 ); } catch ( final IOException e ) { ForesterUtil.fatalError( PRG_NAME, e.getMessage() ); @@ -107,17 +112,20 @@ public final class check_fasta { } } - private static void procSeq( final String infile, final Map names, final Sequence seq ) { + private static boolean procSeq( final String infile, final Map names, final Sequence seq ) { + boolean duplicate = false; final String name = seq.getIdentifier(); if ( !names.containsKey( name ) ) { names.put( name, ( short ) 1 ); } else { + duplicate = true; final short i = names.get( name ); ( ( BasicSequence ) seq ).setIdentifier( name + "_" + i ); names.put( name, ( short ) ( i + 1 ) ); - System.out.println( " " + infile + i + ": " + seq.getIdentifier() ); + System.out.println( " " + infile + " " + i + ": " + seq.getIdentifier() ); } + return duplicate; } private static void argumentsError() {