2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2014 Christian M. Zmasek
6 // Copyright (C) 2014 Sanford-Burnham Medical Research Institute
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 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25 package org.forester.msa;
27 import java.util.HashMap;
29 public final class DeleteableMsa extends BasicMsa {
31 private int _length = 0;
32 private int _mapped_col_positions[] = null;
33 private int _mapped_row_positions[] = null;
34 private int _seqs = 0;
35 private HashMap<String, Integer> _seq_id_to_row_map = null;
37 public DeleteableMsa( final BasicMsa msa ) {
39 _mapped_col_positions = new int[ msa.getLength() ];
40 _mapped_row_positions = new int[ msa.getNumberOfSequences() ];
41 for( int i = 0; i < _mapped_col_positions.length; ++i ) {
42 _mapped_col_positions[ i ] = i;
44 for( int i = 0; i < _mapped_row_positions.length; ++i ) {
45 _mapped_row_positions[ i ] = i;
47 _seq_id_to_row_map = new HashMap<String, Integer>();
48 for( int row = 0; row < msa.getNumberOfSequences(); ++row ) {
49 _seq_id_to_row_map.put( msa.getIdentifier( row ), row );
51 _length = msa.getLength();
52 _seqs = msa.getNumberOfSequences();
55 public void deleteColumn( final int col ) {
56 if ( col >= _length || col < 0 ) {
57 throw new IllegalArgumentException( "column " + col + " is out of range" );
59 for( int c = col; c < _length - 1; ++c ) {
60 _mapped_col_positions[ c ] = _mapped_col_positions[ c + 1 ];
65 public void deleteRow( final int row ) {
66 if ( row >= _seqs || row < 0 ) {
67 throw new IllegalArgumentException( "row " + row + " is out of range" );
69 for( int r = row; r < _seqs - 1; ++r ) {
70 _mapped_row_positions[ r ] = _mapped_row_positions[ r + 1 ];
75 public void deleteRow( final String id ) {
77 for( int r = 0; r < getNumberOfSequences(); ++r ) {
78 if ( getIdentifier( r ).equals( id ) ) {
84 throw new IllegalArgumentException( "id [" + id + "] not found" );
90 public String getIdentifier( final int row ) {
91 return super.getIdentifier( _mapped_row_positions[ row ] );
95 public int getLength() {
100 public int getNumberOfSequences() {
105 public char getResidueAt( final int row, final int col ) {
106 return super.getResidueAt( _mapped_row_positions[ row ], _mapped_col_positions[ col ] );
110 public void setIdentifier( final int row, final String id ) {
111 super.setIdentifier( _mapped_row_positions[ row ], id );
115 public void setResidueAt( final int row, final int col, final char residue ) {
116 super.setResidueAt( _mapped_row_positions[ row ], _mapped_col_positions[ col ], residue );