# Path: seqcluster/libs/pysen.py
# def pysenMMean (x, y):


from operator import itemgetter
from  seqcluster.libs import pysen
from seqcluster.libs.classes import *
import numpy as np
import seqcluster.libs.logger as mylog
    data_loci.insert(0, best_loci)
    return data_loci


def peak_calling(clus_obj):
    """
    Run peak calling inside each cluster
    """
    new_cluster = {}
    for cid in clus_obj.clus:
        cluster = clus_obj.clus[cid]
        cluster.update()
        logger.debug("peak calling for %s" % cid)
        bigger = cluster.locimaxid
        # fn to get longer > 30 < 100 precursor
        # iterate by them mapping reads, detect peak, descart, start_again
        # give quantification of 'matures'
        if bigger in clus_obj.loci:
            s, e = min(clus_obj.loci[bigger].counts.keys()), max(clus_obj.loci[bigger].counts.keys())
            scale = min(s, e)
            logger.debug("bigger %s at %s-%s" % (bigger, s, e))
            dt = np.array([0] * (e - s + 12))
            for pos in clus_obj.loci[bigger].counts:
                ss = int(pos) - scale + 5
                dt[ss] += clus_obj.loci[bigger].counts[pos]
        x = np.array(range(0, len(dt)))
        logger.debug("x %s and y %s" % (x, dt))
        # tab = pd.DataFrame({'x': x, 'y': dt})
        # tab.to_csv( str(cid) + "peaks.csv", mode='w', header=False, index=False)
        if len(x) > 35 + 12:

# Path: seqcluster/libs/pysen.py
# def pysenMMean (x, y):


# Path: seqcluster/detect/description.py
from operator import itemgetter
from  seqcluster.libs import pysen
from seqcluster.libs.classes import *
import numpy as np
import seqcluster.libs.logger as mylog

    data_loci.insert(0, best_loci)
    return data_loci


def peak_calling(clus_obj):
    """
    Run peak calling inside each cluster
    """
    new_cluster = {}
    for cid in clus_obj.clus:
        cluster = clus_obj.clus[cid]
        cluster.update()
        logger.debug("peak calling for %s" % cid)
        bigger = cluster.locimaxid
        # fn to get longer > 30 < 100 precursor
        # iterate by them mapping reads, detect peak, descart, start_again
        # give quantification of 'matures'
        if bigger in clus_obj.loci:
            s, e = min(clus_obj.loci[bigger].counts.keys()), max(clus_obj.loci[bigger].counts.keys())
            scale = min(s, e)
            logger.debug("bigger %s at %s-%s" % (bigger, s, e))
            dt = np.array([0] * (e - s + 12))
            for pos in clus_obj.loci[bigger].counts:
                ss = int(pos) - scale + 5
                dt[ss] += clus_obj.loci[bigger].counts[pos]
        x = np.array(range(0, len(dt)))
        logger.debug("x %s and y %s" % (x, dt))
        # tab = pd.DataFrame({'x': x, 'y': dt})
        # tab.to_csv( str(cid) + "peaks.csv", mode='w', header=False, index=False)
        if len(x) > 35 + 12:

            peaks = pysen.pysenMMean(x, dt)