-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# coding: utf8 | ||
""" | ||
Recreate glottolog data files from the current version published at http://glottolog.org | ||
""" | ||
from __future__ import unicode_literals | ||
import re | ||
|
||
from ete3 import Tree | ||
from pyglottolog.api import Glottolog | ||
|
||
|
||
def tree(glottocodes, gl_repos): | ||
label_pattern = re.compile("'[^\[]+\[([a-z0-9]{4}[0-9]{4})[^']*'") | ||
|
||
def rename(n): | ||
n.name = label_pattern.match(n.name).groups()[0] | ||
n.length = 1 | ||
|
||
glottocodes = set(glottocodes) | ||
glottocodes_in_global_tree = set() | ||
languoids = {} | ||
families = [] | ||
for lang in Glottolog(gl_repos).languoids(): | ||
if not lang.lineage: # a top-level node | ||
if not lang.category.startswith('Pseudo '): | ||
families.append(lang) | ||
languoids[lang.id] = lang | ||
|
||
glob = Tree() | ||
glob.name = 'glottolog_global' | ||
|
||
for family in sorted(families): | ||
node = family.newick_node(nodes=languoids) | ||
node.visit(rename) | ||
langs_in_tree = set(n.name for n in node.walk()) | ||
langs_selected = glottocodes.intersection(langs_in_tree) | ||
if not langs_selected: | ||
continue | ||
|
||
tree = Tree("({0});".format(node.newick), format=3) | ||
tree.name = 'glottolog_{0}'.format(family.id) | ||
if family.level.name == 'family': | ||
tree.prune([n.encode('ascii') for n in langs_selected]) | ||
glottocodes_in_global_tree = glottocodes_in_global_tree.union( | ||
set(n.name for n in tree.traverse())) | ||
else: | ||
glottocodes_in_global_tree = glottocodes_in_global_tree.union(langs_in_tree) | ||
glob.add_child(tree) | ||
|
||
# global | ||
nodes = glottocodes_in_global_tree.intersection(glottocodes) | ||
glob.prune([n.encode('ascii') for n in nodes]) | ||
return glob.write(format=9), nodes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<%inherit file="../${context.get('request').registry.settings.get('clld.app_template', 'app.mako')}"/> | ||
<%namespace name="util" file="../util.mako"/> | ||
<%! active_menu_item = "phylogenys" %> | ||
<%block name="title">Phylogeny ${ctx.name}</%block> | ||
<%! from clld_phylogeny_plugin.tree import Tree %> | ||
<%! from clld_phylogeny_plugin.interfaces import ITree %> | ||
<% tree = req.registry.queryUtility(ITree)(ctx, req) %> | ||
|
||
<%block name="head"> | ||
${Tree.head(req)|n} | ||
<link href="${request.static_url('clld:web/static/css/select2.css')}" | ||
rel="stylesheet"> | ||
<script src="${request.static_url('clld:web/static/js/select2.js')}"></script> | ||
</%block> | ||
|
||
<div class="row-fluid"> | ||
<div class="span8"> | ||
<h2>${title()}</h2> | ||
|
||
% if ctx.description: | ||
<div class="alert alert-info">${ctx.description}</div> | ||
% endif | ||
% if tree.parameters: | ||
<div class="alert alert-success"> | ||
The tree has been pruned to only contain leaf nodes with values for | ||
the selected variables. For the full tree click | ||
<a href="${req.resource_url(ctx)}">here</a>. | ||
</div> | ||
% endif | ||
<div> | ||
<form action="${req.resource_url(ctx)}"> | ||
<fieldset> | ||
<p> | ||
You may combine these ${_('Parameters').lower()} with another | ||
one. | ||
Start typing the ${_('Parameter').lower()} name or number in | ||
the field below. | ||
</p> | ||
${ms(request, combination=tree).render()|n} | ||
<button class="btn" type="submit">Submit</button> | ||
</fieldset> | ||
</form> | ||
</div> | ||
${tree.render()} | ||
</div> | ||
|
||
<div class="span4"> | ||
<% ca = h.get_adapter(h.interfaces.IRepresentation, ctx, req, ext='description.html') %> | ||
% if ca: | ||
<div class="well well-small"> | ||
${ca.render(ctx, req)|n} | ||
</div> | ||
% endif | ||
% if tree.parameters: | ||
<div class="accordion" id="values-acc" data-spy="affix" data-offset-top="0" | ||
style="margin-right: 10px;"> | ||
% for parameter in tree.parameters: | ||
<div class="accordion-group"> | ||
<div class="accordion-heading"> | ||
<a class="accordion-toggle" data-toggle="collapse" | ||
data-parent="#values-acc" href="#acc-${parameter.id}"> | ||
${parameter.name} | ||
</a> | ||
</div> | ||
<div id="acc-${parameter.id}" | ||
class="accordion-body collapse${' in' if loop.first else ''}"> | ||
<div class="accordion-inner"> | ||
${h.get_adapter(h.interfaces.IRepresentation, parameter, req, ext='valuetable.html').render(parameter, req)|n} | ||
</div> | ||
</div> | ||
</div> | ||
% endfor | ||
</div> | ||
% endif | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters