7476cadc83e9d69548f29166fb0b15a4aab417b3
[jalview.git] / forester / java / src / org / forester / msa / ResampleableMsa.java
1 // / $Id: ResampleableMsa.java,v 1.3 2010/12/13 18:59:48 cmzmasek Exp $
2 // forester -- software libraries and applications
3 // for genomics and evolutionary biology research.
4 //
5 // Copyright (C) 2010 Christian M Zmasek
6 // Copyright (C) 2010 Sanford-Burnham Medical Research Institute
7 // All rights reserved
8 // 
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.
13 //
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.
18 // 
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
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
25
26 package org.forester.msa;
27
28 public final class ResampleableMsa extends BasicMsa {
29
30     private int[] _resampled_column_positions = null;
31
32     public ResampleableMsa( final BasicMsa msa ) {
33         super( msa );
34     }
35
36     public void resample( final int[] resampled_column_positions ) {
37         if ( resampled_column_positions.length != getLength() ) {
38             _resampled_column_positions = null;
39             throw new IllegalArgumentException( "illegal attempt to use " + resampled_column_positions.length
40                     + " resampled column positions on msa of length " + getLength() );
41         }
42         _resampled_column_positions = resampled_column_positions;
43     }
44
45     @Override
46     public char getResidueAt( final int row, final int col ) {
47         if ( _resampled_column_positions != null ) {
48             return super.getResidueAt( row, _resampled_column_positions[ col ] );
49         }
50         return super.getResidueAt( row, col );
51     }
52
53     @Override
54     public void setResidueAt( final int row, final int col, final char residue ) {
55         throw new NoSuchMethodError( "illegal attempt to set residue in resampleable msa" );
56     }
57 }