示例#1
0
def heatmaps_plot_results(meta: str, pvalues: str, job_id: str):
    with tempfile.TemporaryDirectory() as output_path:
        with tempfile.NamedTemporaryFile(suffix=os.path.splitext(pvalues)[-1]) as pvalues_file:
            with tempfile.NamedTemporaryFile() as meta_file:
                _from_s3_to_temp(pvalues, pvalues_file)
                _from_s3_to_temp(meta, meta_file)

                count_name = 'plot_count__{}.png'.format(job_id)
                count_log_name = 'plot_count_log__{}.png'.format(job_id)

                heatmaps_plot(meta_file.name, pvalues_file.name, output_path, count_name, count_log_name)

                output_count_file = os.path.join(output_path, count_name)
                output_count_log_file = os.path.join(output_path, count_log_name)

                if not os.path.exists(output_count_file) or not os.path.exists(output_count_log_file):
                    raise PlotException('Could not generate output file for plot of type dot_plot')

                response = {
                    'job_id': job_id,
                    'files': {
                        'count_plot': count_name,
                        'count_log_plot': count_log_name
                    },
                    'success': True
                }

                write_image_to_s3(output_count_file, count_name)
                write_image_to_s3(output_count_log_file, count_log_name)

                return response
示例#2
0
def heatmap_plot(meta_path: str, pvalues_path: str, output_path: str, count_name: str, log_name: str, verbose: bool):
    try:
        r_plotter.heatmaps_plot(meta_path, pvalues_path, output_path, log_name, count_name)
    except MissingR:
        print('You cannot perform this plot command unless there is a working R setup according to CellPhoneDB specs')
    except RRuntimeException as e:
        app_logger.error(str(e))
    except:
        app_logger.error('Unexpected error')

        if verbose:
            traceback.print_exc(file=sys.stdout)
        else:
            app_logger.error('execute with --verbose to see full stack trace')
    def test_heatmaps_plot(self):
        meta_path = self._get_fixture('hi_test_meta.txt')
        pvalues_path = self._get_input_file_path_for('pvalues')
        plot_output_counts = 'heatmaps_plot_counts.png'
        plot_output_count_logs = 'heatmaps_plot_count_logs.png'

        heatmaps_plot(meta_file=meta_path,
                      pvalues_file=pvalues_path,
                      output_path=output_test_dir,
                      count_name=plot_output_counts,
                      log_name=plot_output_count_logs,
                      pvalue=0.05)

        for file in [plot_output_counts, plot_output_count_logs]:
            output_path = os.path.join(output_test_dir, file)
            self.assertTrue(os.path.exists(output_path),
                            'Plot of type heatmap_plot did not work')
            self.assertGreater(os.path.getsize(output_path), 0)
            os.remove(output_path)