:param pyramid: hic pyramid
160713
def load_data(self, pyramid):
        
        import colorsys

        logger.info("loading data from level = {}".format(self.level))
        # self.im_init = np.array(pyramid.data[str(self.level)],
        # dtype=np.int32)
        # self.n_frags = self.im_init.shape[0]

        # start loading sparse matrix #####
        self.n_frags = int(np.copy(pyramid.data[str(self.level)]["nfrags"][0]))
        self.np_2_scipy_sparse = np.copy(pyramid.data[str(self.level)]["data"])
        self.sparse_mat_csr = sp.csr_matrix(
            (self.np_2_scipy_sparse[2, :], self.np_2_scipy_sparse[0:2, :]),
            shape=(self.n_frags, self.n_frags),
        )
        self.sparse_mat_csc = sp.csc_matrix(
            (self.np_2_scipy_sparse[2, :], self.np_2_scipy_sparse[0:2, :]),
            shape=(self.n_frags, self.n_frags),
        )
        # end loading sparse matrix #####

        int_n_frags = np.int32(self.n_frags)
        self.pos_vect_frags_4_GL = np.ndarray(
            (int_n_frags, 4), dtype=np.float32
        )
        self.col_vect_frags_4_GL = np.ndarray(
            (int_n_frags, 4), dtype=np.float32
        )

        self.dict_contigs = dict()
        ContFrags = pyramid.spec_level[str(self.level)]["contigs_dict"]
        if str(self.level - 1) in pyramid.spec_level:
            subContFrags = pyramid.spec_level[str(self.level - 1)][
                "contigs_dict"
            ]
        else:
            subContFrags = ContFrags
        coord_cont = dict()

        n_contigs = len(list(ContFrags.keys()))
        # print "n init contigs = ", n_contigs
        HSV_tuples = [
            (x * 2.5 / n_contigs, 0.5, 0.5) for x in range(n_contigs)
        ]
        RGB_tuples = [colorsys.hsv_to_rgb(*x) for x in HSV_tuples]
        self.distri_frag = []

        # list_contigs = ContFrags.keys()
        # print "Cont frags keys = ", ContFrags.keys()
        list_contigs_id = pyramid.list_contigs_id
        # debugggg
        # list_contigs.sort()

        for i in range(0, self.n_frags):
            self.frags_init_contigs.append("")

        for id_cont in list_contigs_id:
            self.dict_contigs[id_cont] = dict()
            cont_frag = ContFrags[id_cont]
            sub_cont_frag = subContFrags[id_cont]
            coord_cont[id_cont] = []
            name_contig = cont_frag[0].init_contig
            tick_kb = []
            end_frags_kb = []

            id_f_prev = -1
            lim_curr_cont = len(cont_frag)
            sub_lim_curr_cont = len(sub_cont_frag)
            len_curr_contig_bp = 0
            curr_sub_pos = 0
            for id_f in range(0, lim_curr_cont):
                f = cont_frag[id_f]
                lkb = f.length_kb
                len_curr_contig_bp += lkb
            for id_f in range(0, lim_curr_cont):
                f = cont_frag[id_f]
                lkb = f.length_kb
                self.distri_frag.append(lkb)
                start = f.start_pos
                end = f.end_pos
                pos_kb = start + lkb / 2.0
                tick_kb.append(pos_kb)
                end_frags_kb.append(end)
                id_f_curr = f.np_id_abs - 1
                n_accu_frags = f.n_accu_frags
                n_sub_frags = f.sub_frag_end - f.sub_frag_start + 1

                self.frags_init_contigs[id_f_curr] = f.init_contig

                if id_f < lim_curr_cont - 1:
                    id_f_next = cont_frag[id_f + 1].np_id_abs - 1
                else:
                    id_f_next = -1
                f_T_frag = (
                    np.int32(f.curr_id - 1),
                    np.int32(f.contig_id),
                    np.int32(start),
                    np.int32(lkb),
                    np.int32(0),
                    np.int32(id_f_curr),
                    np.int32(id_f_prev),
                    np.int32(id_f_next),
                    np.int32(lim_curr_cont),
                    np.int32(len_curr_contig_bp),
                    np.int32(n_accu_frags),
                )
                self.pos_vect_frags_4_GL[id_f_curr, 0] = (
                    np.float32(f.curr_id - 1) / 100.0
                )
                self.pos_vect_frags_4_GL[id_f_curr, 1] = (
                    np.float32(f.contig_id) / 100.0
                )
                # self.pos_vect_frags_4_GL[id_f_curr, 2] = np.float32(0.0)
                self.pos_vect_frags_4_GL[id_f_curr, 2] = 0.0
                self.pos_vect_frags_4_GL[id_f_curr, 3] = np.float32(1.0)
                # GL_pos_frag = (np.float32(f.curr_id - 1),
                #            np.float32(f.contig_id),
                #            np.float32(lim_curr_cont),
                #            np.float32(0.0))
                # self.col_vect_frags_4_GL[id_f_curr,0] = np.float32(0.)
                # self.col_vect_frags_4_GL[id_f_curr,1] = np.float32(1.)
                # self.col_vect_frags_4_GL[id_f_curr,2] = np.float32(0.)
                # self.col_vect_frags_4_GL[id_f_curr,3] = np.float32(1.)
                self.col_vect_frags_4_GL[id_f_curr, 0] = np.float32(
                    RGB_tuples[id_cont - 1][0]
                )
                self.col_vect_frags_4_GL[id_f_curr, 1] = np.float32(
                    RGB_tuples[id_cont - 1][1]
                )
                self.col_vect_frags_4_GL[id_f_curr, 2] = np.float32(
                    RGB_tuples[id_cont - 1][2]
                )
                self.col_vect_frags_4_GL[id_f_curr, 3] = np.float32(1.0)

                # GL_col_frag = (np.float32(RGB_tuples[id_cont - 1][0],
                #                np.float32(RGB_tuples[id_cont - 1][1]),
                #                np.float32(RGB_tuples[id_cont - 1][2]),
                #                np.float32(1.0))
                self.S_o_A_frags["pos"].append(f.curr_id - 1)
                self.S_o_A_frags["sub_pos"].append(curr_sub_pos)  # TO DO !!!!
                self.S_o_A_frags["id_c"].append(f.contig_id)
                self.S_o_A_frags["start_bp"].append(start)
                self.S_o_A_frags["len_bp"].append(lkb)
                self.S_o_A_frags["sub_len"].append(n_sub_frags)
                self.S_o_A_frags["circ"].append(0)
                self.S_o_A_frags["id"].append(id_f_curr)
                self.S_o_A_frags["prev"].append(id_f_prev)
                self.S_o_A_frags["next"].append(id_f_next)
                self.S_o_A_frags["l_cont"].append(lim_curr_cont)
                self.S_o_A_frags["sub_l_cont"].append(sub_lim_curr_cont)
                self.S_o_A_frags["l_cont_bp"].append(len_curr_contig_bp)
                self.S_o_A_frags["n_accu"].append(n_accu_frags)

                id_f_prev = id_f_curr
                self.vect_frag_np.append(f_T_frag)
                curr_sub_pos += n_sub_frags

                # self.pos_vect_frags_4_GL.append(GL_pos_frag)
                # self.col_vect_frags_4_GL.append(GL_col_frag)
            for f in cont_frag:
                coord_cont[id_cont].append(f.np_id_abs - 1)
            self.dict_contigs[id_cont]["intra_coord"] = coord_cont[id_cont]
            self.dict_contigs[id_cont]["frags"] = cont_frag
            self.dict_contigs[id_cont]["name"] = name_contig
            self.dict_contigs[id_cont]["tick_kb"] = np.array(tick_kb)
            self.dict_contigs[id_cont]["end_frags_kb"] = np.array(end_frags_kb)
            #######################

        self.vect_frag_np = np.array(self.vect_frag_np, dtype=self.T_frag)

        # self.pos_vect_frags_4_GL = np.array(self.pos_vect_frags_4_GL,
        # dtype=self.float4) self.col_vect_frags_4_GL =
        # np.array(self.col_vect_frags_4_GL, dtype=self.float4)

        for key in list(self.S_o_A_frags.keys()):
            self.S_o_A_frags[key] = np.array(
                self.S_o_A_frags[key], dtype=np.int32
            )

        total_trans = 0
        n_tot = 0
        n_tot_intra = 0
        for id_cont in range(1, len(self.dict_contigs) + 1):
            sub_sp_mat_tmp = self.sparse_mat_csr[coord_cont[id_cont], :]
            n_full_contact = sub_sp_mat_tmp.sum()
            sub_sp_mat_tmp_csc = sub_sp_mat_tmp.tocsc()
            sub_sp_mat_tmp_intra = sub_sp_mat_tmp_csc[:, coord_cont[id_cont]]
            shape_test = sub_sp_mat_tmp_intra.shape
            test = shape_test[0] == shape_test[1]
            if not test:
                logger.info("MIERDA!!!!")
            n_intra = sub_sp_mat_tmp_intra.sum()

            total_trans += n_full_contact
            total_trans -= n_intra
            # n_tot += (sub_sp_mat_tmp.shape[0] * sub_sp_mat_tmp.shape[1]) -
            # sub_sp_mat_tmp_intra.shape[0]*sub_sp_mat_tmp_intra.shape[1]
            n_tot_intra += shape_test[0] * (shape_test[0] - 1) / 2

        # for id_cont in xrange(1, len(self.dict_contigs)+1):
        #    full = self.im_init[coord_cont[id_cont], :]
        #    intra = self.im_init[np.ix_(coord_cont[id_cont],
        #    coord_cont[id_cont])]
        #    total_trans += full.sum()
        #    total_trans -= intra.sum()
        #    n_tot += (full.shape[0]*full.shape[1]) -
        #    intra.shape[0]*intra.shape[1]
        n_tot = (
            self.sparse_mat_csr.shape[0]
            * (self.sparse_mat_csr.shape[0] - 1)
            / 2
            - n_tot_intra
        )
        self.mean_value_trans = total_trans / np.float32(n_tot)
        if np.isnan(self.mean_value_trans):
            self.mean_value_trans = np.amin(self.sparse_mat_csr.data) / 10.0
        logger.debug(
            "computed mean trans value ... = {}".format(self.mean_value_trans)
        )

        self.distri_frag = np.array(self.distri_frag)

        # self.define_inter_chrom_coord()
        # self.init_data()

        self.n_contigs = len(self.dict_contigs)
1074625
@Override
	public void process( ImagePyramid<GrayF32> image1 ,
						 ImagePyramid<GrayF32> image2 ) {


		// Process the pyramid from low resolution to high resolution
		boolean first = true;
		for( int i = image1.getNumLayers()-1; i >= 0; i-- ) {
			GrayF32 layer1 = image1.getLayer(i);
			GrayF32 layer2 = image2.getLayer(i);

			// declare memory for this layer
			deriv2X.reshape(layer1.width,layer1.height);
			deriv2Y.reshape(layer1.width,layer1.height);
			warpDeriv2X.reshape(layer1.width,layer1.height);
			warpDeriv2Y.reshape(layer1.width,layer1.height);
			warpImage2.reshape(layer1.width,layer1.height);

			// compute the gradient for the second image
			gradient.process(layer2,deriv2X,deriv2Y);

			if( !first ) {
				// interpolate initial flow from previous layer
				interpolateFlowScale(layer1.width, layer1.height);
			} else {
				// for the very first layer there is no information on flow so set everything to 0
				first = false;

				initFlowX.reshape(layer1.width,layer1.height);
				initFlowY.reshape(layer1.width,layer1.height);
				flowX.reshape(layer1.width,layer1.height);
				flowY.reshape(layer1.width,layer1.height);

				ImageMiscOps.fill(flowX,0);
				ImageMiscOps.fill(flowY,0);
				ImageMiscOps.fill(initFlowX,0);
				ImageMiscOps.fill(initFlowY,0);
			}

			// compute flow for this layer
			processLayer(layer1,layer2,deriv2X,deriv2Y);
		}
	}
776266
public void unusual() {
		// Note that the first level does not have to be one
		pyramid = FactoryPyramid.discreteGaussian(new int[]{2,6},-1,2,true, ImageType.single(imageType));

		// Other kernels can also be used besides Gaussian
		Kernel1D kernel;
		if(GeneralizedImageOps.isFloatingPoint(imageType) ) {
			kernel = FactoryKernel.table1D_F32(2,true);
		} else {
			kernel = FactoryKernel.table1D_I32(2);
		}
	}
627833
def gauss_fltr_pyramid(dem, size=None, full=False, origmask=False):
    
    dem = malib.checkma(dem)
    levels = int(np.floor(np.log2(size)))
    #print levels
    dim = np.floor(np.array(dem.shape)/float(2**levels) + 1)*(2**levels)
    #print dem.shape
    #print dim
    #Can do something with np.pad here
    #np.pad(a_fp.filled(), 1, mode='constant', constant_values=(a_fp.fill_value,))
    dem2 = np.full(dim, dem.fill_value)
    offset = (dim - np.array(dem.shape))/2.0
    #print offset
    #dem2[0:dem.shape[0],0:dem.shape[1]] = dem.data 
    dem2[offset[0]:dem.shape[0]+offset[0],offset[1]:dem.shape[1]+offset[1]] = dem.data 
    dem2 = np.ma.masked_equal(dem2, dem.fill_value)
    #dem2 = dem
    for n in range(levels):
        print(dem2.shape)
        dim = (np.floor(np.array(dem2.shape)/2.0 + 1)*2).astype(int)
        #dem2 = gauss_fltr_astropy(dem2, size=5, origmask=origmask)
        #dem2 = gauss_fltr_astropy(dem2, size=5)
        dem2 = gauss_fltr_astropy(dem2, size=5)
        #Note: Should use zoom with same bilinear interpolation here for consistency
        #However, this doesn't respect nan
        #dem2 = zoom(dem2, 0.5, order=1, prefilter=False, cval=dem.fill_value)
        dem2 = dem2[::2,::2]
    if full:
        print("Resizing to original input dimensions")
        from scipy.ndimage import zoom
        for n in range(levels):
            print(dem2.shape)
            #Note: order 1 is bilinear
            dem2 = zoom(dem2, 2, order=1, prefilter=False, cval=dem.fill_value)
        #dem2 = zoom(dem2, 2**levels, order=1, prefilter=False, cval=dem2.fill_value)
        print(dem2.shape)
        #This was for power of 2 offset
        #offset = (2**levels)/2
        #print offset
        #dem2 = dem2[offset:dem.shape[0]+offset,offset:dem.shape[1]+offset]
        #Use original offset
        dem2 = dem2[offset[0]:dem.shape[0]+offset[0],offset[1]:dem.shape[1]+offset[1]]
        if origmask:
            print("Applying original mask")
            #Allow filling of interior holes, but use original outer edge
            maskfill = malib.maskfill(dem)
            #dem2 = np.ma.array(dem2, mask=np.ma.getmaskarray(dem))
            dem2 = np.ma.array(dem2, mask=maskfill, fill_value=dem.fill_value)
    return dem2
627023
def main(global_settings, **settings):
    """"""
    my_session_factory = SignedCookieSessionFactory('itsaseekreet')
    # Add session engine
    config = Configurator(
        settings=settings,
        session_factory=my_session_factory
    )
    # Add static and templates
    config.add_static_view(name='static', path='static')
    config.include('pyramid_jinja2')
    config.add_jinja2_search_path('templates')
    config.include('ps_crud')

    # Setting up pyramid_sacrud
    config.include('pyramid_sacrud', route_prefix='admin')
    settings = config.get_settings()
    settings['pyramid_sacrud.models'] = (
        ('Docker', [Image(), ]),
    )

    # Make app
    config.scan('views')
    return config.make_wsgi_app()
1111755
def mtf_image_transformer_base_cifar():
  """"""
  hparams = mtf_image_transformer_base()
  hparams.mesh_shape = "batch:8"
  hparams.layout = "batch:batch"
  hparams.learning_rate_decay_steps = 13600  # one epoch
  hparams.batch_size = 32
  hparams.num_heads = 4
  hparams.num_decoder_layers = 12
  hparams.block_length = 256
  hparams.hidden_size = 512
  hparams.d_ff = 2048
  hparams.learning_rate = 0.5
  hparams.layer_preprocess_sequence = "none"
  hparams.layer_postprocess_sequence = "dan"
  hparams.layer_prepostprocess_dropout = 0.3
  hparams.unconditional = True
  return hparams
913997
def display_hierarchy_helper(root, parent_id_to_children, depth):
  
  print '%s%s (%s)' % ('%s+--' % ('|'.join(['  '] * depth)),
                       root['name'], root['id'])

  # Recurse for each child of this root that has children.
  for child in parent_id_to_children.get(root['id'], []):
    display_hierarchy_helper(child, parent_id_to_children, depth + 1)
1116026
def create_single_structure_pse(structure_name, structure_content, residue_ids_of_interest, pymol_executable = 'pymol', settings = {}):
    ''' '''
    b = BatchBuilder(pymol_executable = pymol_executable)
    PSE_files = b.run(SingleStructureBuilder, [{structure_name : PDBContainer(structure_name, structure_content, residue_ids_of_interest)}], settings = settings)
    return PSE_files[0], b.PSE_scripts[0]
321905
def heightmap_set_value(hm: np.ndarray, x: int, y: int, value: float) -> None:
    
    if hm.flags["C_CONTIGUOUS"]:
        warnings.warn(
            "Assign to this heightmap with hm[i,j] = value\n"
            "consider using order='F'",
            DeprecationWarning,
            stacklevel=2,
        )
        hm[y, x] = value
    elif hm.flags["F_CONTIGUOUS"]:
        warnings.warn(
            "Assign to this heightmap with hm[x,y] = value",
            DeprecationWarning,
            stacklevel=2,
        )
        hm[x, y] = value
    else:
        raise ValueError("This array is not contiguous.")
694308
public static <O extends ImageGray<O>>
	void reshapeOutput( ImagePyramid<?> pyramid , O[] output ) {

		for( int i = 0; i < output.length; i++ ) {
			int w = pyramid.getWidth(i);
			int h = pyramid.getHeight(i);
			output[i].reshape(w, h);
		}
	}
35195
def cublasZhpr(handle, uplo, n, alpha, x, incx, AP):
    
    
    status = _libcublas.cublasZhpr_v2(handle,
                                      _CUBLAS_FILL_MODE[uplo], 
                                      n, ctypes.byref(ctypes.c_double(alpha)),
                                      int(x), incx, int(AP))
    cublasCheckStatus(status)
301337
def img2img_transformer2d_base():
  """"""
  hparams = image_transformer2d_base()
  # learning related flags
  hparams.layer_preprocess_sequence = "n"
  hparams.layer_postprocess_sequence = "da"
  # This version seems to benefit from a higher learning rate.
  hparams.learning_rate = 0.2
  hparams.layer_prepostprocess_dropout = 0.1
  hparams.learning_rate_warmup_steps = 12000
  hparams.filter_size = 2048
  hparams.num_encoder_layers = 4
  hparams.num_decoder_layers = 8
  hparams.bottom["inputs"] = modalities.image_channel_embeddings_bottom
  hparams.dec_attention_type = cia.AttentionType.LOCAL_2D
  hparams.block_raster_scan = True
  return hparams
274297
def transformer_base_v2():
  """"""
  hparams = transformer_base_v1()
  hparams.layer_preprocess_sequence = "n"
  hparams.layer_postprocess_sequence = "da"
  hparams.layer_prepostprocess_dropout = 0.1
  hparams.attention_dropout = 0.1
  hparams.relu_dropout = 0.1
  hparams.learning_rate_warmup_steps = 8000
  hparams.learning_rate = 0.2
  return hparams
369039
def mqp_lm1b_base():
  """"""
  hparams = mtf_transformer2.mtf_unitransformer_base()
  hparams.d_model = 1024
  hparams.max_length = 256
  hparams.batch_size = 256
  # Parameters for my_layer_stack()
  hparams.num_hidden_layers = 6
  hparams.d_ff = 8192
  hparams.d_kv = 128
  hparams.num_heads = 8
  hparams.learning_rate_decay_steps = 13600
  hparams.layout = "batch:batch;vocab:model;d_ff:model;heads:model"
  hparams.mesh_shape = "batch:32"
  return hparams
832823
def hicup_filtering_chart(self):
        

        # Specify the order of the different possible categories
        keys = OrderedDict()
        keys['Valid_Pairs'] =            { 'color': '#2f7ed8', 'name': 'Valid Pairs' }
        keys['Same_Fragment_Internal'] = { 'color': '#0d233a', 'name': 'Same Fragment - Internal' }
        keys['Same_Circularised'] =      { 'color': '#910000', 'name': 'Same Fragment - Circularised' }
        keys['Same_Dangling_Ends'] =     { 'color': '#8bbc21', 'name': 'Same Fragment - Dangling Ends' }
        keys['Re_Ligation'] =            { 'color': '#1aadce', 'name': 'Re-ligation' }
        keys['Contiguous_Sequence'] =    { 'color': '#f28f43', 'name': 'Contiguous Sequence' }
        keys['Wrong_Size'] =             { 'color': '#492970', 'name': 'Wrong Size' }

        # Config for the plot
        config = {
            'id': 'hicup_filtering_plot',
            'title': 'HiCUP: Filtering Statistics',
            'ylab': '# Read Pairs',
            'cpswitch_counts_label': 'Number of Read Pairs',
            'cpswitch_c_active': False
        }

        return bargraph.plot(self.hicup_data, keys, config)
333530
def _adapt_params(self, stepsize, stepsize_bar, h_bar, mu, index_i, alpha, n_alpha=1):
        
        gamma = 0.05  # free parameter that controls the amount of shrinkage towards mu
        t0 = 10.0  # free parameter that stabilizes the initial iterations of the algorithm
        kappa = 0.75
        # See equation (6) section 3.2.1 for details

        estimate = 1.0 / (index_i + t0)
        h_bar = (1 - estimate) * h_bar + estimate * (self.delta - alpha / n_alpha)

        stepsize = np.exp(mu - sqrt(index_i) / gamma * h_bar)
        i_kappa = index_i ** (-kappa)
        stepsize_bar = np.exp(i_kappa * np.log(stepsize) + (1 - i_kappa) * np.log(stepsize_bar))

        return stepsize, stepsize_bar, h_bar
1315693
def write_hier(self, GO_id, out=sys.stdout,
                       len_dash=1, max_depth=None, num_child=None, short_prt=False,
                       include_only=None, go_marks=None):
        """"""
        gos_printed = set()
        self[GO_id].write_hier_rec(gos_printed, out, len_dash, max_depth, num_child,
            short_prt, include_only, go_marks)