def get_subtype_reference_alignment_allele_frequencies(region,
                                                       subtype='B',
                                                       VERBOSE=0,
                                                       refname='HXB2',
                                                       type='nuc'):
    '''Get the entropy of a large subtype reference alignment'''
    import numpy as np

    fn = get_subtype_reference_alignment_allele_frequencies_filename(
        region, subtype=subtype, refname=refname, type=type, VERBOSE=VERBOSE)

    return np.load(fn)
def get_subtype_reference_alignment_allele_frequencies(region, subtype='B', VERBOSE=0,
                                                       refname='HXB2',
                                                       type='nuc'):
    '''Get the entropy of a large subtype reference alignment'''
    import numpy as np

    fn = get_subtype_reference_alignment_allele_frequencies_filename(region,
                                                                     subtype=subtype,
                                                                     refname=refname,
                                                                     type=type,
                                                                     VERBOSE=VERBOSE)

    return np.load(fn)
        alphabet_bio = ambiguous_dna
    else:
        alphabet = alphaa
        alphabet_bio = protein

    for region in regions:
        if VERBOSE >= 1:
            print region


        if use_save:
            if VERBOSE >= 2:
                print 'Get allele frequencies'
            fn_in = get_subtype_reference_alignment_allele_frequencies_filename(region,
                                                                      subtype=subtype,
                                                                      refname=refname,
                                                                      type=alitype,
                                                                      VERBOSE=VERBOSE)
            afs = np.load(fn_in)


            if VERBOSE >= 2:
                print 'Calculate consensus'
            
            consm = alphabet[afs[:5].argmax(axis=0)]
            consrec = SeqRecord(Seq(''.join(consm), alphabet_bio),
                                id='consensus_subtype'+subtype+'_refto_'+refname,
                                name='consensus_subtype'+subtype+'_refto_'+refname,
                                description=('Consensus of subtype '+subtype+
                                             ' reference alignment to '+refname),
                               )
        alphabet = alpha
        alphabet_bio = ambiguous_dna
    else:
        alphabet = alphaa
        alphabet_bio = protein

    for region in regions:
        if VERBOSE >= 1:
            print region

        if use_save:
            if VERBOSE >= 2:
                print 'Get allele frequencies'
            fn_in = get_subtype_reference_alignment_allele_frequencies_filename(
                region,
                subtype=subtype,
                refname=refname,
                type=alitype,
                VERBOSE=VERBOSE)
            afs = np.load(fn_in)

            if VERBOSE >= 2:
                print 'Calculate consensus'

            consm = alphabet[afs[:5].argmax(axis=0)]
            consrec = SeqRecord(
                Seq(''.join(consm), alphabet_bio),
                id='consensus_subtype' + subtype + '_refto_' + refname,
                name='consensus_subtype' + subtype + '_refto_' + refname,
                description=('Consensus of subtype ' + subtype +
                             ' reference alignment to ' + refname),
            )