(no commit message)
[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: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.msa;
27
28 import org.forester.sequence.BasicSequence;
29 import org.forester.sequence.MolecularSequence;
30
31 public final class ResampleableMsa extends BasicMsa {
32
33     private int[] _resampled_column_positions = null;
34
35     public ResampleableMsa( final BasicMsa msa ) {
36         super( msa );
37     }
38
39     @Override
40     final public char getResidueAt( final int row, final int col ) {
41         if ( _resampled_column_positions != null ) {
42             return super.getResidueAt( row, _resampled_column_positions[ col ] );
43         }
44         return super.getResidueAt( row, col );
45     }
46
47     final public void resample( final int[] resampled_column_positions ) {
48         if ( resampled_column_positions.length != getLength() ) {
49             throw new IllegalArgumentException( "illegal attempt to use " + resampled_column_positions.length
50                                                 + " resampled column positions on msa of length " + getLength() );
51         }
52         _resampled_column_positions = resampled_column_positions;
53     }
54
55     @Override
56     final public void setResidueAt( final int row, final int col, final char residue ) {
57         throw new NoSuchMethodError( "illegal attempt to set residue in resampleable msa" );
58     }
59
60     @Override
61     public MolecularSequence getSequence( final int row ) {
62         return new BasicSequence( getIdentifier( row ), getSequenceAsString( row ).toString(), getType() );
63     }
64 }