# Path: cmonkey/tools/util.py
# def read_ratios(result_dir):
#     csvpath = os.path.join(result_dir, 'ratios.tsv.gz')
#     df = pandas.read_csv(csvpath, index_col=0, sep='\t')
#     df.index = map(str, df.index)
#     return df


import json
import os
import string
import cmonkey.database as cm2db
from sqlalchemy import func, and_
from cmonkey.tools.util import read_ratios
        cm_string += '<span class="gaggle-species">' + species + '</span>\n'
        cm_string += '<div class="gaggle-namelist"><ol>\n'

        cluster_conds = [c.column_name.name for c in session.query(cm2db.ColumnMember).filter(
            and_(cm2db.ColumnMember.cluster == cluster, cm2db.ColumnMember.iteration == iteration))]
        for col_name in cluster_conds:
            cm_string += "<li>" + col_name + "</li>\n"
        cm_string += "</ol></div>"

        # motifs
        m_string = ''

        for m in session.query(cm2db.MotifInfo).filter(
                and_(cm2db.MotifInfo.cluster == cluster, cm2db.MotifInfo.iteration == iteration)):
            m_string += '<div class="gaggle-data motifs">\n'
            m_string += '<span class="gaggle-name">%s motif %d (%s)</span>\n' % (runinfo.organism, m.motif_num, m.seqtype)
            m_string += '<span class="gaggle-species">' + species + '</span>\n'
            m_string += '<div class="gaggle-matrix-tsv">\n'
            m_string += "\tPOSITION\tA\tC\tG\tT\n"

            for r in m.pssm_rows:
                m_string += "%d\t%f\t%f\t%f\t%f\n" % (r.row, r.a, r.c, r.g, r.t)
            m_string += "</div></div>\n"

        s = templ.substitute(cluster=cluster, row_members=rm_string, column_members=cm_string, motifs=m_string)
        with open(os.path.join(output_dir, 'cluster-%03d.html' % cluster), 'w') as outfile:
            outfile.write(s)


def cluster_expressions_to_json_file(session, result_dir, output_dir):

# Path: cmonkey/tools/util.py
# def read_ratios(result_dir):
#     csvpath = os.path.join(result_dir, 'ratios.tsv.gz')
#     df = pandas.read_csv(csvpath, index_col=0, sep='\t')
#     df.index = map(str, df.index)
#     return df


# Path: cmonkey/tools/export.py
import json
import os
import string
import cmonkey.database as cm2db
from sqlalchemy import func, and_
from cmonkey.tools.util import read_ratios

        cm_string += '<span class="gaggle-species">' + species + '</span>\n'
        cm_string += '<div class="gaggle-namelist"><ol>\n'

        cluster_conds = [c.column_name.name for c in session.query(cm2db.ColumnMember).filter(
            and_(cm2db.ColumnMember.cluster == cluster, cm2db.ColumnMember.iteration == iteration))]
        for col_name in cluster_conds:
            cm_string += "<li>" + col_name + "</li>\n"
        cm_string += "</ol></div>"

        # motifs
        m_string = ''

        for m in session.query(cm2db.MotifInfo).filter(
                and_(cm2db.MotifInfo.cluster == cluster, cm2db.MotifInfo.iteration == iteration)):
            m_string += '<div class="gaggle-data motifs">\n'
            m_string += '<span class="gaggle-name">%s motif %d (%s)</span>\n' % (runinfo.organism, m.motif_num, m.seqtype)
            m_string += '<span class="gaggle-species">' + species + '</span>\n'
            m_string += '<div class="gaggle-matrix-tsv">\n'
            m_string += "\tPOSITION\tA\tC\tG\tT\n"

            for r in m.pssm_rows:
                m_string += "%d\t%f\t%f\t%f\t%f\n" % (r.row, r.a, r.c, r.g, r.t)
            m_string += "</div></div>\n"

        s = templ.substitute(cluster=cluster, row_members=rm_string, column_members=cm_string, motifs=m_string)
        with open(os.path.join(output_dir, 'cluster-%03d.html' % cluster), 'w') as outfile:
            outfile.write(s)


def cluster_expressions_to_json_file(session, result_dir, output_dir):

    ratios = read_ratios(result_dir)