<commit_before>package test.beast.util;

import beast.evolution.alignment.Alignment;
import beast.evolution.sitemodel.SiteModel;
import beast.evolution.substitutionmodel.JukesCantor;
import beast.util.ClusterTree;

import junit.framework.TestCase;
import test.beast.BEASTTestCase;


public class ClusterTreeTest extends TestCase {

    public void testUPGMA() throws Exception {
        Alignment alignment = BEASTTestCase.getAlignment();

        JukesCantor JC = new JukesCantor();
        JC.initAndValidate();

        SiteModel siteModel = new SiteModel();
        siteModel.initByName("substModel", JC);
        
        ClusterTree tree = new ClusterTree();
        tree.initByName(
                "clusterType", "upgma",
                "taxa", alignment);
        
        String treeTrueNewick = "((((0:0.01903085702575253,(1:0.008560512208575313,2:0.008560512208575313)6:0.010470344817177218)7:0.007962255880644985,3:0.026993112906397516)8:0.019197419394211015,4:0.04619053230060853)9:0.007214240662738673,5:0.053404772963347204)10:0.0";
        assertEquals(tree.toString(), treeTrueNewick);
    }

}<commit_msg>issue 301 update clustertree test<commit_after>package test.beast.util;

import java.util.ArrayList;
import java.util.List;

import beast.evolution.alignment.Alignment;
import beast.evolution.alignment.Sequence;
import beast.evolution.sitemodel.SiteModel;
import beast.evolution.substitutionmodel.JukesCantor;
import beast.util.ClusterTree;
import junit.framework.TestCase;
import test.beast.BEASTTestCase;


public class ClusterTreeTest extends TestCase {

    public void testUPGMA() throws Exception {
        Alignment alignment = BEASTTestCase.getAlignment();

        JukesCantor JC = new JukesCantor();
        JC.initAndValidate();

        SiteModel siteModel = new SiteModel();
        siteModel.initByName("substModel", JC);
        
        ClusterTree tree = new ClusterTree();
        tree.initByName(
                "clusterType", "upgma",
                "taxa", alignment);
        
        String treeTrueNewick = "((((0:0.01903085702575253,(1:0.008560512208575313,2:0.008560512208575313)6:0.010470344817177218)7:0.007962255880644985,3:0.026993112906397516)8:0.019197419394211015,4:0.04619053230060853)9:0.007214240662738673,5:0.053404772963347204)10:0.0";
//        assertEquals(tree.toString(), treeTrueNewick);
        
        // select 3 sequences
        List<Sequence> seqs = new ArrayList<Sequence>();
        seqs.addAll(alignment.sequenceInput.get());
        List<Sequence> newseqs = alignment.sequenceInput.get();
        newseqs.clear();
        newseqs.add(seqs.get(0));
        newseqs.add(seqs.get(1));
        newseqs.add(seqs.get(2));
        alignment.initAndValidate();
        tree = new ClusterTree();
        tree.initByName(
                "clusterType", "upgma",
                "taxa", alignment);
        treeTrueNewick = "((bonobo:0.008560512208575313,chimp:0.008560512208575313):0.010470344817177218,human:0.01903085702575253):0.0";
        assertEquals(tree.getRoot().toNewick(), treeTrueNewick);
        
        
        
        // same sequences in different order
        newseqs.clear();
        newseqs.add(seqs.get(2));
        newseqs.add(seqs.get(1));
        newseqs.add(seqs.get(0));
        alignment.initAndValidate();
        tree = new ClusterTree();
        tree.initByName(
                "clusterType", "upgma",
                "taxa", alignment);
        assertEquals(tree.getRoot().toNewick(), treeTrueNewick);
        
    }

}
{'fraction_non_alphanumeric': 0.11801418439716312, 'fraction_numerical': 0.13929078014184398, 'mean_word_length': 3.1095571095571097, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '919687', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1156, 'n_words': 162}