def get_subtype_reference_alignment_tree(region,
                                         subtype='B',
                                         refname='HXB2',
                                         type='nuc',
                                         VERBOSE=0,
                                         format='newick'):
    '''Get filename of consensus of subtype reference alignment'''
    from Bio import Phylo
    from hivwholeseq.cross_sectional.filenames import (
        get_subtype_reference_alignment_tree_filename)

    fn = get_subtype_reference_alignment_tree_filename(region,
                                                       subtype=subtype,
                                                       refname=refname,
                                                       type=type,
                                                       VERBOSE=VERBOSE,
                                                       format=format)
    if format == 'newick':
        return Phylo.read(fn, format)
    
    from hivwholeseq.utils.tree import tree_from_json
    from hivwholeseq.utils.generic import read_json
    return tree_from_json(read_json(fn))
            ali = get_subtype_reference_alignment(region,
                                                  subtype=subtype,
                                                  refname=refname,
                                                  type=alitype,
                                                  VERBOSE=VERBOSE)

            if VERBOSE >= 2:
                print 'Calculate tree'
            tree = build_tree_fasttree(ali, VERBOSE=VERBOSE)


            if VERBOSE >= 2:
                print 'Save to file, newick'
            fn_out = get_subtype_reference_alignment_tree_filename(region,
                                                               subtype=subtype,
                                                               refname=refname,
                                                               type=alitype,
                                                               VERBOSE=VERBOSE,
                                                               format='newick')
            Phylo.write([tree], fn_out, 'newick')


            if VERBOSE >= 2:
                print 'Annotate tree (for JSON format)'
            from hivwholeseq.utils.nehercook.ancestral import ancestral_sequences
            a = ancestral_sequences(tree, ali, alphabet='ACGT-N', copy_tree=False,
                                    attrname='sequence', seqtype='str')
            a.calc_ancestral_sequences()
            del a


            if VERBOSE >= 2: