Exemplo n.º 1
0
Arquivo: nj.py Projeto: trmznt/genaf
def func_callback( query, user ):

    from fatools.lib.analytics.dist import get_distance_matrix
    from fatools.lib.analytics.nj import plot_nj

    haplotype_sets = query.get_filtered_haplotype_sets()

    dm = get_distance_matrix(haplotype_sets)

    dbh = query.dbh
    fso_dir = get_fso_temp_dir(user.login)

    tip_label = query.options.get('tip_label', 'S')
    label_callback = {
        'S': lambda x: dbh.get_sample_by_id(x).code,
        'I': None,
        'C': lambda x: dbh.get_sample_by_id(x).location.country,
        '1': lambda x: dbh.get_sample_by_id(x).location.level1,
        '2': lambda x: dbh.get_sample_by_id(x).location.level2,
        '3': lambda x: dbh.get_sample_by_id(x).location.level3,
        '4': lambda x: dbh.get_sample_by_id(x).location.level4,
    }

    tree_type = { 'F': 'fan', 'R': 'radial', 'U': 'unrooted'}[query.options.get('tree_type', 'F')]

    njplot_png = plot_nj(dm, fso_dir.abspath, 'png',
            label_callback = label_callback[tip_label], tree_type=tree_type)
    njplot_pdf = plot_nj(dm, fso_dir.abspath, 'pdf',
            label_callback = label_callback[tip_label], tree_type=tree_type)

    options = { 'png_plot': fso.get_urlpath(njplot_png),
                'pdf_plot': fso.get_urlpath(njplot_pdf) }

    html, code = format_output( options )

    return {    'custom': None,
                'options': None,
                'title': 'Neighbor-Joining (NJ) Tree Result',
                'html': html,
                'jscode': code,
                'refs': [
                    'Paradis E., Claude J. & Strimmer K. (2004) '
                    'APE: analyses of phylogenetics and evolution in R language. '
                    '<em>Bioinformatics</em>, <strong>20</strong>: 289-290',
                    '<a href="http://ape-package.ird.fr/">APE website</a>'
                ],
    }
Exemplo n.º 2
0
Arquivo: mca.py Projeto: trmznt/genaf
def func_callback( query, user ):

    from fatools.lib.analytics.dist import get_distance_matrix, null_distance
    from fatools.lib.analytics.ca import mca, plot_pca, format_data

    dimension = 2

    haplotype_sets = query.get_filtered_haplotype_sets()
    dm = get_distance_matrix(haplotype_sets, null_distance)
    mca_res = mca(dm)

    fso_dir = get_fso_temp_dir(user.login)
    plotfile_urls = []

    for (ax, ay) in combinations(range( dimension ), 2):
        plotfile = fso_dir.abspath + '/' + 'pcoa-%d-%d' % (ax, ay)
        plot_png = plot_pca(mca_res, dm, ax, ay, plotfile + '.png')
        plot_pdf = plot_pca(mca_res, dm, ax, ay, plotfile + '.pdf')
        plotfile_urls.append( (fso.get_urlpath(plot_png), fso.get_urlpath(plot_pdf)) )

    mca_data = format_data(mca_res, dm)
    data_file = fso_dir.abspath + '/' + 'mca-data.txt'
    with open(data_file, 'w') as outfile:
        for r in mca_data:
            outfile.write( '\t'.join( r ) )
            outfile.write( '\n' )

    options = { 'plotfile_urls': plotfile_urls, 'data_file': fso.get_urlpath(data_file) }

    html, code = format_output( (mca_res, dm), options )

    return {    'custom': None,
                'options': None,
                'title': 'Multiple Correspondence Analysis (MCA) Result',
                'html': html,
                'jscode': code,
                'refs': [
                    'L&ecirc;, S., Josse, J. &amp; Husson, F. (2008). '
                    'FactoMineR: An R Package for Multivariate Analysis. '
                    '<em>Journal of Statistical Software</em>. <strong>25(1)</strong>. pp. 1-18.',
                    '<a href="http://factominer.free.fr/">FactoMineR website</a>'
                ],
    }
Exemplo n.º 3
0
Arquivo: pcoa.py Projeto: trmznt/genaf
def func_callback( query, user ):

    from fatools.lib.analytics.dist import get_distance_matrix
    from fatools.lib.analytics.ca import pcoa, plot_pca, format_data

    dimension = 2

    haplotype_sets = query.get_filtered_haplotype_sets()

    dm = get_distance_matrix(haplotype_sets)
    pca_res = pcoa(dm, dim = dimension)

    fso_dir = get_fso_temp_dir(user.login)
    plotfile_urls = []

    for (ax, ay) in combinations(range( dimension ), 2):
        plotfile = fso_dir.abspath + '/' + 'pcoa-%d-%d' % (ax, ay)
        plot_png = plot_pca(pca_res, dm, ax, ay, plotfile + '.png')
        plot_pdf = plot_pca(pca_res, dm, ax, ay, plotfile + '.pdf')
        plotfile_urls.append( (fso.get_urlpath(plot_png), fso.get_urlpath(plot_pdf)) )

    pca_data = format_data(pca_res, dm)
    data_file = fso_dir.abspath + '/' + 'pcoa-data.txt'
    with open(data_file, 'w') as outfile:
        for r in pca_data:
            outfile.write( '\t'.join( r ) )
            outfile.write( '\n' )

    options = { 'plotfile_urls': plotfile_urls, 'data_file': fso.get_urlpath(data_file) }

    html, code = format_output( (pca_res, dm), options )

    return {    'custom': None,
                'options': None,
                'title': 'Principal Coordinate Analysis (PCoA) Result',
                'html': html,
                'jscode': code,
    }

    return ('Principal Coordinate Analysis (PCoA) Result', html, code)