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;
68 public StringBuffer asSimpleText() {
69 return new StringBuffer( getName() );
73 public StringBuffer asText() {
74 final StringBuffer sb = new StringBuffer( getName() );
76 sb.append( getLength() );
77 if ( !ForesterUtil.isEmpty( getId() ) ) {
81 if ( getConfidence() != CONFIDENCE_DEFAULT ) {
83 sb.append( getConfidence() );
90 public PhylogenyData copy() {
91 if ( getId() == null ) {
92 return new ProteinDomain( getName(), getFrom(), getTo(), getConfidence() );
94 return new ProteinDomain( getName(), getFrom(), getTo(), getId(), getConfidence() );
97 public double getConfidence() {
101 public int getFrom() {
105 public String getId() {
109 public int getLength() {
110 return ( ( getTo() - getFrom() ) + 1 );
113 public String getName() {
122 public boolean isEqual( final PhylogenyData protein_domain ) {
123 if ( protein_domain == null ) {
126 if ( !( protein_domain instanceof ProteinDomain ) ) {
129 else if ( ( ( ProteinDomain ) protein_domain ).getLength() != getLength() ) {
132 else if ( !( ( ProteinDomain ) protein_domain ).getName().equals( getName() ) ) {
139 public StringBuffer toNHX() {
140 throw new UnsupportedOperationException();
144 public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
145 writer.write( ForesterUtil.LINE_SEPARATOR );
146 writer.write( indentation );
147 if ( getId() != null ) {
148 PhylogenyDataUtil.appendOpen( writer,
149 PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_DOMAIN,
150 PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_PROT_DOMAIN_FROM,
152 PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_PROT_DOMAIN_TO,
154 PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_PROT_DOMAIN_CONFIDENCE,
155 getConfidence() + "",
156 PhyloXmlMapping.IDENTIFIER,
160 PhylogenyDataUtil.appendOpen( writer,
161 PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_DOMAIN,
162 PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_PROT_DOMAIN_FROM,
164 PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_PROT_DOMAIN_TO,
166 PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_PROT_DOMAIN_CONFIDENCE,
167 getConfidence() + "" );
169 writer.write( getName() );
170 PhylogenyDataUtil.appendClose( writer, PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECTURE_DOMAIN );
174 public String toString() {
175 return asText().toString();