Search in sources :

Example 11 with FilteredAlignment

use of beast.evolution.alignment.FilteredAlignment in project beast2 by CompEvol.

the class AlignmentListInputEditor method splitItem.

// replaceItem
void splitItem() {
    int[] selected = getTableRowSelection();
    if (selected.length == 0) {
        JOptionPane.showMessageDialog(this, "Select partitions to split, before hitting the split button");
        return;
    }
    String[] options = { "{1,2} + 3", "{1,2} + 3 frame 2", "{1,2} + 3 frame 3", "1 + 2 + 3", "1 + 2 + 3 frame 2", "1 + 2 + 3 frame 3" };
    String option = (String) JOptionPane.showInputDialog(null, "Split selected alignments into partitions", "Option", JOptionPane.WARNING_MESSAGE, null, options, "1 + 2 + 3");
    if (option == null) {
        return;
    }
    String[] filters = null;
    String[] ids = null;
    if (option.equals(options[0])) {
        filters = new String[] { "1::3,2::3", "3::3" };
        ids = new String[] { "_1,2", "_3" };
    } else if (option.equals(options[1])) {
        filters = new String[] { "1::3,3::3", "2::3" };
        ids = new String[] { "_1,2", "_3" };
    } else if (option.equals(options[2])) {
        filters = new String[] { "2::3,3::3", "1::3" };
        ids = new String[] { "_1,2", "_3" };
    } else if (option.equals(options[3])) {
        filters = new String[] { "1::3", "2::3", "3::3" };
        ids = new String[] { "_1", "_2", "_3" };
    } else if (option.equals(options[4])) {
        filters = new String[] { "2::3", "3::3", "1::3" };
        ids = new String[] { "_1", "_2", "_3" };
    } else if (option.equals(options[5])) {
        filters = new String[] { "3::3", "1::3", "2::3" };
        ids = new String[] { "_1", "_2", "_3" };
    } else {
        return;
    }
    for (int i = selected.length - 1; i >= 0; i--) {
        int rowNr = selected[i];
        Alignment alignment = alignments.remove(rowNr);
        getDoc().delAlignmentWithSubnet(alignment);
        try {
            List<Alignment> newAlignments = new ArrayList<>();
            for (int j = 0; j < filters.length; j++) {
                FilteredAlignment f = new FilteredAlignment();
                f.initByName("data", alignment, "filter", filters[j], "dataType", alignment.dataTypeInput.get());
                f.setID(alignment.getID() + ids[j]);
                getDoc().addAlignmentWithSubnet(f, getDoc().beautiConfig.partitionTemplate.get());
                newAlignments.add(f);
            }
            alignments.addAll(newAlignments);
            partitionCount = alignments.size();
            tableData = null;
            initTableData();
            if (newAlignments.size() == 2) {
                link(TREE_COLUMN, alignments.size() - 1, alignments.size() - 2);
            } else {
                link(TREE_COLUMN, alignments.size() - 2, alignments.size() - 3);
                tableData = null;
                initTableData();
                link(TREE_COLUMN, alignments.size() - 1, alignments.size() - 2);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    refreshPanel();
}
Also used : FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Alignment(beast.evolution.alignment.Alignment) ArrayList(java.util.ArrayList) FilteredAlignment(beast.evolution.alignment.FilteredAlignment)

Example 12 with FilteredAlignment

use of beast.evolution.alignment.FilteredAlignment in project beast2 by CompEvol.

the class FilteredAlignmentTest method testRangeFiltered.

@Test
public void testRangeFiltered() throws Exception {
    Alignment data = getAlignment();
    FilteredAlignment data2 = new FilteredAlignment();
    data2.initByName("data", data, "filter", "1-9");
    assertEquals(9, data2.getSiteCount());
    assertEquals(9, data2.getPatternCount());
    data2.initByName("data", data, "filter", "2-9");
    assertEquals(8, data2.getSiteCount());
    assertEquals(8, data2.getPatternCount());
    data2.initByName("data", data, "filter", "10-");
    assertEquals(7, data2.getSiteCount());
    data2.initByName("data", data, "filter", "-10");
    assertEquals(10, data2.getSiteCount());
    data2.initByName("data", data, "filter", "-");
    assertEquals(16, data2.getSiteCount());
    data2.initByName("data", data, "filter", "2-5,7-10");
    assertEquals(8, data2.getSiteCount());
    assertEquals(8, data2.getPatternCount());
}
Also used : Alignment(beast.evolution.alignment.Alignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Test(org.junit.Test)

Example 13 with FilteredAlignment

use of beast.evolution.alignment.FilteredAlignment in project beast2 by CompEvol.

the class FilteredAlignmentTest method testFilteredFileredAlignment.

@Test
public void testFilteredFileredAlignment() throws Exception {
    Alignment data1 = getAlignment();
    FilteredAlignment data2 = new FilteredAlignment();
    data2.initByName("data", data1, "filter", "2:16:2");
    FilteredAlignment data3 = new FilteredAlignment();
    // , "ascertained", true, "excludeto", 1);
    data3.initByName("data", data2, "filter", "-");
    assertEquals(alignmentToString(data2, 0), alignmentToString(data3, 0));
    assertEquals(alignmentToString(data2, 1), alignmentToString(data3, 1));
    FilteredAlignment data4 = new FilteredAlignment();
    data4.initByName("data", data3, "filter", "-", "ascertained", true, "excludeto", 1);
    assertEquals(alignmentToString(data2, 0), alignmentToString(data4, 0));
    assertEquals(alignmentToString(data2, 1), alignmentToString(data4, 1));
}
Also used : Alignment(beast.evolution.alignment.Alignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Test(org.junit.Test)

Example 14 with FilteredAlignment

use of beast.evolution.alignment.FilteredAlignment in project beast2 by CompEvol.

the class FilteredAlignmentTest method testIteratorFiltered.

@Test
public void testIteratorFiltered() throws Exception {
    Alignment data = getAlignment();
    FilteredAlignment data2 = new FilteredAlignment();
    data2.initByName("data", data, "filter", "1:16:2");
    assertEquals(8, data2.getSiteCount());
    assertEquals(8, data2.getPatternCount());
    int iPattern = data2.getPatternIndex(0);
    int[] pattern = data2.getPattern(iPattern);
    assertEquals(0, pattern[0]);
    assertEquals(0, pattern[1]);
    data2.initByName("data", data, "filter", "2:16:2");
    assertEquals(8, data2.getSiteCount());
    iPattern = data2.getPatternIndex(0);
    pattern = data2.getPattern(iPattern);
    assertEquals(0, pattern[0]);
    assertEquals(1, pattern[1]);
    data2.initByName("data", data, "filter", "1:10:2");
    assertEquals(5, data2.getSiteCount());
    data2.initByName("data", data, "filter", "1::3");
    assertEquals(6, data2.getSiteCount());
    data2.initByName("data", data, "filter", "2::3");
    assertEquals(5, data2.getSiteCount());
    data2.initByName("data", data, "filter", "::");
    assertEquals(16, data2.getSiteCount());
    data2.initByName("data", data, "filter", "2:5:");
    assertEquals(4, data2.getSiteCount());
    data2.initByName("data", data, "filter", ":5:");
    assertEquals(5, data2.getSiteCount());
    data2.initByName("data", data, "filter", "1::3,2::3");
    assertEquals(11, data2.getSiteCount());
    // System.out.println(alignmentToString(data2, 1));
    data2.initByName("data", data, "filter", "3::3");
    assertEquals(5, data2.getSiteCount());
// System.out.println(alignmentToString(data2, 1));
}
Also used : Alignment(beast.evolution.alignment.Alignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Test(org.junit.Test)

Example 15 with FilteredAlignment

use of beast.evolution.alignment.FilteredAlignment in project beast2 by CompEvol.

the class FilteredAlignmentTest method testReordered.

@Test
public void testReordered() throws Exception {
    // make sure the order of sites is not affected by filtering
    Alignment data = getAlignmentNoTInHuman();
    data.setID("data");
    // second sequence not in alphabetical order
    FilteredAlignment data2 = new FilteredAlignment();
    data2.initByName("data", data, "filter", "3:6:1");
    System.out.println("human\t" + alignmentToString(data2, 0) + "\n1chimp\t" + alignmentToString(data2, 1));
    assertEquals(alignmentToString(data2, 0), "AACC");
    assertEquals(alignmentToString(data2, 1), "GTAC");
    // first sequence not in alphabetical order
    FilteredAlignment data3 = new FilteredAlignment();
    data3.initByName("data", data, "filter", "11:14:1");
    System.out.println("human\t" + alignmentToString(data3, 0) + "\n1chimp\t" + alignmentToString(data3, 1));
    assertEquals(alignmentToString(data3, 0), "GGAA");
    assertEquals(alignmentToString(data3, 1), "GTAC");
    // first sequence not in alphabetical order, repeat site
    FilteredAlignment data4 = new FilteredAlignment();
    data4.initByName("data", data, "filter", "3:16:4");
    System.out.println("human\t" + alignmentToString(data4, 0) + "\n1chimp\t" + alignmentToString(data4, 1));
    assertEquals(alignmentToString(data4, 0), "ACGA");
    assertEquals(alignmentToString(data4, 1), "GGGG");
    // first and second sequence not in alphabetical order
    FilteredAlignment data5 = new FilteredAlignment();
    data5.initByName("data", data, "filter", "4:14:3");
    System.out.println("human\t" + alignmentToString(data5, 0) + "\n1chimp\t" + alignmentToString(data5, 1));
    assertEquals(alignmentToString(data5, 0), "ACGA");
    assertEquals(alignmentToString(data5, 1), "TGCA");
}
Also used : Alignment(beast.evolution.alignment.Alignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Test(org.junit.Test)

Aggregations

FilteredAlignment (beast.evolution.alignment.FilteredAlignment)18 Alignment (beast.evolution.alignment.Alignment)17 Test (org.junit.Test)7 TaxonSet (beast.evolution.alignment.TaxonSet)4 ArrayList (java.util.ArrayList)4 BEASTInterface (beast.core.BEASTInterface)3 Taxon (beast.evolution.alignment.Taxon)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 CompoundDistribution (beast.core.util.CompoundDistribution)2 GenericTreeLikelihood (beast.evolution.likelihood.GenericTreeLikelihood)2 MRCAPrior (beast.math.distributions.MRCAPrior)2 ParametricDistribution (beast.math.distributions.ParametricDistribution)2 XMLParser (beast.util.XMLParser)2 IOException (java.io.IOException)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 SAXException (org.xml.sax.SAXException)2 NexusParser (babel.util.NexusParser)1