def _method_call(self, data: str, iterations: str, project_name: str, threshold: float, debug_seed: str):
        result_means_filename = self._get_result_filename('means', data, iterations)
        result_pvalues_filename = self._get_result_filename('pvalues', data, iterations)
        result_significant_means_filename = self._get_result_filename('significant_means', data, iterations)
        result_pvalues_means_filename = self._get_result_filename('pvalues_means', data, iterations)
        result_deconvoluted_filename = self._get_result_filename('deconvoluted', data, iterations)

        meta_filename = os.path.realpath('{}/hi_{}_meta.txt'.format(data_test_dir, data))
        counts_filename = os.path.realpath('{}/hi_{}_counts.txt'.format(data_test_dir, data))

        LocalMethodLauncher(cellphonedb_app.cellphonedb).cpdb_statistical_analysis_local_method_launcher(meta_filename,
                                                                                                         counts_filename,
                                                                                                         project_name,
                                                                                                         iterations,
                                                                                                         threshold,
                                                                                                         output_test_dir,
                                                                                                         result_means_filename,
                                                                                                         result_pvalues_filename,
                                                                                                         result_significant_means_filename,
                                                                                                         result_pvalues_means_filename,
                                                                                                         result_deconvoluted_filename,
                                                                                                         debug_seed)

        self._assert_result('means', data, iterations, project_name, result_means_filename)
        self._assert_result('pvalues', data, iterations, project_name, result_pvalues_filename)
        self._assert_result('significant_means', data, iterations, project_name, result_significant_means_filename)
        self._assert_result('pvalues_means', data, iterations, project_name, result_pvalues_means_filename)
        self._assert_result('deconvoluted', data, iterations, project_name, result_deconvoluted_filename)
def analysis(meta_filename: str,
             counts_filename: str,
             counts_data: str,
             project_name: str,
             threshold: float,
             result_precision: int,
             output_path: str,
             output_format: str,
             means_result_name: str,
             significant_means_result_name: str,
             deconvoluted_result_name: str,
             verbose: bool,
             database: Optional[str],
             subsampling: bool,
             subsampling_log: bool,
             subsampling_num_pc: int,
             subsampling_num_cells: Optional[int]
             ):
    try:

        subsampler = Subsampler(subsampling_log,
                                subsampling_num_pc,
                                subsampling_num_cells,
                                verbose) if subsampling else None

        LocalMethodLauncher(cpdb_app.create_app(verbose,
                                                database)).cpdb_analysis_local_method_launcher(meta_filename,
                                                                                               counts_filename,
                                                                                               counts_data,
                                                                                               project_name,
                                                                                               threshold,
                                                                                               output_path,
                                                                                               output_format,
                                                                                               means_result_name,
                                                                                               significant_means_result_name,
                                                                                               deconvoluted_result_name,
                                                                                               result_precision,
                                                                                               subsampler,
                                                                                               )
    except (ReadFileException, ParseMetaException, ParseCountsException, ThresholdValueException,
            AllCountsFilteredException) as e:
        app_logger.error(str(e) +
                         (':' if (hasattr(e, 'description') and e.description) or (
                                 hasattr(e, 'hint') and e.hint) else '') +
                         (' {}.'.format(e.description) if hasattr(e, 'description') and e.description else '') +
                         (' {}.'.format(e.hint) if hasattr(e, 'hint') and e.hint else '')
                         )

    except EmptyResultException as e:
        app_logger.warning(str(e) +
                           (':' if (hasattr(e, 'description') and e.description) or (
                                   hasattr(e, 'hint') and e.hint) else '') +
                           (' {}.'.format(e.description) if hasattr(e, 'description') and e.description else '') +
                           (' {}.'.format(e.hint) if hasattr(e, 'hint') and e.hint else '')
                           )
    except:
        app_logger.error('Unexpected error')

        if verbose:
            traceback.print_exc(file=sys.stdout)
Exemple #3
0
    def _method_call(self, data: str, project_name: str, threshold: float,
                     result_precision: int):
        result_means_filename = self._get_result_filename(
            'means', data, threshold, result_precision)
        result_significant_means_filename = self._get_result_filename(
            'significant_means', data, threshold, result_precision)
        result_deconvoluted_filename = self._get_result_filename(
            'deconvoluted', data, threshold, result_precision)

        meta_filename = os.path.realpath('{}/hi_{}_meta.txt'.format(
            data_test_dir, data))
        counts_filename = os.path.realpath('{}/hi_{}_counts.txt'.format(
            data_test_dir, data))

        LocalMethodLauncher(
            cellphonedb_app.cellphonedb).cpdb_analysis_local_method_launcher(
                meta_filename, counts_filename, project_name, threshold,
                output_test_dir, result_means_filename,
                result_significant_means_filename,
                result_deconvoluted_filename, result_precision)

        self._assert_result('means', data, project_name, result_means_filename,
                            threshold, result_precision)
        self._assert_result('significant_means', data, project_name,
                            result_significant_means_filename, threshold,
                            result_precision)
        self._assert_result('deconvoluted', data, project_name,
                            result_deconvoluted_filename, threshold,
                            result_precision)
def analysis_scanpy(adata,
                    var_names,
                    obs_names,
                    obs_key,
                    var_key=None,
                    gene_id_format=None,
                    project_name='',
                    threshold=0.1,
                    result_precision='3',
                    output_path='',
                    output_format='csv',
                    means_result_name='means',
                    significant_means_result_name='significant_means',
                    deconvoluted_result_name='deconvoluted',
                    verbose=True,
                    database='latest',
                    subsampling=False,
                    subsampling_log=True,
                    subsampling_num_pc=100,
                    subsampling_num_cells=None,
                    write=False,
                    add_to_uns=True):
    try:

        subsampler = Subsampler(subsampling_log, subsampling_num_pc,
                                subsampling_num_cells,
                                verbose) if subsampling else None

        out = LocalMethodLauncher(cpdb_app.create_app(
            verbose, database)).cpdb_analysis_local_method_launcher_scanpy(
                adata, var_names, obs_names, obs_key, var_key, gene_id_format,
                project_name, threshold, output_path, output_format,
                means_result_name, significant_means_result_name,
                deconvoluted_result_name, result_precision, subsampler, write,
                add_to_uns)
        return out
    except (ReadFileException, ParseMetaException, ParseCountsException,
            ThresholdValueException, AllCountsFilteredException) as e:
        app_logger.error(
            str(e) + (':' if (hasattr(e, 'description') and e.description) or
                      (hasattr(e, 'hint') and e.hint) else '') +
            (' {}.'.format(e.description)
             if hasattr(e, 'description') and e.description else '') +
            (' {}.'.format(e.hint) if hasattr(e, 'hint') and e.hint else ''))

    except EmptyResultException as e:
        app_logger.warning(
            str(e) + (':' if (hasattr(e, 'description') and e.description) or
                      (hasattr(e, 'hint') and e.hint) else '') +
            (' {}.'.format(e.description)
             if hasattr(e, 'description') and e.description else '') +
            (' {}.'.format(e.hint) if hasattr(e, 'hint') and e.hint else ''))
    except:
        app_logger.error('Unexpected error')

        if verbose:
            traceback.print_exc(file=sys.stdout)
Exemple #5
0
def statistical_analysis(meta_filename: str,
                         counts_filename: str,
                         project_name: str,
                         iterations: int,
                         threshold: float,
                         result_precision: int,
                         output_path: str,
                         means_result_name: str,
                         pvalues_result_name: str,
                         significant_mean_result_name: str,
                         means_pvalues_result_name: str,
                         deconvoluted_result_name: str,
                         debug_seed: int,
                         threads: int,
                         verbose: bool,
                         ) -> None:
    try:
        LocalMethodLauncher(cpdb_app.create_app(verbose)). \
            cpdb_statistical_analysis_local_method_launcher(meta_filename,
                                                            counts_filename,
                                                            project_name,
                                                            iterations,
                                                            threshold,
                                                            output_path,
                                                            means_result_name,
                                                            pvalues_result_name,
                                                            significant_mean_result_name,
                                                            means_pvalues_result_name,
                                                            deconvoluted_result_name,
                                                            debug_seed,
                                                            threads,
                                                            result_precision
                                                            )
    except (ReadFileException, ParseMetaException, ParseCountsException, ThresholdValueException,
            AllCountsFilteredException) as e:
        app_logger.error(str(e) +
                         (':' if (hasattr(e, 'description') and e.description) or (
                                 hasattr(e, 'hint') and e.hint) else '') +
                         (' {}.'.format(e.description) if hasattr(e, 'description') and e.description else '') +
                         (' {}.'.format(e.hint) if hasattr(e, 'hint') and e.hint else '')
                         )

    except EmptyResultException as e:
        app_logger.warning(str(e) +
                           (':' if (hasattr(e, 'description') and e.description) or (
                                   hasattr(e, 'hint') and e.hint) else '') +
                           (' {}.'.format(e.description) if hasattr(e, 'description') and e.description else '') +
                           (' {}.'.format(e.hint) if hasattr(e, 'hint') and e.hint else '')
                           )
    except:
        app_logger.error('Unexpected error')
        if (verbose):
            traceback.print_exc(file=sys.stdout)
def analysis(meta_filename: str, counts_filename: str, project_name: str,
             threshold: float, output_path: str, means_result_name: str,
             deconvoluted_result_name: str, verbose: bool):
    LocalMethodLauncher(
        cpdb_app.create_app(verbose)).cpdb_analysis_local_method_launcher(
            meta_filename,
            counts_filename,
            project_name,
            threshold,
            output_path,
            means_result_name,
            deconvoluted_result_name,
        )
def statistical_analysis(meta_filename: str, counts_filename: str,
                         project_name: str, iterations: str, threshold: float,
                         output_path: str, means_result_name: str,
                         pvalues_result_name: str,
                         significant_mean_result_name: str,
                         means_pvalues_result_name: str,
                         deconvoluted_result_name: str, debug_seed: str,
                         threads: int, verbose: bool):
    print(verbose)
    LocalMethodLauncher(cpdb_app.create_app(
        verbose)).cpdb_statistical_analysis_local_method_launcher(
            meta_filename, counts_filename, project_name, iterations,
            threshold, output_path, means_result_name, pvalues_result_name,
            significant_mean_result_name, means_pvalues_result_name,
            deconvoluted_result_name, debug_seed, threads)
Exemple #8
0
    def _method_call(self,
                     data: str,
                     project_name: str,
                     threshold: float,
                     result_precision: int,
                     subsampler: Optional[Subsampler] = None,
                     counts_data: str = 'ensembl'):
        result_names_as_fixture = False
        if result_names_as_fixture:
            result_deconvoluted_filename, result_means_filename, result_significant_means_filename = self._original_names(
                data, result_precision, threshold)
        else:
            result_means_filename = self._get_result_filename(
                'means', data, threshold, result_precision)
            result_significant_means_filename = self._get_result_filename(
                'significant_means', data, threshold, result_precision)
            result_deconvoluted_filename = self._get_result_filename(
                'deconvoluted', data, threshold, result_precision)

        meta_filename = os.path.realpath('{}/hi_{}_meta.txt'.format(
            data_test_dir, data))

        if counts_data == 'ensembl':
            counts_file = '{}/hi_{}_counts.txt'.format(data_test_dir, data)
        else:
            counts_file = '{}/hi_{}_counts_{}.txt'.format(
                data_test_dir, data, counts_data)

        counts_filename = os.path.realpath(counts_file)

        LocalMethodLauncher(
            cellphonedb_app.cellphonedb).cpdb_analysis_local_method_launcher(
                meta_filename, counts_filename, counts_data, project_name,
                threshold, output_test_dir, 'txt', result_means_filename,
                result_significant_means_filename,
                result_deconvoluted_filename, result_precision, subsampler)

        self._assert_result('means', data, project_name, result_means_filename,
                            threshold, result_precision)
        self._assert_result('significant_means', data, project_name,
                            result_significant_means_filename, threshold,
                            result_precision)
        self._assert_result('deconvoluted', data, project_name,
                            result_deconvoluted_filename, threshold,
                            result_precision)
Exemple #9
0
def analysis(meta_filename: str, counts_filename: str, project_name: str,
             threshold: float, output_path: str, means_result_name: str,
             deconvoluted_result_name: str, verbose: bool):
    try:
        LocalMethodLauncher(
            cpdb_app.create_app(verbose)).cpdb_analysis_local_method_launcher(
                meta_filename,
                counts_filename,
                project_name,
                threshold,
                output_path,
                means_result_name,
                deconvoluted_result_name,
            )
    except (ReadFileException, ParseMetaException) as e:
        app_logger.error(e)
    except:
        app_logger.error('Unexpected error')
Exemple #10
0
def statistical_analysis(meta_filename: str, counts_filename: str,
                         project_name: str, iterations: str, threshold: float,
                         output_path: str, means_result_name: str,
                         pvalues_result_name: str,
                         significant_mean_result_name: str,
                         means_pvalues_result_name: str,
                         deconvoluted_result_name: str, debug_seed: str,
                         threads: int, verbose: bool):
    print(verbose)
    try:
        LocalMethodLauncher(cpdb_app.create_app(
            verbose)).cpdb_statistical_analysis_local_method_launcher(
                meta_filename, counts_filename, project_name, iterations,
                threshold, output_path, means_result_name, pvalues_result_name,
                significant_mean_result_name, means_pvalues_result_name,
                deconvoluted_result_name, debug_seed, threads)
    except (ReadFileException, ParseMetaException) as e:
        app_logger.error(e)
    except:
        app_logger.error('Unexpected error')
    def _method_call(
        self,
        data: str,
        iterations: int,
        project_name: str,
        threshold: float,
        debug_seed: int,
        result_precision: int,
        subsampler: Optional[Subsampler] = None,
    ):

        result_names_as_fixture = False
        if result_names_as_fixture:
            result_deconvoluted_filename, result_means_filename, result_pvalues_filename, result_significant_means_filename = self._original_names(
                data, debug_seed, iterations, result_precision, threshold)

        else:
            result_means_filename = self._get_result_filename(
                'means', data, iterations, debug_seed, threshold,
                result_precision)
            result_pvalues_filename = self._get_result_filename(
                'pvalues', data, iterations, debug_seed, threshold,
                result_precision)
            result_significant_means_filename = self._get_result_filename(
                'significant_means', data, iterations, debug_seed, threshold,
                result_precision)
            result_deconvoluted_filename = self._get_result_filename(
                'deconvoluted', data, iterations, debug_seed, threshold,
                result_precision)

        meta_filename = os.path.realpath('{}/hi_{}_meta.txt'.format(
            data_test_dir, data))
        counts_filename = os.path.realpath('{}/hi_{}_counts.txt'.format(
            data_test_dir, data))

        LocalMethodLauncher(cellphonedb_app.cellphonedb). \
            cpdb_statistical_analysis_local_method_launcher(meta_filename,
                                                            counts_filename,
                                                            'ensembl',
                                                            project_name,
                                                            iterations,
                                                            threshold,
                                                            output_test_dir,
                                                            'txt',
                                                            result_means_filename,
                                                            result_pvalues_filename,
                                                            result_significant_means_filename,
                                                            result_deconvoluted_filename,
                                                            debug_seed,
                                                            result_precision=result_precision,
                                                            subsampler=subsampler,
                                                            )

        self._assert_result('means', data, iterations, project_name,
                            result_means_filename, debug_seed, threshold,
                            result_precision)
        self._assert_result('pvalues', data, iterations, project_name,
                            result_pvalues_filename, debug_seed, threshold,
                            result_precision)
        self._assert_result('significant_means', data, iterations,
                            project_name, result_significant_means_filename,
                            debug_seed, threshold, result_precision)
        self._assert_result('deconvoluted', data, iterations, project_name,
                            result_deconvoluted_filename, debug_seed,
                            threshold, result_precision)
def statistical_analysis(meta_filename: str,
                         counts_filename: str,
                         counts_data='ensembl',
                         project_name='',
                         threshold=0.1,
                         result_precision='3',
                         output_path='',
                         output_format='csv',
                         means_result_name='means',
                         significant_means_result_name='significant_means',
                         deconvoluted_result_name='deconvoluted',
                         verbose=True,
                         database='latest',
                         subsampling=False,
                         subsampling_log=True,
                         subsampling_num_pc=100,
                         subsampling_num_cells=None,
                         debug_seed='-1',
                         pvalue=0.05,
                         pvalues_result_name='pvalues',
                         iterations=1000,
                         threads=4) -> None:
    database = choose_database(None, None, value=database)
    try:

        subsampler = Subsampler(subsampling_log, subsampling_num_pc,
                                subsampling_num_cells,
                                verbose) if subsampling else None

        LocalMethodLauncher(cpdb_app.create_app(verbose, database)). \
            cpdb_statistical_analysis_local_method_launcher(meta_filename,
                                                            counts_filename,
                                                            counts_data,
                                                            project_name,
                                                            iterations,
                                                            threshold,
                                                            output_path,
                                                            output_format,
                                                            means_result_name,
                                                            pvalues_result_name,
                                                            significant_means_result_name,
                                                            deconvoluted_result_name,
                                                            debug_seed,
                                                            threads,
                                                            result_precision,
                                                            pvalue,
                                                            subsampler,
                                                            )
    except (ReadFileException, ParseMetaException, ParseCountsException,
            ThresholdValueException, AllCountsFilteredException) as e:
        app_logger.error(
            str(e) + (':' if (hasattr(e, 'description') and e.description) or
                      (hasattr(e, 'hint') and e.hint) else '') +
            (' {}.'.format(e.description)
             if hasattr(e, 'description') and e.description else '') +
            (' {}.'.format(e.hint) if hasattr(e, 'hint') and e.hint else ''))

    except EmptyResultException as e:
        app_logger.warning(
            str(e) + (':' if (hasattr(e, 'description') and e.description) or
                      (hasattr(e, 'hint') and e.hint) else '') +
            (' {}.'.format(e.description)
             if hasattr(e, 'description') and e.description else '') +
            (' {}.'.format(e.hint) if hasattr(e, 'hint') and e.hint else ''))
    except:
        app_logger.error('Unexpected error')
        if verbose:
            traceback.print_exc(file=sys.stdout)