Exemplo n.º 1
0
def metropolis(tssb,
               iters=1000,
               std=0.01,
               burnin=0,
               n_ssms=0,
               n_cnvs=0,
               fin1='',
               fin2='',
               rseed=1,
               ntps=5):

    wts, nodes = tssb.get_mixture()

    # file names
    FNAME_SSM_DATA = fin1
    FNAME_CNV_DATA = fin2
    basename = os.path.basename(fin1).split('.')[0]
    FNAME_C_TREE = 'c_tree_' + basename + '_' + str(rseed) + '.txt'
    FNAME_C_DATA_STATES = 'c_data_states_' + basename + '_' + str(
        rseed) + '.txt'
    FNAME_C_PARAMS = 'c_params_' + basename + '_' + str(rseed) + '.txt'
    FNAME_C_MH_ARATIO = 'c_mh_ar_' + basename + '_' + str(rseed) + '.txt'
    NTPS = str(ntps)

    ## initialize the MH sampler###########
    #for tp in arange(ntps):
    #	sample_cons_params(tssb,tp)
    #	update_params(tssb,tp)
    ######################################

    ## prepare to call the c++ code ###########
    u2.set_node_height(tssb)
    write_tree(tssb, n_ssms, FNAME_C_TREE)  #write the current tree to the disk
    u2.map_datum_to_node(tssb)

    write_data_state(tssb, FNAME_C_DATA_STATES
                     )  # this is need for binomial parameter computations
    ###########################################

    MH_ITR = str(iters)
    MH_STD = str(std)
    N_SSM_DATA = str(n_ssms)
    N_CNV_DATA = str(n_cnvs)
    NNODES = str(len(nodes))
    TREE_HEIGHT = str(max([node.ht for node in nodes]) + 1)

    script_dir = os.path.dirname(os.path.realpath(__file__))
    sp.call([
        '%s/mh.o' % script_dir, MH_ITR, MH_STD, N_SSM_DATA, N_CNV_DATA, NNODES,
        TREE_HEIGHT, FNAME_SSM_DATA, FNAME_CNV_DATA, FNAME_C_TREE,
        FNAME_C_DATA_STATES, FNAME_C_PARAMS, FNAME_C_MH_ARATIO, NTPS
    ])
    ar = str(loadtxt(FNAME_C_MH_ARATIO, dtype='string'))
    update_tree_params(
        tssb, FNAME_C_PARAMS
    )  # update the tree with the new parameters sampled using the c++ code

    return ar
Exemplo n.º 2
0
	def __log_likelihood__(self, phi, tp, update_tree=True,new_state=0):	
		if update_tree:
					##################################################
					## some useful info about the tree,
					## used by CNV related computations,
					u.set_node_height(self.tssb)
					u.set_path_from_root_to_node(self.tssb)
					u.map_datum_to_node(self.tssb)
					##################################################
		return self.__log_complete_likelihood__(phi, self.mu_r, self.mu_v, tp, new_state)
Exemplo n.º 3
0
	def __log_likelihood__(self, phi, tp, update_tree=True,new_state=0):	
		if update_tree:
					##################################################
					## some useful info about the tree,
					## used by CNV related computations,
					u.set_node_height(self.tssb)
					u.set_path_from_root_to_node(self.tssb)
					u.map_datum_to_node(self.tssb)
					##################################################
		return self.__log_complete_likelihood__(phi, self.mu_r, self.mu_v, tp, new_state)
Exemplo n.º 4
0
def metropolis(tssb,
               iters=1000,
               std=0.01,
               burnin=0,
               nInputData=0,
               fin='',
               rseed=1,
               maxCopyNumber=6,
               baseline=0.0,
               tmp_dir='.'):
    wts, nodes = tssb.get_mixture()

    # file names
    FNAME_INPUT_DATA = fin
    FNAME_C_TREE, FNAME_C_PARAMS, FNAME_C_MH_ARATIO, FNAME_OUTPUT_DATA\
        = get_c_fnames(tmp_dir)

    ## initialize the MH sampler###########
    # sample_cons_params(tssb)
    # update_params(tssb)
    ######################################

    ## prepare to call the c++ code ###########
    u2.set_node_height(tssb)
    write_tree(tssb, FNAME_C_TREE)  # write the current tree to the disk
    u2.map_datum_to_node(tssb)
    ###########################################

    MH_ITR = str(iters)
    MH_STD = str(std)
    N_INPUT_DATA = str(nInputData)
    NNODES = str(len(nodes))
    TREE_HEIGHT = str(max([node.ht for node in nodes]) + 1)
    MAX_COPY_NUMBER = str(maxCopyNumber)
    BASELINE = str(baseline)
    script_dir = os.path.dirname(os.path.realpath(__file__))

    print['%s/mh.o' % script_dir, MH_ITR, MH_STD, N_INPUT_DATA, NNODES,
          TREE_HEIGHT, MAX_COPY_NUMBER, BASELINE, FNAME_INPUT_DATA,
          FNAME_C_TREE, FNAME_C_PARAMS, FNAME_C_MH_ARATIO, FNAME_OUTPUT_DATA]

    sp.check_call([
        '%s/mh.o' % script_dir, MH_ITR, MH_STD, N_INPUT_DATA, NNODES,
        TREE_HEIGHT, MAX_COPY_NUMBER, BASELINE, FNAME_INPUT_DATA, FNAME_C_TREE,
        FNAME_C_PARAMS, FNAME_C_MH_ARATIO, FNAME_OUTPUT_DATA
    ])

    ar = str(loadtxt(FNAME_C_MH_ARATIO, dtype='string'))

    dp = load_data_params(FNAME_OUTPUT_DATA)
    # update the tree with the new parameters sampled using the c++ code
    update_tree_params(tssb, FNAME_C_PARAMS)

    return ar, dp
Exemplo n.º 5
0
def metropolis(tssb,iters=1000,std=0.01,burnin=0,n_ssms=0,n_cnvs=0,fin1='',fin2='',rseed=1, ntps=5):

	wts, nodes = tssb.get_mixture()

	# file names
	FNAME_SSM_DATA = fin1
	FNAME_CNV_DATA = fin2
	basename = os.path.basename(fin1).split('.')[0]
	FNAME_C_TREE = 'c_tree_' + basename + '_' + str(rseed) + '.txt'
	FNAME_C_DATA_STATES = 'c_data_states_' + basename + '_' + str(rseed) + '.txt'
	FNAME_C_PARAMS = 'c_params_' + basename + '_' + str(rseed) + '.txt' ;
	FNAME_C_MH_ARATIO = 'c_mh_ar_' + basename + '_' + str(rseed) + '.txt' ;
	NTPS = str(ntps)

	## initialize the MH sampler###########
	#for tp in arange(ntps): 
	#	sample_cons_params(tssb,tp)
	#	update_params(tssb,tp)
	######################################
	
	## prepare to call the c++ code ###########
	u2.set_node_height(tssb)
	write_tree(tssb,n_ssms,FNAME_C_TREE) #write the current tree to the disk
	u2.map_datum_to_node(tssb)
	
	write_data_state(tssb,FNAME_C_DATA_STATES) # this is need for binomial parameter computations
	###########################################
	
	MH_ITR = str(iters)
	MH_STD = str(std)
	N_SSM_DATA = str(n_ssms)
	N_CNV_DATA = str(n_cnvs)
	NNODES = str(len(nodes))
	TREE_HEIGHT = str(max([node.ht for node in nodes])+1)
	
	script_dir = os.path.dirname(os.path.realpath(__file__))
	sp.call(['%s/mh.o' % script_dir, MH_ITR, MH_STD, N_SSM_DATA, N_CNV_DATA, NNODES, TREE_HEIGHT, FNAME_SSM_DATA, FNAME_CNV_DATA, FNAME_C_TREE, FNAME_C_DATA_STATES, FNAME_C_PARAMS,FNAME_C_MH_ARATIO, NTPS])
	ar = str(loadtxt(FNAME_C_MH_ARATIO,dtype='string'))
	update_tree_params(tssb,FNAME_C_PARAMS) # update the tree with the new parameters sampled using the c++ code
	
	return ar