<commit_before>import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))

from bnol import workflows
import unittest
from numpyfied import NumpyfiedTestCase
import numpy as np

class WorkflowsTester(NumpyfiedTestCase):

    @staticmethod
    def _testFilePath(filename):
        return os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', filename)

    def test_cuffnorm_one_vs_rest_analysis(self):
        analysis = workflows.CuffnormOneVsRest(self._testFilePath('genes.count_table'), [True]*30 + [False]*89)
        onlyInformative = analysis.informativeGenes(allGenes=False)
        allGenes = analysis.informativeGenes(allGenes=True)

        nInformative = len(onlyInformative.index)
        ranking = ["GENE_%s" % g for g in ['F','D','G','C','I','H','E','A','B']]

        self.assertAllTrue(allGenes.index==ranking, "Incorrect ranking of genes by entropy gain")
        self.assertAllTrue(onlyInformative.index==allGenes.index[:nInformative], "Incorrect subset of genes in informative grouping")
        self.assertAllTrue(onlyInformative==allGenes.iloc[:nInformative,:], "Values for informative genes do not match across informative / all-genes groups")
        self.assertAllTrue(onlyInformative.loc[:,'Informative']==1, "Non-informative genes included in informative-only group")
        self.assertAllTrue(allGenes.loc[:,'Informative'][nInformative:]==0, "Informative genes included in non-informative section")
        informative = allGenes.loc[:,'Gain']>allGenes.loc[:,'MDLP-Criterion']
        self.assertAllTrue(informative==allGenes.loc[:,'Informative'], "Gain vs MDLP-criterion does not match marking as informative")

    # def test_cuffnorm_multiclass_analysis(self):
    #     path = self._testFilePath('genes.count_table')
    #     approaches = {
    #         'CuffnormMultiClassCompare' : [0]*30 + [1]*29 + [2]*30 + [3]*30,
    #         'CuffnormOneVsRest' : [True]*30 + [False]*89
    #     }
    #     objs = dict()
    #     for approach, specimenClasses in approaches.items():
    #         objs[approach] = getattr(workflows, approach)(path, specimenClasses)
    #
    #     for allGenes in [True, False]:
    #         output = dict()
    #         for approach, obj in objs.items():
    #             output[approach] = obj.informativeGenes(allGenes)
    #         mul = output['CuffnormMultiClassCompare']
    #         one = output['CuffnormOneVsRest']
    #
    #         self.assertAllTrue(mul[0]==one, "Data re informative genes does not match between multi-class and one-vs-rest approaches")
    #         self.assertAllTrue(mul[0].index==one.index, "Ranking of genes does not match between multi-class and one-vs-rest approaches")
    #         self.assertEqual(len(mul.keys()), 4, "Multi-class informative gene analysis returns incorrect number of analyses for number of classes")

    def test_multiclass_to_onevsrest_class_conversion(self):
        multiClasses = [0]*7 + [1]*9 + [0]*3 + [2]*8
        expected = [
            [True]*7 + [False]*9 + [True]*3 + [False]*8,<commit_msg>Multiprocessing does not fail on Travis CI when only running test_cuffnorm_one_vs_rest_analysis() but not testing multiclass. Inverting tests to check for failures.<commit_after>import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))

from bnol import workflows
import unittest
from numpyfied import NumpyfiedTestCase
import numpy as np

class WorkflowsTester(NumpyfiedTestCase):

    @staticmethod
    def _testFilePath(filename):
        return os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', filename)

    # def test_cuffnorm_one_vs_rest_analysis(self):
    #     analysis = workflows.CuffnormOneVsRest(self._testFilePath('genes.count_table'), [True]*30 + [False]*89)
    #     onlyInformative = analysis.informativeGenes(allGenes=False)
    #     allGenes = analysis.informativeGenes(allGenes=True)
    #
    #     nInformative = len(onlyInformative.index)
    #     ranking = ["GENE_%s" % g for g in ['F','D','G','C','I','H','E','A','B']]
    #
    #     self.assertAllTrue(allGenes.index==ranking, "Incorrect ranking of genes by entropy gain")
    #     self.assertAllTrue(onlyInformative.index==allGenes.index[:nInformative], "Incorrect subset of genes in informative grouping")
    #     self.assertAllTrue(onlyInformative==allGenes.iloc[:nInformative,:], "Values for informative genes do not match across informative / all-genes groups")
    #     self.assertAllTrue(onlyInformative.loc[:,'Informative']==1, "Non-informative genes included in informative-only group")
    #     self.assertAllTrue(allGenes.loc[:,'Informative'][nInformative:]==0, "Informative genes included in non-informative section")
    #     informative = allGenes.loc[:,'Gain']>allGenes.loc[:,'MDLP-Criterion']
    #     self.assertAllTrue(informative==allGenes.loc[:,'Informative'], "Gain vs MDLP-criterion does not match marking as informative")

    def test_cuffnorm_multiclass_analysis(self):
        path = self._testFilePath('genes.count_table')
        approaches = {
            'CuffnormMultiClassCompare' : [0]*30 + [1]*29 + [2]*30 + [3]*30,
            'CuffnormOneVsRest' : [True]*30 + [False]*89
        }
        objs = dict()
        for approach, specimenClasses in approaches.items():
            objs[approach] = getattr(workflows, approach)(path, specimenClasses)

        for allGenes in [True, False]:
            output = dict()
            for approach, obj in objs.items():
                output[approach] = obj.informativeGenes(allGenes)
            mul = output['CuffnormMultiClassCompare']
            one = output['CuffnormOneVsRest']

            self.assertAllTrue(mul[0]==one, "Data re informative genes does not match between multi-class and one-vs-rest approaches")
            self.assertAllTrue(mul[0].index==one.index, "Ranking of genes does not match between multi-class and one-vs-rest approaches")
            self.assertEqual(len(mul.keys()), 4, "Multi-class informative gene analysis returns incorrect number of analyses for number of classes")

    def test_multiclass_to_onevsrest_class_conversion(self):
        multiClasses = [0]*7 + [1]*9 + [0]*3 + [2]*8
        expected = [
            [True]*7 + [False]*9 + [True]*3 + [False]*8,
{'fraction_non_alphanumeric': 0.1297322984318074, 'fraction_numerical': 0.012038650403928403, 'mean_word_length': 3.6909361069836555, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3261939', 'n_tokens_mistral': 2032, 'n_tokens_neox': 1945, 'n_words': 411}