Пример #1
0
def run_tool(args):
    logging.debug('Arguments {}'.format(args))

    # init a Patient
    patient_data = Patient.Patient(indiv_name=args.indiv_id,
                                   driver_genes_file=args.driver_genes_file)

    # Patient load cluster and mut ccf files
    parse_sif_file(args.sif, args.mutation_ccf_file, patient_data)
    load_clustering_results(args.cluster_ccf_file, patient_data)

    tree_edges = load_tree_edges_file(args.tree_tsv)
    bt_engine = BuildTreeEngine(patient_data)
    tree = Tree()
    tree.init_tree_from_clustering(patient_data.ClusteringResults)
    tree.set_new_edges(tree_edges)
    patient_data.TopTree = tree

    patient_data.TopTree = bt_engine.top_tree
    patient_data.TreeEnsemble = bt_engine.trees

    gk_engine = GrowthKineticsEngine(patient_data)

    gk_engine.estimate_growth_rate(args.n_iter)
    """
Пример #2
0
def run_tool(args):
    logging.debug('Arguments {}'.format(args))
    import data.Patient as Patient
    from .GrowthKineticsEngine import GrowthKineticsEngine

    patient_data = Patient.Patient(indiv_name=args.indiv_id)
    mcmc_trace_cell_abundance, num_itertaions = load_mcmc_trace_abundances(
        args.abundance_mcmc_trace)
    with open(args.sif, 'r') as f:
        header = f.readline().strip('\n').split('\t')
        sample_time_points = {}
        for line in f:
            fields = dict(zip(header, line.strip('\n').split('\t')))
            try:
                sample_time_points[fields['sample_id']] = float(
                    fields['timepoint'])
            except ValueError:
                raise ValueError('Sample time points in sif file are required')
    wbc_time_points = np.array(args.time) if args.time is not None else None
    gk_engine = GrowthKineticsEngine(patient_data, args.wbc)
    gk_engine.estimate_growth_rate(mcmc_trace_cell_abundance,
                                   wbc_time_points=wbc_time_points,
                                   sample_time_points=sample_time_points,
                                   n_iter=min(num_itertaions, args.n_iter))

    # Output and visualization
    import output.PhylogicOutput
    phylogicoutput = output.PhylogicOutput.PhylogicOutput()
    phylogicoutput.write_growth_rate_tsv(gk_engine.growth_rates, args.indiv_id)
    phylogicoutput.plot_growth_rates(gk_engine.growth_rates, args.indiv_id)
Пример #3
0
def run_tool(args):
    logging.debug('Arguments {}'.format(args))

    import data.Patient as Patient
    from .CellPopulationEngine import CellPopulationEngine
    from .BuildTreeEngine import BuildTreeEngine
    import output.PhylogicOutput

    # init a Patient
    patient_data = Patient.Patient(indiv_name=args.indiv_id,
                                   driver_genes_file=args.driver_genes_file)

    # Patient load cluster and mut ccf files
    parse_sif_file(args.sif, args.mutation_ccf_file, patient_data)
    load_clustering_results(args.cluster_ccf_file, patient_data,
                            args.blacklist_threshold, args.blacklist_cluster)
    patient_data.preprocess_samples()
    # Building Phylogenetic Tree
    bt_engine = BuildTreeEngine(patient_data)
    bt_engine.build_tree(n_iter=args.n_iter)
    # Output and visualization
    phylogicoutput = output.PhylogicOutput.PhylogicOutput()
    # Assign Top tree to Patient
    patient_data.TopTree = bt_engine.top_tree
    patient_data.TreeEnsemble = bt_engine.mcmc_trace
    phylogicoutput.write_tree_tsv(bt_engine.mcmc_trace, args.indiv_id)

    # TODO: Fix this
    # patient_data.TreeEnsemble = bt_engine.trees

    # Computing Cell Population
    cp_engine = CellPopulationEngine(patient_data)
    constrained_ccf = cp_engine.compute_constrained_ccf(n_iter=args.n_iter)

    cell_abundance = cp_engine.get_cell_abundance_across_samples(
        constrained_ccf)

    phylogicoutput.write_all_cell_abundances(
        cp_engine.get_all_cell_abundances(), args.indiv_id)
    cell_ancestry = bt_engine.get_cell_ancestry()
    phylogicoutput.write_constrained_ccf_tsv(constrained_ccf, cell_ancestry,
                                             args.indiv_id)
    phylogicoutput.write_cell_abundances_tsv(cell_abundance, cell_ancestry,
                                             args.indiv_id)
    phylogicoutput.generate_html_from_tree(
        args.mutation_ccf_file,
        args.cluster_ccf_file,
        args.indiv_id + '_build_tree_posteriors.tsv',
        args.indiv_id + '_constrained_ccf.tsv',
        sif=args.sif,
        drivers=patient_data.driver_genes,
        treatment_file=args.treatment_data,
        tumor_sizes_file=args.tumor_size,
        cnv_file=args.indiv_id + '.cnvs.txt')
Пример #4
0
def run_tool(args):
    logging.debug('Arguments {}'.format(args))

    import data.Patient as Patient
    from .CellPopulationEngine import CellPopulationEngine
    from .BuildTreeEngine import BuildTreeEngine
    from .ClusteringResults import ClusteringResults

    # init a Patient
    patient_data = Patient.Patient(indiv_name=args.indiv_id,
                                   driver_genes_file=args.driver_genes_file)

    # Patient load cluster and mut ccf files
    clustering_results = ClusteringResults(args.mutation_ccf_file,
                                           args.cluster_ccf_file)
    patient_data.ClusteringResults = clustering_results

    bt_engine = BuildTreeEngine(patient_data)

    bt_engine.build_tree(args.n_iter)

    patient_data.TopTree = bt_engine.top_tree
    patient_data.TreeEnsemble = bt_engine.trees

    cp_engine = CellPopulationEngine(patient_data)
    constrained_ccf = cp_engine.samples_average_constrained_ccf()
    cell_ancestry = bt_engine.get_cell_ancestry()
    cell_abundance = cp_engine.get_cell_abundance(constrained_ccf)

    # Output and visualization
    import output.PhylogicOutput
    phylogicoutput = output.PhylogicOutput.PhylogicOutput()
    phylogicoutput.write_tree_tsv(bt_engine.mcmc_trace, bt_engine.trees_ll,
                                  args.indiv_id)
    phylogicoutput.write_constrained_ccf_tsv(constrained_ccf, cell_ancestry,
                                             args.indiv_id)
    phylogicoutput.write_cell_abundances_tsv(cell_abundance, cell_ancestry,
                                             args.indiv_id)
    phylogicoutput.generate_html_from_tree(
        args.mutation_ccf_file,
        args.cluster_ccf_file,
        args.indiv_id + '_build_tree_posteriors.tsv',
        args.indiv_id + '_constrained_ccf.tsv',
        sif=args.sif,
        drivers=patient_data.driver_genes,
        treatment_file=args.treatment_data,
        tumor_sizes_file=args.tumor_size,
        cnv_file=args.indiv_id + '.cnvs.txt')
Пример #5
0
def run_tool(args):
    logging.debug('Arguments {}'.format(args))

    import data.Patient as Patient
    from .Tree import Tree
    from .CellPopulationEngine import CellPopulationEngine
    from .BuildTreeEngine import BuildTreeEngine

    # init a Patient
    patient_data = Patient.Patient(indiv_name=args.indiv_id,
                                   driver_genes_file=args.driver_genes_file)
    # try:  # if sif file is specified
    # Patient load cluster and mut ccf files
    parse_sif_file(args.sif, args.mutation_ccf_file, patient_data)
    load_clustering_results(args.cluster_ccf_file, patient_data)
    tree_edges = load_tree_edges_file(args.tree_tsv)
    bt_engine = BuildTreeEngine(patient_data)
    tree = Tree()
    tree.init_tree_from_clustering(patient_data.ClusteringResults)
    tree.set_new_edges(tree_edges)
    patient_data.TopTree = tree
    # Computing Cell Population
    cp_engine = CellPopulationEngine(patient_data)
    constrained_ccf = cp_engine.compute_constrained_ccf()

    cell_ancestry = bt_engine.get_cell_ancestry()
    cell_abundance = cp_engine.get_cell_abundance(constrained_ccf)
    # Output and visualization
    import output.PhylogicOutput
    phylogicoutput = output.PhylogicOutput.PhylogicOutput()
    # TODO write cell population MCMC trace to file
    phylogicoutput.write_all_cell_abundances(
        cp_engine.get_all_cell_abundances(), args.indiv_id)
    phylogicoutput.write_constrained_ccf_tsv(constrained_ccf, cell_ancestry,
                                             args.indiv_id)
    phylogicoutput.write_cell_abundances_tsv(cell_abundance, cell_ancestry,
                                             args.indiv_id)
    phylogicoutput.generate_html_from_tree(
        args.mutation_ccf_file,
        args.cluster_ccf_file,
        args.indiv_id + '_build_tree_posteriors.tsv',
        args.indiv_id + '_constrained_ccf.tsv',
        sif=args.sif,
        drivers=patient_data.driver_genes,
        treatment_file=args.treatment_data,
        tumor_sizes_file=args.tumor_size,
        cnv_file=args.indiv_id + '.cnvs.txt')
Пример #6
0
    def addPatient(self, name, ipp, MainWindow):
        """Method to add and save a new patient using the fields"""
        #Confirmation message
        qm = QtWidgets.QMessageBox()
        reply = qm.question(
            MainWindow, 'Continuer ?',
            'Voulez vraiment ajouter ' + name + "(" + ipp + ") ?", qm.Yes,
            qm.No)
        if reply == qm.Yes:
            new = data.deserialize()
            new.getListPatient().append(Patient(name, ipp))
            data.seralize(new)
            self.syncData()

            #Clear fields
            self.lineEdit_name.setText("")
            self.lineEdit_ipp.setText("")
Пример #7
0
def run_tool(args):
    logging.debug('Arguments {}'.format(args))
    import data.Patient as Patient
    from .GrowthKineticsEngine import GrowthKineticsEngine

    patient_data = Patient.Patient(indiv_name=args.indiv_id)
    mcmc_trace_cell_abundance, num_itertaions = load_mcmc_trace_abundances(
        args.abundance_mcmc_trace)
    gk_engine = GrowthKineticsEngine(patient_data, args.wbc)
    gk_engine.estimate_growth_rate(mcmc_trace_cell_abundance,
                                   n_iter=min(num_itertaions, args.n_iter))

    # Output and visualization
    import output.PhylogicOutput
    phylogicoutput = output.PhylogicOutput.PhylogicOutput()
    phylogicoutput.write_growth_rate_tsv(gk_engine.growth_rates, args.indiv_id)
    phylogicoutput.plot_growth_rates(gk_engine.growth_rates, args.indiv_id)
Пример #8
0
def run_tool(args):
    print(args)
    if not args.maf and not args.html:
        print("No output type specified, specify any combination of --html and --maf")

    # sys.path.append(args.phylogic_path)
    # data storage objects
    import data.Patient as Patient
    import data.Sample as Sample

    import ClusterEngine
    import DpEngine
    if not os.path.isfile(args.PoN):
        logging.warning("PanelofNormals (PoN) inaccessible or not specified - not using PoN!")
        PoN = False
    else:
        PoN = args.PoN

    # init a Patient
    patient_data = Patient.Patient(artifact_blacklist=args.artifact_blacklist,
                                   PoN_file=PoN, indiv_name=args.indiv_id, artifact_whitelist=args.artifact_whitelist,
                                   min_coverage=args.min_cov, use_indels=args.use_indels,
                                   impute_missing=args.impute_missing,
                                   driver_genes_file=args.driver_genes_file)

    # delete_auto_bl=args.Delete_Blacklist,
    # Load sample data

    if args.sif:  # if sif file is specified
        sif_file = open(args.sif)

        for file_idx, file_line in enumerate(sif_file):

            ##for now, assume input file order is of the type sample_id\tmaf_fn\tseg_fn\tpurity\ttimepoint
            if not file_idx:
                continue
            if file_line.strip('\n').strip == "":
                continue  # empty rows
            smpl_spec = file_line.strip('\n').split('\t')
            sample_id = smpl_spec[0]
            maf_fn = smpl_spec[1]
            seg_fn = smpl_spec[2]
            purity = float(smpl_spec[3])
            timepoint = float(smpl_spec[4])
            print(timepoint)
            patient_data.addSample(maf_fn, sample_id, timepoint_value=timepoint, grid_size=args.grid_size,
                                   _additional_muts=None, seg_file=seg_fn,
                                   purity=purity, input_type=args.maf_input_type)

            if len(patient_data.sample_list) == args.n_samples:  # use only first N samples
                break

    else:  # if sample names/files are specified directly on cmdline

        # sort order on timepoint or order of entry on cmdline if not present
        print(args.sample_data)
        for idx, sample_entry in enumerate(args.sample_data):
            ##for now, assume input order is of the type sample_id\tmaf_fn\tseg_fn\tpurity\ttimepoint
            smpl_spec = sample_entry.strip('\n').split(':')
            sample_id = smpl_spec[0]
            maf_fn = smpl_spec[1]
            seg_fn = smpl_spec[2]
            purity = float(smpl_spec[3])
            timepoint = float(smpl_spec[4])

            patient_data.addSample(maf_fn, sample_id, timepoint_value=timepoint, grid_size=args.grid_size,
                                   _additional_muts=None,
                                   seg_file=seg_fn,
                                   purity=purity)
            if len(patient_data.sample_list) == args.n_samples:  # use only first N samples
                break

    patient_data.get_arm_level_cn_events()
    patient_data.preprocess_samples()

    # TODO: how 1D (one sample) is handeled
    DP_Cluster = ClusterEngine.ClusterEngine(patient_data)  # html_out=args.indiv_id + '.html')

    DP_Cluster.run_DP_ND(N_iter=args.iter, PriorK={'r': args.Pi_k_r, 'mu': args.Pi_k_mu},
                         mode="maxpear", seed=args.seed)

    patient_data.ClusteringResults = DP_Cluster.results
    patient_data.cluster_temp_removed()
    # sample_id = args.indiv_id

    # Output and visualization
    import output.PhylogicOutput
    phylogicoutput = output.PhylogicOutput.PhylogicOutput()
    cluster_ccfs = {i + 1: ccf_hists for i, ccf_hists in enumerate(patient_data.ClusteringResults.clust_CCF_dens)}
    phylogicoutput.write_patient_cluster_ccfs(patient_data, cluster_ccfs)
    phylogicoutput.write_patient_mut_ccfs(patient_data, cluster_ccfs)
    phylogicoutput.write_patient_cnvs(patient_data, cluster_ccfs)
    phylogicoutput.write_patient_unclustered_events(patient_data)
    phylogicoutput.plot_1d_clusters('{}.cluster_ccfs.txt'.format(patient_data.indiv_name))
    phylogicoutput.plot_1d_mutations('{}.mut_ccfs.txt'.format(patient_data.indiv_name))

    if not args.buildtree:  # run only Clustering tool
        phylogicoutput.generate_html_from_clustering_results(patient_data.ClusteringResults, patient_data,
                                                             drivers=patient_data.driver_genes,
                                                             treatment_file=args.treatment_data)

    else:  # run build tree next
        import BuildTree.BuildTree
        args.cluster_ccf_file = '{}.cluster_ccfs.txt'.format(patient_data.indiv_name)
        args.mutation_ccf_file = '{}.mut_ccfs.txt'.format(patient_data.indiv_name)
        args.n_iter = args.iter
        args.blacklist_cluster = None
        BuildTree.BuildTree.run_tool(args)