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: https://sites.google.com/site/cmzmasek/home/software/forester
26 package org.forester.evoinference.matrix.character;
28 import java.io.IOException;
29 import java.io.Writer;
31 public interface CharacterStateMatrix<S> {
33 public boolean containsCharacter( final String character );
35 public boolean containsIdentifier( final String identifier );
37 public CharacterStateMatrix<S> copy();
39 public String getCharacter( int character_index );
41 public int getCharacterIndex( final String character );
43 public String getIdentifier( int identifier_index );
45 public int getIdentifierIndex( final String identifier );
47 public int getNumberOfCharacters();
49 public int getNumberOfIdentifiers();
51 public S getState( final int identifier_index, final int character_index );
53 public S getState( final String identifier, final int character_index );
55 public S getState( final String identifier, final String character );
57 public boolean isEmpty();
59 public CharacterStateMatrix<S> pivot();
61 public void setCharacter( int character_index, final String character );
63 public void setIdentifier( int identifier_index, final String identifier );
65 public void setState( int identifier_index, int character_index, final S state );
67 public void setState( final String identifier, int character_index, final S state );
69 public void setState( final String identifier, final String character, final S state );
71 public void toWriter( final Writer writer ) throws IOException;
73 public void toWriter( final Writer writer, final Format format ) throws IOException;
76 * It is crucial that the order
77 * ABSENT, UNKNOWN, PRESENT not be changes since
78 * this determines the sort order.
81 static public enum BinaryStates {
82 ABSENT, UNKNOWN, PRESENT;
84 public char toChar() {
93 throw new RuntimeException( "unknown state: " + this );
97 public String toString() {
106 throw new RuntimeException( "unknown state: " + this );
110 public static enum Format {
111 PHYLIP, FORESTER, NEXUS_BINARY
114 static public enum GainLossStates {
115 GAIN, LOSS, UNCHANGED_PRESENT, UNCHANGED_ABSENT, UNKNOWN;
118 public String toString() {
124 case UNCHANGED_PRESENT:
126 case UNCHANGED_ABSENT:
131 throw new RuntimeException( "unknown state: " + this );
135 static public enum NucleotideStates {