2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
26 package org.forester.phylogeny.data;
28 import java.io.IOException;
29 import java.io.Writer;
31 import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
32 import org.forester.util.ForesterUtil;
34 public class ProteinDomain implements PhylogenyData {
36 final public static double CONFIDENCE_DEFAULT = 0.0;
37 final public static String IDENTIFIER_DEFAULT = "";
38 final private String _name;
39 final private int _from;
40 final private int _to;
41 final private String _id;
42 final private double _confidence;
44 public ProteinDomain( final String name, final int from, final int to ) {
45 this( name, from, to, ProteinDomain.IDENTIFIER_DEFAULT, ProteinDomain.CONFIDENCE_DEFAULT );
48 public ProteinDomain( final String name, final int from, final int to, final double confidence ) {
49 this( name, from, to, ProteinDomain.IDENTIFIER_DEFAULT, confidence );
52 public ProteinDomain( final String name, final int from, final int to, final String id ) {
53 this( name, from, to, id, ProteinDomain.CONFIDENCE_DEFAULT );
56 public ProteinDomain( final String name, final int from, final int to, final String id, final double confidence ) {
57 if ( ( from >= to ) || ( to < 0 ) ) {
58 throw new IllegalArgumentException( "attempt to create protein domain from " + from + " to " + to );
64 _confidence = confidence;
67 public StringBuffer asSimpleText() {
68 return new StringBuffer( getName() );
71 public StringBuffer asText() {
72 final StringBuffer sb = new StringBuffer( getName() );
74 sb.append( getLength() );
75 if ( !ForesterUtil.isEmpty( getId() ) ) {
79 if ( getConfidence() != CONFIDENCE_DEFAULT ) {
81 sb.append( getConfidence() );
87 public PhylogenyData copy() {
88 if ( getId() == null ) {
89 return new ProteinDomain( getName(), getFrom(), getTo(), getConfidence() );
91 return new ProteinDomain( getName(), getFrom(), getTo(), getId(), getConfidence() );
94 public double getConfidence() {
98 public int getFrom() {
102 public String getId() {
106 public int getLength() {
107 return ( getTo() - getFrom() + 1 );
110 public String getName() {
118 public boolean isEqual( final PhylogenyData protein_domain ) {
119 if ( protein_domain == null ) {
122 if ( !( protein_domain instanceof ProteinDomain ) ) {
125 else if ( ( ( ProteinDomain ) protein_domain ).getLength() != getLength() ) {
128 else if ( !( ( ProteinDomain ) protein_domain ).getName().equals( getName() ) ) {
134 public StringBuffer toNHX() {
135 throw new UnsupportedOperationException();
138 public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
139 writer.write( ForesterUtil.LINE_SEPARATOR );
140 writer.write( indentation );
141 if ( getId() != null ) {
142 PhylogenyDataUtil.appendOpen( writer,
143 PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_DOMAIN,
144 PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_PROT_DOMAIN_FROM,
146 PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_PROT_DOMAIN_TO,
148 PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_PROT_DOMAIN_CONFIDENCE,
149 getConfidence() + "",
150 PhyloXmlMapping.IDENTIFIER,
154 PhylogenyDataUtil.appendOpen( writer,
155 PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_DOMAIN,
156 PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_PROT_DOMAIN_FROM,
158 PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_PROT_DOMAIN_TO,
160 PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_PROT_DOMAIN_CONFIDENCE,
161 getConfidence() + "" );
163 writer.write( getName() );
164 PhylogenyDataUtil.appendClose( writer, PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_DOMAIN );
168 public String toString() {
169 return asText().toString();