コード例 #1
0
    def test_get_GLS(self):
        phy = PhyBo(self.inputfile, output_dir=self.tmp)

        # test default scenario
        phy.get_GLS()

        # check for weight in one of the scenarios
        assert phy.gls['w-1-1']['2:1'][1] == 9
        assert phy.gls['w-1-1']['8:1'][1] == 2

        # test restriction scenario
        phy.get_GLS(mode='restriction', force=True)
        assert phy.gls['r-3']['12:1'][1] == 3
        assert phy.gls['r-3']['8:1'][1] == 2

        # test topdown, somehow, the algorithmic ordering leads to unstable
        # outputs, this should be fixed, but for testing, it is not unexpected
        # right now, which is why I change to the less than construct for the
        # moment
        phy.get_GLS(mode='topdown', force=True)
        assert phy.gls['t-3']['29:3'][1] < 3
        assert phy.gls['t-3']['8:1'][1] == 2

        glm = list(phy.stats.keys())[0]
        phy.get_stats(glm)
コード例 #2
0
    def test_get_GLS(self):
        phy = PhyBo(self.inputfile, output_dir=self.tmp)
        
        # test default scenario
        phy.get_GLS()

        # check for weight in one of the scenarios
        assert phy.gls['w-1-1']['2:1'][1] == 9
        assert phy.gls['w-1-1']['8:1'][1] == 2

        # test restriction scenario
        phy.get_GLS(mode='restriction', force=True)
        assert phy.gls['r-3']['12:1'][1] == 3
        assert phy.gls['r-3']['8:1'][1] == 2

        # test topdown, somehow, the algorithmic ordering leads to unstable
        # outputs, this should be fixed, but for testing, it is not unexpected
        # right now, which is why I change to the less than construct for the
        # moment
        phy.get_GLS(mode='topdown', force=True)
        assert phy.gls['t-3']['29:3'][1] < 3
        assert phy.gls['t-3']['8:1'][1] == 2

        glm = list(phy.stats.keys())[0]
        phy.get_stats(glm)
コード例 #3
0
    def test_utils(self):
        try:
            import scipy.stats
        except ImportError:
            return

        with patch('lingpy.compare._phylogeny.utils.sps', new=SPS()):
            phy = PhyBo(self.ifile, output_dir=self.tmp.as_posix())
            phy.analyze()
            get_acs(phy, phy.best_model)
            tstats(phy, phy.best_model, return_dists=True)

            check_stats([phy.best_model], phy, filename=os.path.join(self.tmp.as_posix(),
                'test'), pprint=False)
コード例 #4
0
ファイル: test__phylogeny.py プロジェクト: LinguList/lingpy
    def test_utils(self):
        try:
            import scipy.stats
        except ImportError:
            return

        with patch('lingpy.compare._phylogeny.utils.sps', new=SPS()):
            phy = PhyBo(self.ifile, output_dir=self.tmp.as_posix())
            phy.analyze()
            get_acs(phy, phy.best_model)
            tstats(phy, phy.best_model, return_dists=True)

            check_stats([phy.best_model], phy,
                        filename=os.path.join(self.tmp.as_posix(), 'test'),
                        pprint=False)
コード例 #5
0
ファイル: construct_mln.py プロジェクト: kewok/altaic
def construct_mln(tsv_file, newick_tree):
	tre = PhyBo(str(tsv_file)+'.tsv', degree=175, missing=0, tree=newick_tree)
	tre.analyze(runs = 'default', plot_dists = True, gpl = 1, push_gains = True, missing_data = 0, homoplasy = 0.05)
	# get the minimal lateral network. Assume, for now a threshold of 1% of the total number of words to count as a borrowing
	tre.get_MLN(tre.best_model, method='mr', threshold=10) 
	# plot the MLN
	tre.plot_MLN(tre.best_model)
	return(tre.best_model)
コード例 #6
0
ファイル: test__phylogeny.py プロジェクト: kadster/lingpy
def test_utils(mocker, SPS, ifile, tmppath):
    try:
        import scipy.stats
    except ImportError:  # pragma: no cover
        return

    mocker.patch('lingpy.compare._phylogeny.utils.sps', new=SPS)
    phy = PhyBo(ifile, output_dir=str(tmppath))
    phy.analyze()
    get_acs(phy, phy.best_model)
    tstats(phy, phy.best_model, return_dists=True)

    check_stats([phy.best_model],
                phy,
                filename=str(tmppath / 'test'),
                pprint=False)
コード例 #7
0
 def test_plot(self):
     phy = PhyBo(self.inputfile, output_dir=self.tmp)
     phy.get_GLS()
     glm = list(phy.stats.keys())[0]
     phy.plot_concept_evolution(glm)
     phy.plot_GLS(glm)
     phy.plot_ACS(glm)
     phy.get_MLN(glm)
     phy.graph = defaultdict(lambda: Graph())
     phy.plot_MLN(glm)
     phy.analyze()
     phy.get_IVSD()
     phy.get_MSN()
     glm = list(phy.geograph.keys())[0]
     phy.geograph[glm] = MagicMock(
         edges=lambda **kw: [(MagicMock(), MagicMock(), defaultdict(lambda: 2))])
     phy._meta['conf'] = dict(linescale=2, groups_colors=defaultdict(lambda: 'a'))
     phy.plot_MSN(glm)
コード例 #8
0
    def test_plot(self):
        phy = PhyBo(self.inputfile, output_dir=self.tmp.as_posix())
        phy.get_GLS()
        glm = list(phy.stats.keys())[0]
        phy.plot_GLS(glm)
        phy.plot_ACS(glm)

        for method in ['bc', 'td', 'mr']:
            phy.get_MLN(glm, method=method)

        phy.plot_MLN(glm)
        phy.plot_MLN_3d(glm)
        phy.analyze(runs=[('weighted', (2, 1))], output_gml=True,
                    output_plot=True)
        phy.get_IVSD()
        phy.get_ACS(phy.best_model)
        phy.get_MSN(phy.best_model)
        phy.get_MSN(phy.best_model, deep_nodes=True)
        phy.plot_MSN(phy.best_model, conf=phy.conf)
        phy.plot_two_concepts('I', '15:2', '16:2')
        edge1, edge2 = list(phy.graph[phy.best_model].edges())[0]
        phy.get_edge(phy.best_model, edge1, edge2)
        phy.get_edge(phy.best_model, 'Beijing', 'Shanghai')
        phy.get_edge(phy.best_model, edge1, edge2, msn=True)
        phy.get_PDC('w-2-1', aligned_output=True)
        phy.plot_concept_evolution(phy.best_model, concept="I")
コード例 #9
0
ファイル: workflow.py プロジェクト: xrotwang/lingpy
print('[i] Carrying out alignment analyses.')
msa.align(
        method='library',
        output = True        
        )

print('[i] Writing results to wordlist file.')
msa.output('qlc',filename='DOGON_alignments')

print("[i] Plotting the alignments.")
msa.output('html',filename='DOGON')

print("[i] Starting with the borrowing detection.")
from lingpy.compare.phylogeny import PhyBo
tre = PhyBo('DOGON_lexstat.qlc',
        ref='lexstatid', degree=180)

tre.analyze(runs='weighted', mode='mixed')

print("[i] Plotting the results.")
# make nice labels for the taxon-names
labels = dict(
        [(t,t[:9]) for t in tre.taxa]
        )
tre.get_MLN(tre.best_model)
tre.plot_MLN(
        tre.best_model,
        filename='DOGON',
        fileformat='svg',
        figsize=(15,7),
        labels=labels
コード例 #10
0
 def test_plot(self):
     phy = PhyBo(self.inputfile, output_dir=self.tmp)
     phy.get_GLS()
     glm = list(phy.stats.keys())[0]
     phy.plot_concept_evolution(glm)
     phy.plot_GLS(glm)
     phy.plot_ACS(glm)
     phy.get_MLN(glm)
     phy.graph = defaultdict(lambda: Graph())
     phy.plot_MLN(glm)
     phy.analyze()
     phy.get_IVSD()
     phy.get_MSN()
     glm = list(phy.geograph.keys())[0]
     phy.geograph[glm] = MagicMock(edges=lambda **kw: [(MagicMock(
     ), MagicMock(), defaultdict(lambda: 2))])
     phy._meta['conf'] = dict(linescale=2,
                              groups_colors=defaultdict(lambda: 'a'))
     phy.plot_MSN(glm)
コード例 #11
0
ファイル: workflow.py プロジェクト: tjade273/lingpy
           cols=['concepts', 'taxa', 'counterpart', 'tokens', 'lexstatid'])

print('[i] Loading data into the Alignments class.')
msa = Alignments('DOGON_lexstat.qlc', ref='lexstatid')

print('[i] Carrying out alignment analyses.')
msa.align(method='library', output=True)

print('[i] Writing results to wordlist file.')
msa.output('qlc', filename='DOGON_alignments')

print("[i] Plotting the alignments.")
msa.output('html', filename='DOGON')

print("[i] Starting with the borrowing detection.")
from lingpy.compare.phylogeny import PhyBo

tre = PhyBo('DOGON_lexstat.qlc', ref='lexstatid', degree=180)

tre.analyze(runs='weighted', mode='mixed')

print("[i] Plotting the results.")
# make nice labels for the taxon-names
labels = dict([(t, t[:9]) for t in tre.taxa])
tre.get_MLN(tre.best_model)
tre.plot_MLN(tre.best_model,
             filename='DOGON',
             fileformat='svg',
             figsize=(15, 7),
             labels=labels)
コード例 #12
0
    def setup(self):

        self.phy = PhyBo('.../test_data/sagart.qlc')
コード例 #13
0
ファイル: test_phylogeny.py プロジェクト: kadster/lingpy
def test_plot(inputfile, mocker, Bmp, Sp, Plt, tmppath):
    mocker.patch('lingpy.compare.phylogeny.mpl', new=mocker.MagicMock())
    mocker.patch('lingpy.compare.phylogeny.gls2gml', new=mocker.MagicMock())
    mocker.patch('lingpy.compare.phylogeny.plot_tree', new=mocker.MagicMock())
    mocker.patch('lingpy.compare.phylogeny.bmp', new=Bmp)
    mocker.patch('lingpy.compare.phylogeny.plt', new=Plt)
    mocker.patch('lingpy.compare.phylogeny.sp', new=Sp)

    phy = PhyBo(inputfile, output_dir=str(tmppath))
    phy.get_GLS()
    glm = list(phy.stats.keys())[0]
    phy.plot_GLS(glm)
    phy.plot_ACS(glm)

    for method in ['bc', 'td', 'mr']:
        phy.get_MLN(glm, method=method)

    phy.plot_MLN(glm)
    phy.plot_MLN_3d(glm)
    phy.analyze(runs=[('weighted', (2, 1))], output_gml=True, output_plot=True)
    phy.get_IVSD()
    phy.get_ACS(phy.best_model)
    phy.get_MSN(phy.best_model)
    phy.get_MSN(phy.best_model, deep_nodes=True)
    phy.plot_MSN(phy.best_model, conf=phy.conf)
    phy.plot_two_concepts('I', '15:2', '16:2')
    edge1, edge2 = list(phy.graph[phy.best_model].edges())[0]
    phy.get_edge(phy.best_model, edge1, edge2)
    phy.get_edge(phy.best_model, 'Beijing', 'Shanghai')
    phy.get_edge(phy.best_model, edge1, edge2, msn=True)
    phy.get_PDC('w-2-1', aligned_output=True)
    phy.plot_concept_evolution(phy.best_model, concept="I")