Пример #1
0
def make_individul_plots(ippath, oppath, fileinfo, columns, x_max_factor=1):
    #print("1:" + oppath)
    # extract file list
    imglist = [x for x in os.listdir(ippath) if not x.startswith('.')]

    for key, value in columns.items():
        # get range
        data_range = FindRange(ippath, variable=key)

        # make histogram for individual dataset
        for img in imglist:
            #print("2:" + oppath)
            df_segments_s = pd.read_csv(
                os.path.join(ippath, img, 'segments_s.csv'))

            # histogram for average length
            plt.figure(figsize=(5, 5))

            ax = IndividualHisto(df_segments_s,
                                 column=key,
                                 bin_range=data_range,
                                 x_max_factor=x_max_factor)
            ax.set_xlabel(value['x_label'])
            ax.set_ylabel('Frequency (%)')

            DirCheck(os.path.join(oppath, 'histo', value['file_label']))
            opfilename = os.path.join(oppath, 'histo', value['file_label'],
                                      img + '.png')
            plt.savefig(opfilename)
            plt.close()
    return
Пример #2
0
def make_individul_plots_all(ippath,
                             oppath,
                             fileinfo,
                             filestat,
                             columns,
                             x_max_factor=1):
    #print("1:" + oppath)
    # extract file list
    labels, uniques = pd.factorize(filestat['Group'])

    for i in uniques:
        # level: Group
        tmp_df = filestat[filestat['Group'] == i]
        data_merge = []
        filenames = tmp_df['Names']
        for key, value in columns.items():
            # level: thickness, length
            # get range
            data_range = FindRange(ippath, variable=key)

            plt.figure(figsize=(5, 5))

            for idx, filename in enumerate(filenames):

                df_segments_s = pd.read_csv(
                    os.path.join(ippath, filename, 'segments_s.csv'))

                # IndividualHisto(df_segments_s, column = key, bin_range = data_range, x_max_factor = x_max_factor)

                binsize = 100
                bins = np.linspace(data_range[0], data_range[1] * x_max_factor,
                                   binsize)
                data = df_segments_s[key]

                ax = plt.subplot(len(filenames), 1, idx + 1)
                ax.hist(data,
                        bins=bins,
                        weights=(np.zeros_like(data) + 1. / data.size) * 100)

            ax.set_xlabel(value['x_label'])
            ax.set_ylabel('Frequency (%)')

            DirCheck(os.path.join(oppath, 'histo_summary'))
            opfilename = os.path.join(
                oppath, 'histo_summary',
                'comp_' + key + '_' + str(i) + "_" + str(i) + '.png')
            plt.savefig(opfilename)
            plt.close()
    return
Пример #3
0
def convert_xml_csv(ippath, oppath):
    filelist, fileabslist = ListFiles(ippath, extension='.xml')

    for idx, f in enumerate(filelist):
        filename = f.replace('.xml', '')
        ip = os.path.join(ippath, f)
        op = os.path.join(oppath, filename)

        print(ip)
        print(op)

        # create path
        if filename not in os.listdir(oppath):
            DirCheck(op)

            # convert *.xml to *.csv
            csv_all = MSXmlReader(ip)

            # save each spreadsheet into individual *.csv file
            for key, value in csv_all.items():
                oppath_tmp = os.path.join(op, key + '.csv')
                value.to_csv(oppath_tmp, index=False)
nchannel = int(sys.argv[5])
crop_region = int(sys.argv[6])
op_dir = str(sys.argv[7])

ip_path = os.path.join(path, analysis_dir, analysis_subdir, csvdata_dir)

# create output path
dir_for_check = []
# op_dir = 'csvdata_crop'
op_path = os.path.join(path, analysis_dir, analysis_subdir, op_dir)
dir_for_check.append(op_path)
for i in range(nchannel):
	dir_tmp = os.path.join(op_path, str(i+1))
	dir_for_check.append(dir_tmp)
print(dir_for_check)
DirCheck(dir_for_check)


# %%
# load crop data
dir_par = 'par'
path_cropdata = os.path.join(path, analysis_dir, dir_par, 'cropsize.csv')
df_cropdata = pd.read_csv(path_cropdata, header = 0)
# display(df_cropdata)

# %%
# load image stat
path_imgstat = os.path.join(path, analysis_dir, 'preprocessing', 'imginfo', 'imgstat.csv')
df_imgstat = pd.read_csv(path_imgstat, header = 0)
# display(df_imgstat)
Пример #5
0
                oppath_tmp = os.path.join(op, key + '.csv')
                value.to_csv(oppath_tmp, index=False)


#%% [markdown]
#  ### Execution
#  To run the code, please change `path` to the directory hosts the raw data.

#%%
path = 'data'
ipdir = 'raw'
opdir = 'csv'
ippath = os.path.join(path, ipdir)
oppath = os.path.join(path, opdir)
# make dir
DirCheck(oppath)

# convert files in batch
convert_xml_csv(ippath, oppath)

#%% [markdown]
#   ## Part 2:
#   Calulating the length and average thickness of each segment.
#   * Inputs: nodes.csv, points.csv, segments.csv
#   * Outputs: segments_s.csv
#
#   `SegStats` extracts euclidean coordinates and thickness of each point, then calculate the total length and average thickness.
#%% [markdown]
#  ### Functions

#%%
Пример #6
0
nchannel = int(sys.argv[7])
crop_region = int(sys.argv[8])
pad_pixel = int(sys.argv[9])
pixelsize = float(sys.argv[10])
nnd_plot_dir = str(sys.argv[11])

# input path
nnd_data_path = os.path.join(path, analysis_dir, st_dir, nnd_dir, nnd_data_dist_dir)
print(nnd_data_path)

# output folder
nnd_plot_path = os.path.join(path, analysis_dir, st_dir, nnd_dir, nnd_plot_dir)

dir_check = []
dir_check.append(nnd_plot_path)
DirCheck(dir_check)

# %%
# create grouped filename and file path 
group = {
    'wildtype': 'w',
    'knockout': 'k'
}
ippath = {
    'nnddata':{
        'dir': nnd_data_path,
        'ext': '.csv',
    }
}

oppath = {
Пример #7
0
# functions ============================================


# ========================================================

#%%
path = '/Volumes/LaCie_DataStorage/Asensio_Lab'
raw_dir = 'alignment_opencv_01'
sub_dir = 'KO_2_reordered_rename'
ippath = os.path.join(path, raw_dir, sub_dir)
print(ippath)

op_dir = 'alignment_opencv_01_std'
oppath = os.path.join(path, op_dir, sub_dir)

DirCheck(oppath)

#%%
filename, filepath = ListFiles(ippath, '.tif')
print(filepath)

#%%
inten_min = 0.0
inten_max = 0.0
for i in range(len(filename)):
    ipfilepath = os.path.join(ippath, filename[i] + '.tif')
    opfilepath = os.path.join(oppath, filename[i] + '.tif')
    
    ROI = [4352, 3088, 4096, 4096]
    im = Image.open(ipfilepath)
    im_std = Standardize(im, ROI)
Пример #8
0
from core.img import openimage, AlignImages, AlignImagesStack, AlignImages_Affine, AlignImagesStack_Affine


# functions ============================================


# ========================================================

#%%

path = '/Volumes/LaCie_DataStorage/Asensio_Lab'
raw_dir = 'output'
sub_dir = 'KO_2_reordered_rename'
ippath = os.path.join(path, raw_dir, sub_dir)
print(ippath)

dircheck = []
op_dir = 'alignment_opencv_01'
opmatch_dir = 'alignment_match_opencv_01'
oppath = os.path.join(path, op_dir, sub_dir)
oppath_match = os.path.join(path, opmatch_dir, sub_dir)
dircheck.append(oppath)
dircheck.append(oppath_match)

DirCheck(dircheck)

#%%
factor = 1/16
center = 50
AlignImagesStack_Affine(ippath, oppath, oppath_match, factor, centerimg = center, ext = '.tif')
path = '/Volumes/LaCie_DataStorage/Asensio_Lab'
project_dir = 'TEM_stitching'
ip_dir = 'data'
op_dir = 'data_renamed'
ippath = os.path.join(path, project_dir, ip_dir)
print(ippath)
oppath = os.path.join(path, project_dir, op_dir)
print(oppath)

#%%
foldernames = ListFolders(ippath)

dirchecklist = []
for i in foldernames:
    dirchecklist.append(os.path.join(oppath, i))
DirCheck(dirchecklist)

#%% 
par_path = os.path.join(path, project_dir, 'par', 'tile_dimension.csv')
par_data= pd.read_csv(par_path)
display(par_data)

#%%
filelist, fileabslist = ListFiles(ippath, extension = '.mrc')
# print(filelist)
org_filename = par_data['cellname'] 

class imgfile:
    def __init__(self, filename, filepath, foldername, folderpath):
            self.filename = filename
            self.filepath = filepath
Пример #10
0
from shutil import copyfile
from core.fileop import DirCheck, ListFiles, ListFolders, SplitAll, SortByFolder
from core.imgstitching import IdxConverter

#%%
path = '/Volumes/LaCie_DataStorage/Asensio_Lab'
wd_dir = 'TEM_stitching'
ip_dir = 'output'
ippath = os.path.join(path, wd_dir, ip_dir)
print(ippath)

dircheck = []
op_dir = 'output_reordered'
oppath = os.path.join(path, wd_dir, op_dir)
dircheck.append(oppath)
DirCheck(dircheck)

#%%
# load par
par_dir = 'par'
par_path = os.path.join(path, wd_dir, par_dir, 'tile_dimension.csv')
DimData = pd.read_csv(par_path)
display(DimData)
DimData['filename'] = DimData['filename'].astype(str)
DimData.dtypes
#%%
for i in ListFolders(ippath):
    i = 'rescue'
    ippath_tmp = os.path.join(ippath, i)
    oppath_tmp = os.path.join(oppath, i)
    DirCheck(oppath_tmp)