<commit_before># Copyright (c) 2009-2016 <NAME> <<EMAIL>>
#
# This module is free software. You can redistribute it and/or modify it under 
# the terms of the MIT License, see the file COPYING included with this 
# distribution.

""" 
Module to compare DNA sequence motifs (positional frequency matrices)
"""

# Python imports
import sys
import os
from time import sleep
import random

# External imports
from scipy.stats import norm,entropy,chi2_contingency
from scipy.spatial import distance
from numpy import mean,std,array,sum

# GimmeMotifs imports
from gimmemotifs.motif import *
from gimmemotifs.config import *
from gimmemotifs.c_metrics import pwmscan,score
# pool import is at the bottom

# Try to import the fisim code, if it present
try:
    fisim_dir = "/usr/share/gimmemotifs/includes/fisim"
    if os.path.exists(fisim_dir):
        sys.path.append(fisim_dir)
        import fisim.Motif
except ImportError:
    pass

# Function that can be parallelized
def _get_all_scores(mc, motifs, dbmotifs, match, metric, combine, pval):
    scores = {}
    for m1 in motifs:
        scores[m1.id] = {}
        for m2 in dbmotifs:
            scores[m1.id][m2.id] = mc.compare_motifs(m1, m2, match, metric, combine, pval=pval)    
    return scores


def akl(x,y):
    """ Calcylates the average Kullback-Leibler similarity
    See Mahony,  2007
    """
    return 10 - (entropy(x,y) + entropy(y,x)) / 2.0

def chisq(x,y):
    return chi2_contingency([x, y])[1]

def ssd(x,y):
    """ Sum of squared distances 
    """
    return sum([(a-b)**2 for a,b in zip(x,y)] )

def seqcor(m1,m2):
    l1 = len(m1)
    l2 = len(m2)

    l = max(l1, l2)

    # Create random sequence<commit_msg>trying to figure out cause of travis error<commit_after># Copyright (c) 2009-2016 <NAME> <<EMAIL>>
#
# This module is free software. You can redistribute it and/or modify it under 
# the terms of the MIT License, see the file COPYING included with this 
# distribution.

""" 
Module to compare DNA sequence motifs (positional frequency matrices)
"""

# Python imports
import sys
import os
from time import sleep
import random
import logging

# External imports
from scipy.stats import norm,entropy,chi2_contingency
from scipy.spatial import distance
from numpy import mean,std,array,sum

# GimmeMotifs imports
from gimmemotifs.motif import *
from gimmemotifs.config import *
from gimmemotifs.c_metrics import pwmscan,score
# pool import is at the bottom

# Try to import the fisim code, if it present
try:
    fisim_dir = "/usr/share/gimmemotifs/includes/fisim"
    if os.path.exists(fisim_dir):
        sys.path.append(fisim_dir)
        import fisim.Motif
except ImportError:
    pass

# Function that can be parallelized
def _get_all_scores(mc, motifs, dbmotifs, match, metric, combine, pval):
    try:
        scores = {}
        for m1 in motifs:
            scores[m1.id] = {}
            for m2 in dbmotifs:
                scores[m1.id][m2.id] = mc.compare_motifs(m1, m2, match, metric, combine, pval=pval)    
    except Exception:
        logging.exception("f(%r) failed" % (args,))


def akl(x,y):
    """ Calcylates the average Kullback-Leibler similarity
    <NAME>,  2007
    """
    return 10 - (entropy(x,y) + entropy(y,x)) / 2.0

def chisq(x,y):
    return chi2_contingency([x, y])[1]

def ssd(x,y):
    """ Sum of squared distances 
    """
    return sum([(a-b)**2 for a,b in zip(x,y)] )

def seqcor(m1,m2):
    l1 = len(m1)
    l2 = len(m2)

    l = max(l1, l2)

    # Create random sequence
{'fraction_non_alphanumeric': 0.1063768944809837, 'fraction_numerical': 0.020017157563625966, 'mean_word_length': 3.3453416149068325, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '207641', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1217, 'n_words': 375}