args = parser.parse_args()
print('args:')
print(args)
ref_csv = args.ref_csv
array_no = int(args.array_no)
output_dir = args.output_dir
# read .czi file path from csv reference table
ref_df = pd.read_csv(ref_csv)
czi_path = ref_df['files'].iloc[array_no]
bg_czi_path = ref_df['controls'].iloc[array_no]
print('czi path: ' + czi_path)
print('control czi path: ' + bg_czi_path)
# load .czi file into MultiFinder instance
finder = find_cells.MultiFinder(
    czi_path,
    bg_filename=bg_czi_path,
    log_path=output_dir + '/log',
    oof_svm=
    '/n/denic_lab/Users/nweir/python_packages/csth-imaging/trained_svm.pkl')
print('MultiFinder created.')
# initialize a CellSplitter from finder
splitter = segment_cells.CellSplitter(finder)
print('CellSplitter instance created.')
splitter.segment_nuclei(verbose=True)  # segment nuclei
print('Nuclei segmented.')
splitter.segment_cells(488, verbose=True)  # segment cells using the 488 wl
print('Cells segmented.')
# initialize a Foci instance from splitter
foci_obj = foci.Foci(splitter, verbose=True)
print('Foci instance created.')
foci_obj.segment(verbose=True,
                 thresholds={
Exemplo n.º 2
0
parser.add_argument('-o', '--output_dir', required=True,
                    help='dir for CSV-formatted output')
args = parser.parse_args()
print('args:')
print(args)
ref_csv = args.ref_csv
array_no = int(args.array_no)
output_dir = args.output_dir
# read .czi file path from csv reference table
ref_df = pd.read_csv(ref_csv)
im_path = ref_df['files'].iloc[array_no]
bg_path = ref_df['controls'].iloc[array_no]
print('im path: ' + im_path)
print('control path: ' + bg_path)
# load .czi file into MultiFinder instance
finder = find_cells.MultiFinder(
    im_path, bg_filename=bg_path, log_path=output_dir + '/log', foc_channel=640)
print('MultiFinder created.')
# initialize a CellSplitter from finder
splitter = segment_cells.CellSplitter(finder, lo_p=True, threshold=300)
print('CellSplitter instance created.')
splitter.segment_nuclei(verbose=True)  # segment nuclei
print('Nuclei segmented.')
splitter.segment_cells(488, verbose=True)  # segment cells using the 488 wl
print('Cells segmented.')
# initialize a Foci instance from splitter
foci_obj = foci.Foci(splitter, verbose=True)
print('Foci instance created.')
foci_obj.segment(seg_channels=(640,), min_cutoff={640: 5}, rm_nuclear=False,
                 thresholds={640: (4000, 2000)})
print('Foci segmented.')
cell_im = foci_obj.segmented_cells[0]
Exemplo n.º 3
0
                    required=True,
                    help='path to reference csv file')
parser.add_argument('-a',
                    '--array_no',
                    required=True,
                    help='SLURM job array ID')
args = parser.parse_args()
print('args:')
print(args)
ref_csv = args.ref_csv
array_no = int(args.array_no)
# read .czi file path from csv reference table
ref_df = pd.read_csv(ref_csv)
czi_path = ref_df['files'].iloc[array_no]
print('czi path: ' + czi_path)
finder = find_cells.MultiFinder(czi_path)
nuclei_ims = finder.get_channel_arrays(405, bg=False)
print('nuclei_ims shape:')
print(nuclei_ims.shape)
del finder  # save memory
cm = plt.cm.get_cmap('RdYlBu_r')  # colormap for plotting
for i in range(0, nuclei_ims.shape[0]):
    c_im = nuclei_ims[i, :, :, :].astype('uint16')
    kmeans_subset = np.random.choice(c_im.flatten(), 1000000)
    cluster_out = KMeans(n_clusters=2, algorithm='full',
                         n_init=50).fit(kmeans_subset.reshape(-1, 1))
    n, bins = np.histogram(kmeans_subset, bins=100)
    colors_1 = np.zeros(shape=bins.shape)
    colors_1[bins > np.amin(
        kmeans_subset.reshape(-1, 1)[cluster_out.labels_ == 1])] = 1
    colors_1 = colors_1[:-1]
Exemplo n.º 4
0
                    help='path for CSV-formatted output')
args = parser.parse_args()
print('args:')
print(args)
ref_csv = args.ref_csv
array_no = int(args.array_no)
output_path = args.output_path
# read .czi file path from csv reference table
ref_df = pd.read_csv(ref_csv)
czi_paths = ref_df['files'].tolist()
# load .czi file into MultiFinder instance
output_df = pd.DataFrame(columns=['filename', 'im_number', 'flagged_z'])
for czi in czi_paths:
    finder = find_cells.MultiFinder(
        czi,
        oof_svm=
        '/n/denic_lab/Users/nweir/python_packages/csth-imaging/trained_svm.pkl'
    )
    im_for_clf = finder.get_channel_arrays(finder.foc_channel, bg=False)
    print('unlabeling out of focus slices...')
    with open(finder.oof_svm, 'rb') as r:
        clf = pickle.load(r)
    shrt_fname = finder.filenames[0].split('/')[-1][:-4]
    for im in range(0, im_for_clf.shape[0]):
        if finder.log_path is not None:
            focus_slices = finder.get_blur_slices(im=im_for_clf[im, :, :, :],
                                                  clf=clf,
                                                  slc_no=im,
                                                  log_path=finder.log_path +
                                                  '/' + shrt_fname)
        else: