X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fphylogeny%2Fdata%2FAccession.java;h=fe11d8de3af7c682f1f9b6cd72189fbb05bb8557;hb=5cad5dbd4f9e8cf09a123d4ee490cf314c05fd2f;hp=3a565abc7edc6a8dee6789de251a64f073336c5c;hpb=2ae595537adc997e493ff35f5ab5d2e80709bac2;p=jalview.git diff --git a/forester/java/src/org/forester/phylogeny/data/Accession.java b/forester/java/src/org/forester/phylogeny/data/Accession.java index 3a565ab..fe11d8d 100644 --- a/forester/java/src/org/forester/phylogeny/data/Accession.java +++ b/forester/java/src/org/forester/phylogeny/data/Accession.java @@ -32,20 +32,74 @@ import org.forester.io.parsers.nhx.NHXtags; import org.forester.io.parsers.phyloxml.PhyloXmlMapping; import org.forester.util.ForesterUtil; -public final class Accession implements PhylogenyData { +public final class Accession implements PhylogenyData, Comparable { - final private String _value; + final private String _comment; final private String _source; - final private String _value_source; + final private String _source_value; + final private String _value; + + public enum Source { + NCBI, REFSEQ, UNIPROT, GI, EMBL, ENSEMBL, UNKNOWN; + + @Override + public String toString() { + switch ( this ) { + case NCBI: + return "ncbi"; + case REFSEQ: + return "refseq"; + case UNIPROT: + return "uniprot"; + case GI: + return "gi"; + case EMBL: + return "embl"; + case ENSEMBL: + return "ensembl"; + case UNKNOWN: + return "unknown"; + default: + throw new IllegalArgumentException(); + } + } + } + + public Accession( final String value ) { + _value = value; + _source = ""; + _comment = ""; + _source_value = value; + } public Accession( final String value, final String source ) { _value = value; _source = source; + _comment = ""; + if ( source != null ) { + _source_value = source + value; + } + else { + _source_value = value; + } + } + + public Accession( final String value, final Source source ) { + _value = value; + _source = source.toString(); + _comment = ""; + _source_value = source + value; + } + + public Accession( final String value, final String source, final String comment ) { + _value = value; + _source = source; + _comment = comment; if ( source != null ) { - _value_source = value + source; + _source_value = source + value; } else { - _value_source = value; + _source_value = value; } } @@ -58,17 +112,29 @@ public final class Accession implements PhylogenyData { public StringBuffer asText() { final StringBuffer sb = new StringBuffer(); if ( !ForesterUtil.isEmpty( getSource() ) ) { - sb.append( "[" ); sb.append( getSource() ); - sb.append( "] " ); + sb.append( ": " ); } sb.append( getValue() ); + if ( !ForesterUtil.isEmpty( getComment() ) ) { + sb.append( " (" ); + sb.append( getComment() ); + sb.append( ")" ); + } return sb; } @Override + public int compareTo( final Accession o ) { + if ( equals( o ) ) { + return 0; + } + return _source_value.compareTo( o._source_value ); + } + + @Override public PhylogenyData copy() { - return new Accession( new String( getValue() ), new String( getSource() ) ); + return new Accession( getValue(), getSource() ); } @Override @@ -88,6 +154,10 @@ public final class Accession implements PhylogenyData { } } + public String getComment() { + return _comment; + } + public String getSource() { return _source; } @@ -98,10 +168,7 @@ public final class Accession implements PhylogenyData { @Override public int hashCode() { - //if ( getSource() != null ) { - // return ( getSource() + getValue() ).hashCode(); - // } - return _value_source.hashCode(); + return _source_value.hashCode(); } @Override @@ -131,20 +198,44 @@ public final class Accession implements PhylogenyData { @Override public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException { if ( ForesterUtil.isEmpty( getSource() ) ) { - PhylogenyDataUtil.appendElement( writer, - PhyloXmlMapping.ACCESSION, - getValue(), - PhyloXmlMapping.ACCESSION_SOURCE_ATTR, - "unknown", - indentation ); + if ( ForesterUtil.isEmpty( getComment() ) ) { + PhylogenyDataUtil.appendElement( writer, + PhyloXmlMapping.ACCESSION, + getValue(), + PhyloXmlMapping.ACCESSION_SOURCE_ATTR, + "unknown", + indentation ); + } + else { + PhylogenyDataUtil.appendElement( writer, + PhyloXmlMapping.ACCESSION, + getValue(), + PhyloXmlMapping.ACCESSION_SOURCE_ATTR, + "unknown", + PhyloXmlMapping.ACCESSION_COMMENT_ATTR, + getComment(), + indentation ); + } } else { - PhylogenyDataUtil.appendElement( writer, - PhyloXmlMapping.ACCESSION, - getValue(), - PhyloXmlMapping.ACCESSION_SOURCE_ATTR, - getSource(), - indentation ); + if ( ForesterUtil.isEmpty( getComment() ) ) { + PhylogenyDataUtil.appendElement( writer, + PhyloXmlMapping.ACCESSION, + getValue(), + PhyloXmlMapping.ACCESSION_SOURCE_ATTR, + getSource(), + indentation ); + } + else { + PhylogenyDataUtil.appendElement( writer, + PhyloXmlMapping.ACCESSION, + getValue(), + PhyloXmlMapping.ACCESSION_SOURCE_ATTR, + getSource(), + PhyloXmlMapping.ACCESSION_COMMENT_ATTR, + getComment(), + indentation ); + } } }