~jon-hill/supertree-toolkit/visualisations

« back to all changes in this revision

Viewing changes to stk/supertree_toolkit.py

  • Committer: Jon Hill
  • Date: 2013-09-24 16:34:30 UTC
  • mfrom: (108.1.16 bug_fixes)
  • Revision ID: jon.hill@imperial.ac.uk-20130924163430-jcgij3mc90g66hnh
Fixing a number of bugs and adding comments to a lot of the schema

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
import datetime
46
46
import gtk
47
47
from indent import *
 
48
import unicodedata
 
49
from stk_internals import *
48
50
 
49
51
#plt.ion()
50
52
 
361
363
            volume  = a.xpath("volume/string_value")[0].text
362
364
            bib_dict['volume']=volume
363
365
        if (a.xpath("pages/string_value")):
364
 
            pages   = a.xpath("pages/string_value")[0].text
365
 
            bib_dict['pages']=pages 
 
366
            firstpage, lastpage = bibparse.process_pages(a.xpath("pages/string_value")[0].text)
 
367
            bib_dict['firstpage']=firstpage
 
368
            bib_dict['lastpage']=lastpage
366
369
        if (a.xpath("issue/string_value")):
367
370
            issue   = a.xpath("issue/string_value")[0].text
368
371
            bib_dict['issue']=issue
459
462
            publisher  = i.xpath("publisher/string_value")[0].text
460
463
            bib_dict['publisher']=publisher
461
464
        if (i.xpath("pages/string_value")):
462
 
            pages   = i.xpath("pages/string_value")[0].text
463
 
            bib_dict['pages']=pages 
 
465
            firstpage, lastpage = bibparse.process_pages(i.xpath("pages/string_value")[0].text)
 
466
            bib_dict['firstpage']=firstpage
 
467
            bib_dict['lastpage']=lastpage
464
468
        if (i.xpath("doi/string_value")):
465
469
            doi     = i.xpath("doi/string_value")[0].text
466
470
            bib_dict['doi']=doi
508
512
            publisher  = i.xpath("publisher/string_value")[0].text
509
513
            bib_dict['publisher']=publisher
510
514
        if (i.xpath("pages/string_value")):
511
 
            pages   = i.xpath("pages/string_value")[0].text
512
 
            bib_dict['pages']=pages 
 
515
            firstpage, lastpage = bibparse.process_pages(i.xpath("pages/string_value")[0].text)
 
516
            bib_dict['firstpage']=firstpage
 
517
            bib_dict['lastpage']=lastpage
513
518
        if (i.xpath("doi/string_value")):
514
519
            doi     = i.xpath("doi/string_value")[0].text
515
520
            bib_dict['doi']=doi
519
524
 
520
525
        bib_it = bibitem.BibItem(bib_dict)
521
526
        bibliography.add_item(bib_it)
522
 
 
 
527
    
523
528
    bibliography.output(fout=filename,formato=format,verbose=False)
524
529
    
525
530
    return
793
798
        parsed.
794
799
    """
795
800
    f = open(filename)
796
 
    content = f.read()                 # read entire file into memory
 
801
    content = f.read() # read entire file into memory
797
802
    f.close()    
 
803
 
 
804
    # translate to ascii
 
805
    content = str(replace_utf(content))
 
806
    
798
807
    # Need to add checks on the file. Problems include:
799
808
# TNT: outputs Phyllip format or something - basically a Newick
800
809
# string without commas, so add 'em back in
1058
1067
    # should raise exception here
1059
1068
    return characters
1060
1069
 
 
1070
def get_characters_used(XML):
 
1071
    """ Return a sorted, unique array of all character names used
 
1072
    in this dataset
 
1073
    """
 
1074
 
 
1075
    c_ = []
 
1076
 
 
1077
    xml_root = _parse_xml(XML)
 
1078
    find = etree.XPath("//character")
 
1079
    chars = find(xml_root)
 
1080
 
 
1081
    for c in chars:
 
1082
        name = c.attrib['name']
 
1083
        ctype = c.attrib['type']
 
1084
        c_.append((name,ctype))
 
1085
 
 
1086
    characters = _uniquify(c_) 
 
1087
    characters.sort(key=lambda x: x[0].lower())
 
1088
 
 
1089
    return characters
1061
1090
 
1062
1091
def get_character_numbers(XML):
1063
1092
    """ Return the number of trees that use each character
3007
3036
    """ Parse a string containing multiple trees 
3008
3037
        to a list of p4 tree objects
3009
3038
    """
3010
 
    
 
3039
   
3011
3040
    try:
3012
3041
        p4.var.doRepairDupedTaxonNames = 2
3013
3042
        p4.var.warnReadNoFile = False