Example #1
0
    def get_html_association(self):
        env = Environment()
        env.loader = jinja2.FileSystemLoader(
                       get_package_location("gdsctools")
                       + "/gdsctools/data/templates/")
        template = env.get_template("boxplot_association.html")

        jinja = {}
        N = len(self.odof.negatives) + len(self.odof.positives)
        jinja["title"] = "Individual Association"

        if self.odof.drug_name:
            drug_name = "%s (%s)" % (self.drug, self.odof.drug_name)
            jinja["subtitle"] = "%s versus %s" % (drug_name, self.feature)
        else:
            jinja["subtitle"] = "%s versus %s" % (self.drug, self.feature)
        jinja['factor'] = ["neg"] * len(self.odof.negatives) + ["pos"] * len(self.odof.positives)
        jinja["data"] = self.odof.negatives.tolist() + self.odof.positives.tolist()
        jinja["smps"] = [str(this) for this in self.odof.indices]
        jinja["subject"] = [str(this) for this in self.odof.indices]

        jinja['ylabel'] = '"logIC50"'

        html = template.render(jinja)
        return html
Example #2
0
    def get_html_association(self):
        env = Environment()
        env.loader = jinja2.FileSystemLoader(
            get_package_location("gdsctools") + "/gdsctools/data/templates/")
        template = env.get_template("boxplot_association.html")

        jinja = {}
        N = len(self.odof.negatives) + len(self.odof.positives)
        jinja["title"] = "Individual Association"

        if self.odof.drug_name:
            drug_name = "%s (%s)" % (self.drug, self.odof.drug_name)
            jinja["subtitle"] = "%s versus %s" % (drug_name, self.feature)
        else:
            jinja["subtitle"] = "%s versus %s" % (self.drug, self.feature)
        jinja['factor'] = ["neg"] * len(self.odof.negatives) + ["pos"] * len(
            self.odof.positives)
        jinja["data"] = self.odof.negatives.tolist(
        ) + self.odof.positives.tolist()
        jinja["smps"] = [str(this) for this in self.odof.indices]
        jinja["subject"] = [str(this) for this in self.odof.indices]

        jinja['ylabel'] = '"logIC50"'

        html = template.render(jinja)
        return html
Example #3
0
    def get_html_tissue(self):
        env = Environment()
        env.loader = jinja2.FileSystemLoader(
            get_package_location("gdsctools") + "/gdsctools/data/templates/")
        template = env.get_template("boxplot_tissue.html")

        data = self._get_boxplot_data("tissue")
        if data is None:
            return ""
        # Show from bottom to top
        labels = data[1][::-1]
        data = data[0][::-1]

        jinja = {}
        N = len(self.odof.negatives) + len(self.odof.positives)
        jinja["title"] = "FEATURE/MS-instability interactions"
        jinja["subtitle"] = "%s versus %s" % (self.drug, self.feature)
        factor = []
        for i, thisdata in enumerate(data):
            factor.extend([labels[i]] * len(thisdata))
        jinja['sign'] = [x.split()[1] for x in factor]
        jinja['status'] = [x.split()[0] for x in factor]
        jinja["data"] = list(pylab.flatten([list(this) for this in data]))
        jinja['xlabel'] = '"logIC50"'

        if len(labels) / 2 >= 10:
            jinja["minTextSize"] = 10

        html = template.render(jinja)
        return html
Example #4
0
    def get_html_tissue(self):
        env = Environment()
        env.loader = jinja2.FileSystemLoader(
                       get_package_location("gdsctools")
                       + "/gdsctools/data/templates/")
        template = env.get_template("boxplot_tissue.html")

        data = self._get_boxplot_data("tissue")
        if data is None:
            return ""
        # Show from bottom to top
        labels = data[1][::-1]
        data = data[0][::-1]

        jinja = {}
        N = len(self.odof.negatives) + len(self.odof.positives)
        jinja["title"] = "FEATURE/MS-instability interactions"
        jinja["subtitle"] = "%s versus %s" % (self.drug, self.feature)
        factor = []
        for i, thisdata in enumerate(data):
            factor.extend( [labels[i]] * len(thisdata))
        jinja['sign'] = [x.split()[1] for  x in factor]
        jinja['status'] = [x.split()[0] for  x in factor]
        jinja["data"] = list(pylab.flatten([list(this) for this in data]))
        jinja['xlabel'] = '"logIC50"'

        if len(labels)/2 >= 10:
            jinja["minTextSize"] = 10

        html = template.render(jinja)
        return html
Example #5
0
    def get_html(self):

        # We have 3 colors but sometimes you may have only one or 2.
        # This may be an issue with canvasXpress. It seems essential
        # to sort the color column so that names are sorted alphabetically
        # and to include colors that are present in the sale order
        """try:
            self.data.sort_values(by='color', inplace=True)
        except:
            self.data.sort("color", inplace=True)
        """
        # Jinja related
        from easydev import get_package_location
        env = Environment()
        env.loader = jinja2.FileSystemLoader(
            get_package_location("gdsctools") + "/gdsctools/data/templates/")
        template = env.get_template("scatter.html")

        # We need to cireate 20 different colors
        from colormap import Colormap
        c = Colormap()
        cmap = c.cmap_linear("red", "blue", "yellow", N=20)

        colors = self.data[self._colname_color]
        colors = ["red" for x in self.data[self._colname_color]]

        jinja = {}
        jinja["colors"] = ["rgba(205,0,0,0.5)"]
        jinja["Group"] = colors
        jinja['xlabel'] = '"%s"' % self.xlabel
        jinja['ylabel'] = '"%s"' % self.ylabel

        selection = [self._colname_x, self._colname_y]

        text = []
        for index in zip(self.data.index):
            text.append("<pre>%s</pre>" %
                        self.data.ix[index][selection].to_string())
        jinja['vars'] = text

        #self.data.markersize /= (self.data.markersize.max()/3.)
        self.data['markersize'] = 20
        selection = [self._colname_x, self._colname_y, self._colname_size]
        #First value is Y, second is X, following will be used in the
        try:  # introduced in pandas > 0.16.2
            jinja['data'] = self.data[selection].round(3).values.tolist()
        except:  #for py3.3 on travis
            jinja['data'] = np.around(self.data[selection]).values.tolist()

        jinja[
            'title'] = '"Regression coefficient vs Bayes factor for all drugs"'

        jinja['minX'] = self.minX
        jinja['minY'] = self.minY
        jinja['maxX'] = self.maxX
        jinja['maxY'] = self.maxY

        self.html = template.render(jinja)
        return self.html
Example #6
0
    def get_html(self):

        # We have 3 colors but sometimes you may have only one or 2.
        # This may be an issue with canvasXpress. It seems essential
        # to sort the color column so that names are sorted alphabetically
        # and to include colors that are present in the sale order
        """try:
            self.data.sort_values(by='color', inplace=True)
        except:
            self.data.sort("color", inplace=True)
        """
        # Jinja related
        from easydev import get_package_location
        env = Environment()
        env.loader = jinja2.FileSystemLoader(
                        get_package_location("gdsctools")
                        + "/gdsctools/data/templates/")
        template = env.get_template("scatter.html")

        # We need to cireate 20 different colors
        from colormap import Colormap
        c = Colormap()
        cmap = c.cmap_linear("red", "blue", "yellow", N=20)

        colors = self.data[self._colname_color]
        colors = ["red" for x in self.data[self._colname_color]]

        jinja = {}
        jinja["colors"] = ["rgba(205,0,0,0.5)"]
        jinja["Group"] = colors
        jinja['xlabel'] = '"%s"' % self.xlabel
        jinja['ylabel'] = '"%s"' % self.ylabel

        text = []
        for index in zip(self.data.index):
            text.append("<pre>%s</pre>" % self.data.ix[index].to_string())
        jinja['vars'] = text

        #self.data.markersize /= (self.data.markersize.max()/3.)
        self.data['markersize'] = 20
        selection = [self._colname_x, self._colname_y, self._colname_size]
        #First value is Y, second is X, following will be used in the
        try: # introduced in pandas > 0.16.2
            jinja['data'] = self.data[selection].round(3).values.tolist()
        except: #for py3.3 on travis
            jinja['data'] = np.around(self.data[selection]).values.tolist()

        jinja['title'] = '"Regression coefficient/ttest/bayes factor for all drugs"' 

        jinja['minX'] = 0
        jinja['minY'] = 0
        jinja['maxX'] = 1
        jinja['maxY'] = self.data[self._colname_y].max() * 1.1

        self.html = template.render(jinja)
        return self.html
Example #7
0
def fa_data(filename=None, where=None):
    """retrieve data set path from fragment_analyser/data dir"""
    import os
    import easydev
    import glob
    fa_path = easydev.get_package_location('fragment_analyser')
    sharedir = os.sep.join([fa_path , "fragment_analyser", 'data'])
    filename = sharedir + os.sep + filename
    if os.path.exists(filename) is False:
        raise Exception('unknown file %s' % filename)
    return filename
Example #8
0
def gdsctools_data(filename, where=None):
    """Simple utilities to retrieve data sets from gdsctools/share directory"""
    gdsctools_path = easydev.get_package_location('gdsctools')
    share = os.sep.join([gdsctools_path, "gdsctools", 'data'])
    # in the code one may use / or \ 
    if where:
        filename = os.sep.join([share, where, filename])
    else:
        filename = os.sep.join([share, filename])
    if os.path.exists(filename) is False:
        raise Exception('unknown file %s' % filename)
    return filename
Example #9
0
def gdsctools_data(filename, where=None):
    """Simple utilities to retrieve data sets from gdsctools/share directory"""
    gdsctools_path = easydev.get_package_location('gdsctools')
    share = os.sep.join([gdsctools_path, "gdsctools", 'data'])
    # in the code one may use / or \ 
    if where:
        filename = os.sep.join([share, where, filename])
    else:
        filename = os.sep.join([share, filename])
    if os.path.exists(filename) is False:
        raise Exception('unknown file %s' % filename)
    return filename
Example #10
0
    def _init_report(self):
        """create the report directory and return the directory name"""
        self.sections = []
        self.section_names = []

        # if the directory already exists, print a warning
        try:
            if os.path.isdir(self.directory) is False:
                if self.verbose:
                    print("Created directory {}".format(self.directory))
                os.mkdir(self.directory)
            # list of directories created in the constructor
            for this in self._to_create:
                try:
                    os.mkdir(self.directory + os.sep + this)
                except:
                    pass  # already created ?
        except Exception:
            pass
        finally:
            # Once the main directory is created, copy files required
            temp_path = easydev.get_package_location("reports")
            temp_path += os.sep + "reports" + os.sep + "resources"

            # Copy the CSS from reports/resources/css
            filenames = glob.glob(os.sep.join([temp_path, "css", "*.css"]))

            # If there are CSS in the directory with JINJA templates, use them
            # as well
            filenames += glob.glob(os.sep.join([self.searchpath, '*.css']))

            # In addition, the user may also provide his own CSS as a list
            filenames += self.extra_css_list
            for filename in filenames:
                target = os.sep.join([self.directory, 'css'])
                if os.path.isfile(target) is False:
                    shutil.copy(filename, target)

            # We copy all javascript from reports resources
            for filename in [
                    'sorttable.js', 'highlight.pack.js', "jquery-1.12.3.min.js"
            ]:
                target = os.sep.join([self.directory, 'js', filename])
                if os.path.isfile(target) is False:
                    filename = os.sep.join([temp_path, "javascript", filename])
                    shutil.copy(filename, target)
            for filename in self.extra_js_list:
                basename = os.path.basename(filename)
                target = os.sep.join([self.directory, 'js', basename])
                if os.path.isfile(target) is False:
                    shutil.copy(filename, target)
Example #11
0
    def _init_report(self):
        """create the report directory and return the directory name"""
        self.sections = []
        self.section_names = []


        # if the directory already exists, print a warning
        try:
            if os.path.isdir(self.directory) is False:
                if self.verbose:
                    print("Created directory {}".format(self.directory))
                os.mkdir(self.directory)
            # list of directories created in the constructor
            for this in self._to_create:
                try:
                    os.mkdir(self.directory + os.sep + this)
                except:
                    pass # already created ?
        except Exception:
            pass
        finally:
            # Once the main directory is created, copy files required
            temp_path = easydev.get_package_location("reports")
            temp_path += os.sep + "reports" + os.sep + "resources"

            # Copy the CSS from reports/resources/css
            filenames = glob.glob(os.sep.join([temp_path, "css", "*.css"]))

            # If there are CSS in the directory with JINJA templates, use them
            # as well
            filenames += glob.glob(os.sep.join([self.searchpath, '*.css']))


            # In addition, the user may also provide his own CSS as a list
            filenames += self.extra_css_list
            for filename in filenames:
                target = os.sep.join([self.directory, 'css' ])
                if os.path.isfile(target) is False:
                    shutil.copy(filename, target)

            # We copy all javascript from reports resources
            for filename in ['sorttable.js', 'highlight.pack.js', "jquery-1.12.3.min.js"]:
                target = os.sep.join([self.directory, 'js', filename ])
                if os.path.isfile(target) is False:
                    filename = os.sep.join([temp_path, "javascript", filename])
                    shutil.copy(filename, target)
            for filename in self.extra_js_list:
                basename = os.path.basename(filename)
                target = os.sep.join([self.directory, 'js', basename ])
                if os.path.isfile(target) is False:
                    shutil.copy(filename, target)
Example #12
0
def biokit_data(filename, where=None):
    """Simple utilities to retrieve data sets from biokit/data directory"""
    import os
    import easydev
    biokit_path = easydev.get_package_location('biokit')
    share = os.sep.join([biokit_path , "biokit", 'data'])
    # in the code one may use / or \ 
    if where:
        filename = os.sep.join([share, where, filename])
    else:
        filename = os.sep.join([share, filename])
    if os.path.exists(filename) is False:
        raise Exception('unknown file %s' % filename)
    return filename
Example #13
0
def bioconvert_data(filename, where=None):
    """Simple utilities to retrieve data sets from bioconvert/data directory"""
    import os
    import easydev
    bioconvert_path = easydev.get_package_location('bioconvert')
    share = os.sep.join([bioconvert_path, "bioconvert", 'data'])
    # in the code one may use / or \
    if where:
        filename = os.sep.join([share, where, filename])
    else:
        filename = os.sep.join([share, filename])
    if os.path.exists(filename) is False:
        raise Exception('unknown file %s' % filename)
    return filename
Example #14
0
    def write_report(self,
                     template_name="simple",
                     template_path=None,
                     filename="report.html",
                     prettify=True):
        """
            Writes the html report.

            Args:
                template_name:  name of the template to use (only used if template_path is None)
                template_path:  path of the custom template to use
                filename:       output file to write
                prettify:       bool to prettify the output html

            Available templates are:
            * simple
        """

        # If no custom path, use one of the predefined templates
        if template_path is None:
            relative_uri = f"html_reports/templates/{template_name}.html"

            template_uri = os.sep.join(
                [easydev.get_package_location("html_reports")] +
                relative_uri.split("/"))

        # Else, use user template
        else:
            template_uri = template_path

        # Load jinja2 template
        template = read_template(template_uri)

        # Render jinja2 template
        output = template.render(
            body="\n".join(self.body),
            scripts=self.scripts,
            raw_scripts=self.raw_scripts,
            styles=self.styles,
            **self.args,
        )

        # Prettify html file
        if prettify:
            output = BeautifulSoup(output, "html.parser").prettify()

        # Write html file
        with open(filename, "w") as file:
            file.write(output)
Example #15
0
    def __init__(self,
                 filename='index.html',
                 directory='report',
                 overwrite=True,
                 verbose=True,
                 template_filename='index.html',
                 mode=None,
                 init_report=True):
        """.. rubric:: Constructor

        :param filename: default to **index.html**
        :param directory: defaults to **report**
        :param overwrite: default to True
        :param verbose: default to True
        :param dependencies: add the dependencies table at the end of the
            document if True.
        :param str mode: if none, report have a structure that contains the
            following directories: OUTPUT, INPUT, js, css, images, code.
            Otherwise, if mode is set to 'summary', only the following
            directories are created: js, css, images 

        """
        gdsctools_path = easydev.get_package_location('gdsctools')
        extra_css_path = sepjoin([gdsctools_path, "gdsctools", "data", "css"])
        extra_js_path = sepjoin(
            [gdsctools_path, "gdsctools", "data", "javascript"])

        extra_css_list = glob.glob(extra_css_path + os.sep + "*css")
        extra_js_list = glob.glob(extra_js_path + os.sep + "*js")

        searchpath = sepjoin(
            [gdsctools_path, "gdsctools", "data", "templates"])

        super(ReportMain, self).__init__(searchpath,
                                         filename=filename,
                                         template_filename=template_filename,
                                         directory=directory,
                                         extra_css_list=extra_css_list,
                                         extra_js_list=extra_js_list,
                                         init_report=init_report)

        self.jinja['dependencies'] = self.get_table_dependencies(
            "gdsctools").to_html()
        self.jinja['analysis'] = 'anova'
        from gdsctools import version
        self.jinja['version'] = version
        self.jinja['title'] = 'ANOVA analysis summary'
        self.jinja["analysis_domain"] = "PANCAN"
        self.jinja['resource_path'] = "."

        self._directory = directory
        self._filename = filename

        if mode is None:
            self._to_create = [
                'OUTPUT', 'INPUT', 'images', 'css', 'js', 'code',
                'associations'
            ]
        elif mode == 'summary':
            self._to_create = [
                'images',
                'css',
                'js',
            ]
        if init_report:
            self._init_report()
Example #16
0
    def _render_data(self, name="all associations"):

        self.data['log10pvalue'] = -log10(self.data['pvalue'])

        self.data['color'] = self.data['color'].apply(
            lambda x: x.replace("black", "not_significant"))
        self.data['color'] = self.data['color'].apply(
            lambda x: x.replace("green", "sensitive"))
        self.data['color'] = self.data['color'].apply(
            lambda x: x.replace("red", "resistant"))

        # We have 3 colors but sometimes you may have only one or 2.
        # This may be an issue with canvasXpress. It seems essential
        # to sort the color column so that names are sorted alphabetically
        # and to include colors that are present in the sale order
        try:
            self.data.sort_values(by='color', inplace=True)
        except:
            self.data.sort("color", inplace=True)
        colors = []
        if "not_significant" in self.data.color.values:
            colors.append("rgba(0,0,0,0.5)")  # black
        if "resistant" in self.data.color.values:
            colors.append("rgba(205,0,0,0.5)")  # red
        if "sensitive" in self.data.color.values:
            colors.append("rgba(0,205,0,0.5)")  # green

        env = Environment()

        from easydev import get_package_location

        env.loader = jinja2.FileSystemLoader(
            get_package_location("gdsctools") + "/gdsctools/data/templates/")
        template = env.get_template("volcano.html")

        jinja = {}

        jinja["colors"] = colors
        jinja["Group"] = list(self.data['color'].values)
        jinja['xlabel'] = "Signed Effect Size"
        jinja['ylabel'] = "-log10(pvalue)"

        text = []
        for x, y, z in zip(self.data['Drug'].values,
                           self.data['Feature'].values,
                           self.data['FDR'].values):

            text.append(
                "<b>Drug:</b>%s <br><b>Feature:</b>%s <br><b>FDR:</b>%s" %
                (x, y, z))
        jinja['vars'] = text
        """
        # does not work in the JS somehow some points do not appear
        # disabled for now
        markersize = self.data['markersize']
        markersize -= markersize.min()
        markersize /= markersize.max()
        markersize = (3*markersize).round()
        #markersize[markersize == 0] = 1

        FC = list(markersize.astype(int).astype(str))
        jinja['FC'] = FC
        """
        self.data.markersize /= (self.data.markersize.max() / 3.)

        #First value is Y, second is X, following will be used in the
        try:  # introduced in pandas > 0.16.2
            jinja['data'] = self.data[[
                "signed_effect", "log10pvalue", "markersize"
            ]].round(3).values.tolist()
        except:  #for py3.3 on travis
            jinja['data'] = np.around(
                self.data[["signed_effect", "log10pvalue",
                           "markersize"]]).values.tolist()
        jinja['title'] = '"%s"' % name

        fdrs = self.get_fdr_ypos()
        fdrs = [0 if np.isnan(x) else x for x in fdrs]
        jinja['additional_fdrs'] = ""
        for i, this in enumerate(fdrs):
            line = '\n{"color": "red", "width": 1, "type": "dashed", "y":  %s}'
            if i == len(fdrs) - 1:
                pass
            else:
                line += ","
            jinja['additional_fdrs'] += line % this

        m = abs(self.data.signed_effect.min())
        M = abs(self.data.signed_effect.max())
        jinja['minX'] = -max([m, M]) * 1.1
        jinja['maxX'] = max([m, M]) * 1.1
        jinja['maxY'] = self.data["log10pvalue"].max() * 1.2
        if max(fdrs) > jinja['maxY']:
            jinja['maxY'] = max(fdrs) * 1.2

        self.html = template.render(jinja)
        return self.html
Example #17
0
import easydev
import os
import tempfile
import subprocess
import sys


sequana_path = easydev.get_package_location('sequana_fastqc')
sharedir = os.sep.join([sequana_path , "sequana_pipelines", 'fastqc', 'data'])


# 
def test_standalone_subprocess():
    directory = tempfile.TemporaryDirectory()
    cmd = "sequana_pipelines_fastqc --input-directory {} "
    cmd += "--working-directory {} --run-mode local --force"
    cmd = cmd.format(sharedir, directory.name)
    subprocess.call(cmd.split())


def test_standalone_script():
    directory = tempfile.TemporaryDirectory()
    import sequana_pipelines.fastqc.main as m
    sys.argv = ["test", "--input-directory", sharedir, "--working-directory",
        directory.name, "--run-mode", "local", "--force"]
    m.main()


def test_full():

    with tempfile.TemporaryDirectory() as directory:
Example #18
0
def sequana_data(filename=None, where=None):
    """Return full path of a sequana resource data file.

    :param str filename: a valid filename to be found
    :param str where: one of the registered data directory (see below)
    :return: the path of file. See also here below in the case where 
        filename is set to "*".

    .. code-block:: python

        from sequana import sequana_data
        filename = sequana_data("test.bam")

    Type the function name with "*" parameter to get a list of
    available files. Withe where argument set, the function returns a 
    list of files. Without the where argument, a dictionary is returned where
    keys correspond to the registered directories::

        filenames = sequana_data("*", where="images")

    Registered directories are:

        - data
        - testing
        - data/adapters
        - images

    .. note:: this does not handle wildcards. The * means retrieve all files.

    """
    sequana_path = easydev.get_package_location('sequana')
    sharedir = os.sep.join([sequana_path, "sequana", 'resources'])
    directories = ['data', 'testing', 'data/adapters', 'images', 'scripts']

    if filename == "*":
        found = collections.defaultdict(list)
        if where is not None:
            directories = [where]
        for thisdir in directories:
            for filename in glob.glob(sharedir + "/%s/*" % thisdir):
                filename = os.path.split(filename)[1]
                to_ignore = ["__init__.py", "__pycache__"]
                if filename.endswith('.pyc') or filename in to_ignore:
                    pass
                else:
                    found[thisdir].append(os.path.split(filename)[1])
        if where is not None:
            return found[where]
        return found

    if filename is None:
        for thisdir in directories:
            print('From %s directory:' % thisdir)
            for filename in glob.glob(sharedir + "/%s/*" % thisdir):
                filename = os.path.split(filename)[1]
                to_ignore = ["__init__.py", "__pycache__"]
                if filename.endswith('.pyc') or filename in to_ignore:
                    pass
                else:
                    print(' - sequana("%s", "%s")' %
                          (os.path.split(filename)[1], thisdir))
        raise ValueError("Choose a valid file from the list above")

    # in the code one may use / or \
    if where:
        filename = os.sep.join([sharedir, where, filename])
    else:

        def _get_valid_file(filename, directory):
            filename = os.sep.join([sharedir, directory, filename])
            if os.path.exists(filename) is False:
                return False
            else:
                return filename

        # try to introspect the different directories
        # return filename if found otherwise raise error
        for thisdir in directories:
            if _get_valid_file(filename, thisdir):
                return _get_valid_file(filename, thisdir)
        raise Exception(
            "unknown file %s. Type sequana_data() to get a list of valid names"
            % filename)

    return filename
Example #19
0
import easydev
import os
import tempfile
import subprocess
import sys

sequana_path = easydev.get_package_location('sequana_coverage')
sharedir = os.sep.join([sequana_path, "sequana_pipelines/coverage/data"])
annotation = sharedir + os.sep + "JB409847.gbk"
reference = sharedir + os.sep + "JB409847.fa"


def test_standalone_subprocess():
    directory = tempfile.TemporaryDirectory()
    cmd = "sequana_pipelines_coverage --input-directory {} "
    cmd += "--working-directory {} --force --annotation {} "
    cmd += " --reference {} -o "
    cmd = cmd.format(sharedir, directory.name, annotation, reference)
    subprocess.call(cmd.split())


def test_standalone_script():
    directory = tempfile.TemporaryDirectory()
    import sequana_pipelines.coverage.main as m
    sys.argv = ["test", "--input-directory", sharedir, "--force"]
    m.main()


def test_wrong_reference():
    directory = tempfile.TemporaryDirectory()
    import sequana_pipelines.coverage.main as m
Example #20
0
    def __init__(self,
                 searchpath=None,
                 filename='index.html',
                 directory='report',
                 overwrite=True,
                 verbose=True,
                 template_filename='index.html',
                 extra_css_list=[],
                 extra_js_list=[],
                 init_report=True):
        """.. rubric:: Constructor


        :param searchpath: where to find the jina templates. 
            If not provided, uses the generic template
        :param filename: output filename (default to **index.html**)
        :param directory: defaults to **report**
        :param overwrite: default to True
        :param verbose: default to True
        :param template_filename: entry point of the jinja code
        :param extra_css_list: where to find the extra css 
        :param extra_js_list: where to find the extra css 
        :param bool init_report: init the report that is create 
            the directories to store css and JS.

        """
        self.verbose = verbose
        self._directory = directory
        self._filename = filename
        self.extra_css_list = extra_css_list
        self.extra_js_list = extra_js_list

        # This contains the sections and their names
        # Not used yet but could be in jinja templating
        self.sections = []
        self.section_names = []

        #: flag to add dependencies
        self.add_dependencies = False

        # For jinja2 inheritance, we need to use the environment
        # to indicate where are the parents' templates
        if searchpath is None:
            thispath = easydev.get_package_location('reports')
            thispath += os.sep + "reports"
            thispath += os.sep + "resources"
            self.searchpath = os.sep.join([thispath, 'templates', "generic"])
        else:
            # path to the template provided by the user
            self.searchpath = searchpath

        # The JINJA environment
        # TODO check that the path exists
        self.env = Environment()
        self.env.loader = FileSystemLoader(self.searchpath)

        # input template file
        self.template = self.env.get_template(template_filename)

        # This dictionary will be used to populate the JINJA template
        self.jinja = {
            'time_now': self.get_time_now(),
            "title": "Title to be defined",
            'dependencies': self.get_table_dependencies().to_html(),
            "report_version": _get_report_version()
        }

        # Directories to create
        self._to_create = [
            'images',
            'css',
            'js',
        ]

        # Create directories and stored css/js/images
        if init_report:
            self._init_report()
Example #21
0
import glob

import easydev

from datetime import datetime
time_now = datetime.now().strftime("%m-%d-%Y %H:%M:%S")

# Get sequana informations
version = pkg_resources.get_distribution('sequana').version
script_path = os.path.dirname(os.path.realpath(__file__))

# Default options
output_dir = os.path.realpath(os.getcwd())

def get_entry_name(entry_point):
    return str(entry_point).split('=')[0].strip()

# Modules available
module_dict = {get_entry_name(entry_point): entry_point for entry_point
               in pkg_resources.iter_entry_points('sequana.module')}

# Find css/js file necessary for the report
sequana_path = easydev.get_package_location('sequana')
css_path = os.sep.join([sequana_path, "sequana", "resources", "css"])
js_path = os.sep.join([sequana_path, "sequana", "resources", "js"])
css_list = glob.glob(css_path + os.sep + "*css")
js_list = glob.glob(js_path + os.sep + "*js")

# Sections list for summary.html
summary_sections = list()
Example #22
0
import easydev
import os
import tempfile
import subprocess
import sys

sequana_path = easydev.get_package_location('sequana_revcomp')
sharedir = os.sep.join([sequana_path, "sequana_pipelines", 'revcomp', 'data'])


#
def test_standalone_subprocess():
    directory = tempfile.TemporaryDirectory()
    cmd = "sequana_pipelines_revcomp --input-directory {} "
    cmd += "--working-directory {} --force"
    cmd = cmd.format(sharedir, directory.name)
    subprocess.call(cmd.split())


def test_standalone_script():
    directory = tempfile.TemporaryDirectory()
    import sequana_pipelines.revcomp.main as m
    sys.argv = [
        "test", "--input-directory", sharedir, "--working-directory",
        directory.name, "--force"
    ]
    m.main()


def test_full():
Example #23
0
    def _render_data(self, name="all associations"):

        self.data['log10pvalue'] = -log10(self.data['pvalue'])

        self.data['color'] = self.data['color'].apply(lambda x:
                x.replace("black", "not_significant"))
        self.data['color'] = self.data['color'].apply(lambda x:
                x.replace("green", "sensitive"))
        self.data['color'] = self.data['color'].apply(lambda x:
                x.replace("red", "resistant"))

        # We have 3 colors but sometimes you may have only one or 2.
        # This may be an issue with canvasXpress. It seems essential
        # to sort the color column so that names are sorted alphabetically
        # and to include colors that are present in the sale order
        try:
            self.data.sort_values(by='color', inplace=True)
        except:
            self.data.sort("color", inplace=True)
        colors = []
        if "not_significant" in self.data.color.values:
            colors.append("rgba(0,0,0,0.5)")  # black
        if "resistant" in self.data.color.values:
            colors.append("rgba(205,0,0,0.5)")  # red
        if "sensitive" in self.data.color.values:
            colors.append("rgba(0,205,0,0.5)")  # green

        env = Environment()

        from easydev import get_package_location

        env.loader = jinja2.FileSystemLoader(
                        get_package_location("gdsctools")
                        + "/gdsctools/data/templates/")
        template = env.get_template("volcano.html")

        jinja = {}

        jinja["colors"] = colors
        jinja["Group"] = list(self.data['color'].values)
        jinja['xlabel'] = "Signed Effect Size"
        jinja['ylabel'] = "-log10(pvalue)"

        text = []
        for x,y,z in zip(self.data['Drug'].values,
            self.data['Feature'].values,
            self.data['FDR'].values):

            text.append("<b>Drug:</b>%s <br><b>Feature:</b>%s <br><b>FDR:</b>%s" % (x,y,z))
        jinja['vars'] = text

        """
        # does not work in the JS somehow some points do not appear
        # disabled for now
        markersize = self.data['markersize']
        markersize -= markersize.min()
        markersize /= markersize.max()
        markersize = (3*markersize).round()
        #markersize[markersize == 0] = 1

        FC = list(markersize.astype(int).astype(str))
        jinja['FC'] = FC
        """
        self.data.markersize /= (self.data.markersize.max()/3.)

        #First value is Y, second is X, following will be used in the
        try: # introduced in pandas > 0.16.2
            jinja['data'] = self.data[["signed_effect", "log10pvalue",
                "markersize"]].round(3).values.tolist()
        except: #for py3.3 on travis
            jinja['data'] = np.around(self.data[["signed_effect", "log10pvalue",
                "markersize"]]).values.tolist()
        jinja['title'] = '"%s"' % name

        fdrs = self.get_fdr_ypos()
        fdrs = [0 if np.isnan(x) else x for x in fdrs]
        jinja['additional_fdrs'] = ""
        for i,this in enumerate(fdrs):
            line = '\n{"color": "red", "width": 1, "type": "dashed", "y":  %s}'
            if i == len(fdrs)-1:
                pass
            else:
                line += ","
            jinja['additional_fdrs'] += line % this

        m = abs(self.data.signed_effect.min())
        M = abs(self.data.signed_effect.max())
        jinja['minX'] = -max([m, M]) * 1.1
        jinja['maxX'] =  max([m, M]) * 1.1
        jinja['maxY'] = self.data["log10pvalue"].max() * 1.2
        if max(fdrs) > jinja['maxY']:
            jinja['maxY'] = max(fdrs) * 1.2

        self.html = template.render(jinja)
        return self.html
Example #24
0
    def __init__(self,
                 searchpath=None,
                 filename='index.html',
                 directory='report',
                 overwrite=True,
                 verbose=True,
                 template_filename='index.html',
                 extra_css_list=[],
                 extra_js_list=[],
                init_report=True):
        """.. rubric:: Constructor


        :param searchpath: where to find the jina templates. 
            If not provided, uses the generic template
        :param filename: output filename (default to **index.html**)
        :param directory: defaults to **report**
        :param overwrite: default to True
        :param verbose: default to True
        :param template_filename: entry point of the jinja code
        :param extra_css_list: where to find the extra css 
        :param extra_js_list: where to find the extra css 
        :param bool init_report: init the report that is create 
            the directories to store css and JS.

        """
        self.verbose = verbose
        self._directory = directory
        self._filename = filename
        self.extra_css_list = extra_css_list
        self.extra_js_list = extra_js_list

        # This contains the sections and their names
        # Not used yet but could be in jinja templating
        self.sections = []
        self.section_names = []

        #: flag to add dependencies
        self.add_dependencies = False

        # For jinja2 inheritance, we need to use the environment
        # to indicate where are the parents' templates
        if searchpath  is None:
            thispath = easydev.get_package_location('reports')
            thispath += os.sep + "reports"
            thispath += os.sep + "resources"
            self.searchpath = os.sep.join([thispath, 'templates', "generic"])
        else:
            # path to the template provided by the user 
            self.searchpath = searchpath

        # The JINJA environment
        # TODO check that the path exists
        self.env = Environment()
        self.env.loader = FileSystemLoader(self.searchpath)

        # input template file 
        self.template = self.env.get_template(template_filename)

        # This dictionary will be used to populate the JINJA template
        self.jinja = {
            'time_now': self.get_time_now(),
            "title": "Title to be defined",
            'dependencies': self.get_table_dependencies().to_html(),
            "report_version": _get_report_version()
        }

        # Directories to create 
        self._to_create = ['images', 'css', 'js',]

        # Create directories and stored css/js/images
        if init_report:
            self._init_report()
Example #25
0
    def __init__(
        self,
        filename="index.html",
        directory="report",
        overwrite=True,
        verbose=True,
        template_filename="index.html",
        mode=None,
        init_report=True,
    ):
        """.. rubric:: Constructor

        :param filename: default to **index.html**
        :param directory: defaults to **report**
        :param overwrite: default to True
        :param verbose: default to True
        :param dependencies: add the dependencies table at the end of the
            document if True.
        :param str mode: if none, report have a structure that contains the
            following directories: OUTPUT, INPUT, js, css, images, code.
            Otherwise, if mode is set to 'summary', only the following
            directories are created: js, css, images 

        """
        gdsctools_path = easydev.get_package_location("gdsctools")
        extra_css_path = sepjoin([gdsctools_path, "gdsctools", "data", "css"])
        extra_js_path = sepjoin([gdsctools_path, "gdsctools", "data", "javascript"])

        extra_css_list = glob.glob(extra_css_path + os.sep + "*css")
        extra_js_list = glob.glob(extra_js_path + os.sep + "*js")

        searchpath = sepjoin([gdsctools_path, "gdsctools", "data", "templates"])

        super(ReportMain, self).__init__(
            searchpath,
            filename=filename,
            template_filename=template_filename,
            directory=directory,
            extra_css_list=extra_css_list,
            extra_js_list=extra_js_list,
            init_report=init_report,
        )

        self.jinja["dependencies"] = self.get_table_dependencies("gdsctools").to_html()
        self.jinja["analysis"] = "anova"
        from gdsctools import version

        self.jinja["version"] = version
        self.jinja["title"] = "ANOVA analysis summary"
        self.jinja["analysis_domain"] = "PANCAN"
        self.jinja["resource_path"] = "."

        self._directory = directory
        self._filename = filename

        if mode is None:
            self._to_create = ["OUTPUT", "INPUT", "images", "css", "js", "code", "associations"]
        elif mode == "summary":
            self._to_create = ["images", "css", "js"]
        if init_report:
            self._init_report()