Beispiel #1
0
 def file_and_status_from_metarow(self, name_and_status, read_index):
     """
     ['>>Sequence Length Distribution', 'pass']
     """
     filename = name_and_status[0].replace(" ", "_").strip(">>") + ".csv"
     filehandle = open(os.path.join(self.out_dir, read_index, filename), "w")
     # new tab
     if "R1" in read_index:
         web_tab = WebTab([read_index, "%s/%s" % (read_index, filename)], status=name_and_status[1])
     # R2; look up existing tab and add filename
     else:
         assert "R2" in read_index
         web_tab = self.tabs[filename]
         # list of lists
         web_tab.filename = [web_tab.filename, [read_index, '%s/%s' % (read_index, filename)]]
         # set status to worse of R1 and R2
         web_tab.update_status(name_and_status[1])
     return filename, filehandle, web_tab
Beispiel #2
0
    def file_and_status_from_metarow(self, name_and_status, read_index):
        """
        ['>>Sequence Length Distribution', 'pass']
        """
        filename = name_and_status[0].replace(" ", "_").strip(">>") + ".csv"
        filehandle = open(os.path.join(self.out_dir, read_index, filename), "w")
        # new tab
        if read_index == "R1":
            web_tab = WebTab([read_index, "R1/%s" % filename], status=name_and_status[1])
        # R2; look up existing tab and add filename
        else:
            assert(read_index == "R2")
            try:
                web_tab = self.tabs[filename]
                # list of lists
                web_tab.filename = [web_tab.filename, ["R2", "R2/%s" % filename]]
                # set status to worse of R1 and R2
                web_tab.update_status(name_and_status[1])
            # R2 has output that is missing from the analysis of R1
            except KeyError:
                # new tab, needs empty R1 plot tab
                web_tab = WebTab([["R1", "R1/%s" % filename], ["R2", "R2/%s" % filename]], status=name_and_status[1])

        return filename, filehandle, web_tab
Beispiel #3
0
Datei: fqc.py Projekt: xtmgah/fqc
def run_add(config,
            name,
            plot_type,
            csv,
            prepend=False,
            status=None,
            x_value=None,
            y_value=None,
            x_label=None,
            y_label=None,
            subtitle=None,
            lower_quartile=None,
            upper_quartile=None,
            mean=None,
            value=None,
            label=None,
            colors=None,
            step=10,
            min_value=None,
            min_color=None,
            mid_color=None,
            max_value=None,
            max_color=None):
    """Copies the CSV into the directory containing the config file if it does not already exist
    there, then either appends an appropriate entry onto the existing config JSON or creates a new
    file.

    Args:
        config (str): file path to config.json
        name (str): name being used in the tab on the dashboard
        plot_type (str): type of chart being created
        csv (str): file path to data file being added to dashboard
        prepend (Optional[bool]): add new plot as first tab in dashboard
        status (Optional[str]): image icon to be displayed on tab [None, 'warn', 'pass', 'fail']
        x_value (Optional[str]): header label in CSV containing the x-values
        y_value (Optional[str]): header label in CSV containing the y-values
        x_label (Optional[str]): x-label to be drawn on dashboard; defaults to `x_value`
        y_label (Optional[str]): y-label to be drawn on dashboard; defaults to `y_value`
        subtitle (Optional[str]): subtitle to be drawn on dashboard
        lower_quartile (Optional[str]): arearange specific option; header label in CSV for lower
            quartile value
        upper_quartile (Optional[str]): arearange specific option; header label in CSV for upper
            quartile value
        mean (Optional[str]): arearange specific option; header label in CSV for mean value
        value (Optional[str]): value label in CSV to be plotted in heatmap
        label (Optional[str]): optional heatmap label header to mark individual coordinates
        colors (Optional[str]): optional color definitions for observable labels
        step (Optional[int]): histogram step
        min_value (Optional[int]): optional heatmap minimum value threshold for color map
        min_color (Optional[str]): optional heatmap minimum color
        mid_color (Optional[str]): optional heatmap mid color for color map
        max_value (Optional[int]): optional heatmap maximum value threshold for color map
        max_color (Optional[str]): optional heatmap maximum color
    """
    filename = add_csv_input(csv, os.path.dirname(config))
    if colors:
        # '(-)CTRL:#1f77b4,(+)CTRL:#d62728'
        try:
            colors_dict = dict([i.split(":") for i in colors.split(",")])
        except ValueError:
            logging.warning("Unable to parse colors (%s) in key:value pairs" %
                            colors)
            colors_dict = None
        colors = colors_dict

    web_tab = WebTab(
        filename, name, status,
        ChartProperties(plot_type,
                        subtitle,
                        x_label,
                        x_value,
                        y_label,
                        y_value,
                        lower_quartile,
                        upper_quartile,
                        mean,
                        value,
                        label,
                        minimum=min_value,
                        maximum=max_value,
                        min_color=min_color,
                        mid_color=mid_color,
                        max_color=max_color,
                        colors=colors,
                        step=step))

    # append onto configuration file
    if os.path.exists(config):
        shutil.copy(config, config + '.bak')
        logging.info("Saving backup: %s" % config + '.bak')
        tab_data = import_json(config)
        if prepend:
            tab_data.insert(0, web_tab.to_dict())
        else:
            tab_data.append(web_tab.to_dict())
        try:
            with open(config, 'w') as fh:
                print(json.dumps(tab_data, indent=4), file=fh)
        except Exception:
            shutil.move(config + '.bak', config)
            logging.exception("The backup config has been restored.")
            raise
    # create new
    else:
        with open(config, 'w') as fh:
            print(json.dumps([entry], indent=4), file=fh)
    logging.info("Added entry into %s\n%s" %
                 (config, json.dumps(web_tab.to_dict(), indent=4)))