Skip to content

Instantly share code, notes, and snippets.

For large files, submit multiple parallel jobs of omero import

P1. find all the files to be uploaded, write the file paths to a csv (mosaics.csv), and review the list. For example, type the following in the terminal to save matching files to mosaics.csv

find /n/scratch3/users/y/yc296/216-OMS_2022MAR-2022MAR/mcmicro -type f -wholename */registration/*.ome.tif | sort >> mosaics.csv
find /n/scratch3/users/y/yc296/216-OMS_2022MAR-2022MAR/mcmicro -type f -wholename */qc/*.ome.tif | sort >> mosaics.csv

P2. follow step 1 and 3 here

javascript:(function(){
let infotab = document.getElementById('infoTab').children[0].children[2];
let channels = infotab.children[0].children[1].children[0].lastElementChild.textContent.trim().split(', ');
let channelsliders = document.getElementById('channel_sliders').children[0];
for(i=0;i<channels.length;i++) {
let p = document.createTextNode(channels[i]);
let br = document.createElement('br');
channelsliders.children[i].insertBefore(br,channelsliders.children[i].firstChild);
channelsliders.children[i].insertBefore(p,channelsliders.children[i].firstChild);
}
@Yu-AnChen
Yu-AnChen / export-cycif-channel-metadata.js
Last active December 15, 2021 00:32
Export CyCIF Experiment Tracker plans in HTAN metadata format
var project_number = 111;
var exp_number = 1;
var exp_name = '168-tumor';
var href = `https://reagenttracker.hms.harvard.edu/api/v0/imaging_cycle/${project_number}/${exp_number}`;
var csv_name = `${exp_name}-${project_number}-${exp_number}`;
var use_actual_cycles = false;
Promise
.all([parse_vocab(), get_exp(href)])
@Yu-AnChen
Yu-AnChen / read_omero_image_level_region.py
Created October 12, 2021 00:46
Fetch pixel data of an image at specific resolution (level) from omero server
# ref https://forum.image.sc/t/omero-py-how-to-get-tiles-at-different-zoom-level-pyramidal-image/
import numpy as np
from omero.gateway import BlitzGateway
from omero.model import enums as omero_enums
import omero
def connect_hms_omero(session_id):
SESSION_ID = session_id
HOST = 'omero-app.hms.harvard.edu'
import argparse
import json
import sys
from omero.gateway import BlitzGateway
from omero.cli import cli_login
from omero.model import StatsInfoI
from omero.rtypes import rdouble
@Yu-AnChen
Yu-AnChen / tifffile_tiled_pyramid_ome_tif.py
Created June 8, 2021 22:35
Write pyramidal ome-tiff using tifffile with channel names and crop positions
import tifffile
import numpy as np
def per_channel_per_tile(img, tile=(1024, 1024)):
num_channels, num_rows, num_columns = img.shape
h, w = tile
for c in range(num_channels):
for y in range(0, num_rows, h):
for x in range(0, num_columns, w):
yield img[c, y:y+h, x:x+w]
# https://forum.image.sc/t/numpy-to-imageplus-imageplus-to-numpy-conversion-with-pyimagej/29399/1
import imagej
import numpy as np
# initialize imagej
ij = imagej.init()
import jnius
# get Java class representations
BackgroundSubtracter = jnius.autoclass(
@Yu-AnChen
Yu-AnChen / mask_to_path.py
Last active April 17, 2021 00:20
Approximate objects in a binary image with polygon outline using opencv
import cv2
import matplotlib.patches as mpatches
import copy
import numpy as np
import matplotlib.pyplot as plt
def binary_to_patches(binary_img):
assert np.unique(binary_img).shape[0] == 2, \
'Input image must be a binary image'
contours, _ = cv2.findContours(
@Yu-AnChen
Yu-AnChen / synapse_upload_folder.py
Last active April 25, 2022 06:55
Upload recursively to sage synapse using synapse python client
import synapseclient
import pathlib
from synapseclient import Folder, File
exclude_folders = (
'.nextflow',
'probability-maps',
'qc',
'registration',
var imgIds = [
1203716, 1203756, 1203720,
];
const omeroUrls = {
hms: 'https://omero.hms.harvard.edu',
idp: 'https://idp.tissue-atlas.org'
};
// choose omero instance between the HMS and the IDP OMERO
const whichOmero = 'hms';