Debian Codegraph @

src/dr/evolution/alignment/CharSetAlignment.java

raw symbols SCIP
1 /*
2 * CharSetAlignment.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.evolution.alignment;
27
28 import dr.app.beauti.util.NexusApplicationImporter;
29 import dr.evolution.sequence.Sequence;
30
31 /**
32 * Created by IntelliJ IDEA.
33 * User: alexei
34 * Date: 1/08/11
35 * Time: 8:04 PM
36 * To change this template use File | Settings | File Templates.
37 */
38 public class CharSetAlignment extends SimpleAlignment {
39
40 public CharSetAlignment(NexusApplicationImporter.CharSet charset, Alignment parentAlignment) {
41 setId(charset.getName());
42
43 for (int i = 0; i < parentAlignment.getSequenceCount(); i++) {
44 Sequence sequence = parentAlignment.getSequence(i);
45 String sequenceString = parentAlignment.getAlignedSequenceString(i);
46
47 String filteredSequence = filter(charset, sequenceString);
48
49 addSequence(new Sequence(sequence.getTaxon(), filteredSequence));
50 }
51
52 setDataType(parentAlignment.getDataType());
53 }
54
55 private String filter(NexusApplicationImporter.CharSet charset, String sequenceString) {
56 StringBuilder filtered = new StringBuilder();
57 for (NexusApplicationImporter.CharSetBlock block : charset.getBlocks()) {
58 int toSite = block.getToSite();
59 if (toSite <= 0) {
60 toSite = sequenceString.length();
61 }
62 for (int i = block.getFromSite(); i <= toSite; i += block.getEvery()) {
63 // the -1 comes from the fact that charsets are indexed from 1 whereas strings are indexed from 0
64 filtered.append(sequenceString.charAt(i - 1));
65 }
66 }
67 return filtered.toString();
68 }
69
70 }