File: ReaderUtils.java

package info (click to toggle)
alter-sequence-alignment 1.3.3%2Bdfsg-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 1,132 kB
  • sloc: java: 6,623; xml: 60; makefile: 5; sh: 2
file content (53 lines) | stat: -rwxr-xr-x 2,030 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 *  This file is part of ALTER.
 *
 *  ALTER is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  ALTER is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with ALTER.  If not, see <http://www.gnu.org/licenses/>.
 */

package reader;

import parser.ParseException;
import types.Sequence;

/**
 * Provides static methods common to every reader.
 * @author Daniel Gomez Blanco
 * @version 1.0
 */

public class ReaderUtils
{
    /**
     * Replaces match characters with the character in the same position of the
     * first sequence of the MSA.
     * @param seq Current sequence.
     * @param first First sequence of the MSA.
     * @throws ParseException If a match character is trying to be replaced by a "?", "." or "-" character.
     */
    public static void replaceMatch(Sequence seq, Sequence first) throws ParseException
    {
        if (seq.getData().contains("."))
            //Lanzar excepcion si el caracter esta en la primera secuencia
            if (seq == first)
                throw new ParseException("Match character \".\" in first sequence of MSA.");
            else
                for(int j=0;j<seq.getData().length();j++)
                    if (seq.getData().charAt(j) == '.')
                        if (first.getData().charAt(j) == '?'
                            || first.getData().charAt(j) == '-')
                            throw new ParseException("Match character \".\" cannot be replaced by \"?\" or \"-\".");
                        else
                            seq.replaceChar(j, first.getData().charAt(j));
    }
}