From 61ea249f73ce46492ffc06d8eab8246373abf25a Mon Sep 17 00:00:00 2001 From: votti Date: Tue, 4 Feb 2020 17:44:27 +0100 Subject: [PATCH 1/3] imc2tiff and ome2micat work now also with hidden files Before os.listdir was used to find files, which would also list hidden files. Now we are using: glob.glob(os.path.join(path, '*')) which should ignore hidden files (https://stackoverflow.com/a/7099342). --- imctools/scripts/imc2tiff.py | 3 ++- imctools/scripts/ome2micat.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/imctools/scripts/imc2tiff.py b/imctools/scripts/imc2tiff.py index 84cad8e..d44ce54 100755 --- a/imctools/scripts/imc2tiff.py +++ b/imctools/scripts/imc2tiff.py @@ -3,6 +3,7 @@ from imctools.io import txtparser import argparse import os +import glob from imctools.external import temporarydirectory import zipfile @@ -93,7 +94,7 @@ def convert_imcfolders2tiff(folders, output_folder, common_filepart=None, common_filepart = '' for fol in folders: - for fn in os.listdir(fol): + for fn in glob.glob(os.path.join(fol, '*')): if (common_filepart in fn) & (fn.endswith(IMC_FILENDINGS) | fn.endswith(ZIP_FILENDING)): txtname = os.path.join(fol, fn) diff --git a/imctools/scripts/ome2micat.py b/imctools/scripts/ome2micat.py index f8d40e1..dd77ce5 100644 --- a/imctools/scripts/ome2micat.py +++ b/imctools/scripts/ome2micat.py @@ -2,6 +2,7 @@ from imctools.io import ometiffparser import argparse import os +import glob import shutil import re @@ -57,9 +58,9 @@ def omefolder2micatfolder(fol_ome, outfolder, fol_masks=None, mask_suffix=None, if mask_suffix is None: mask_suffix = '_mask.tiff' - ome_files = [fn for fn in os.listdir(fol_ome) if fn.endswith('.ome.tiff')] + ome_files = [fn for fn in glob.glob(os.path.join(fol_ome, '*')) if fn.endswith('.ome.tiff')] if fol_masks is not None: - fn_masks = [fn for fn in os.listdir(fol_masks) if fn.endswith(mask_suffix)] + fn_masks = [fn for fn in glob.glob(os.path.join(fol_masks, '*')) if fn.endswith(mask_suffix)] else: fn_masks = [] From c3fe9aa6c1d84d05e6c0dd1b1d6e1ff71b9cbb6b Mon Sep 17 00:00:00 2001 From: votti Date: Tue, 4 Feb 2020 20:27:49 +0100 Subject: [PATCH 2/3] Fixed bug in glob implementation In contrast to os.path.listdir, glob.glob(*) returns the full path, not just the basename. Adapted the scripts to account for that. --- imctools/scripts/imc2tiff.py | 5 ++--- imctools/scripts/ome2micat.py | 9 +++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/imctools/scripts/imc2tiff.py b/imctools/scripts/imc2tiff.py index d44ce54..ca1c58c 100755 --- a/imctools/scripts/imc2tiff.py +++ b/imctools/scripts/imc2tiff.py @@ -95,16 +95,15 @@ def convert_imcfolders2tiff(folders, output_folder, common_filepart=None, for fol in folders: for fn in glob.glob(os.path.join(fol, '*')): - if (common_filepart in fn) & (fn.endswith(IMC_FILENDINGS) | + if (common_filepart in os.path.basename(fn)) & (fn.endswith(IMC_FILENDINGS) | fn.endswith(ZIP_FILENDING)): - txtname = os.path.join(fol, fn) + txtname = fn try: save_imc_to_tiff(txtname, outpath=output_folder, **kwargs) except: failed_images.append(txtname) - if len(failed_images) > 0: print('Failed images:\n') print(failed_images) diff --git a/imctools/scripts/ome2micat.py b/imctools/scripts/ome2micat.py index dd77ce5..8ba08f9 100644 --- a/imctools/scripts/ome2micat.py +++ b/imctools/scripts/ome2micat.py @@ -39,7 +39,7 @@ def ome2micatfolder(path_ome, basefolder, path_mask=None, dtype=None): outfolder = os.path.join(basefolder, fn) if not(os.path.exists(outfolder)): os.makedirs(outfolder) - ome2singletiff(path_ome, outfolder,basename='', dtype=dtype) + ome2singletiff(path_ome, outfolder, basename='', dtype=dtype) if path_mask is not None: fn_mask_base = os.path.split(path_mask)[1] fn_mask_new = os.path.join(outfolder, fn_mask_base) @@ -58,14 +58,15 @@ def omefolder2micatfolder(fol_ome, outfolder, fol_masks=None, mask_suffix=None, if mask_suffix is None: mask_suffix = '_mask.tiff' - ome_files = [fn for fn in glob.glob(os.path.join(fol_ome, '*')) if fn.endswith('.ome.tiff')] + ome_files = [os.path.basename(fn) for fn in glob.glob(os.path.join(fol_ome, '*')) if fn.endswith('.ome.tiff')] if fol_masks is not None: - fn_masks = [fn for fn in glob.glob(os.path.join(fol_masks, '*')) if fn.endswith(mask_suffix)] + fn_masks = [os.path.basename(fn) for fn in glob.glob(os.path.join(fol_masks, '*')) if fn.endswith(mask_suffix)] else: fn_masks = [] for fn_ome in ome_files: - basename_ome = fn_ome.rstrip('.ome.tiff') + len_suffix = len('.ome.tiff') + basename_ome = fn_ome[:-len_suffix] cur_mask = [fn for fn in fn_masks if fn.startswith(basename_ome)] if len(cur_mask) > 0: path_mask = os.path.join(fol_masks, cur_mask[0]) From 0fe128d54a56b98a7ddacdcf0c5b1b9073f1ae16 Mon Sep 17 00:00:00 2001 From: Anton Rau Date: Wed, 5 Feb 2020 09:41:14 +0100 Subject: [PATCH 3/3] Version bump. --- docs/source/conf.py | 6 +++--- pyproject.toml | 4 ++-- setup.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 9cae8c4..94d8182 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -20,13 +20,13 @@ # -- Project information ----------------------------------------------------- project = 'imctools' -copyright = '2019, Vito Zanotelli' +copyright = '2020, Vito Zanotelli' author = 'Vito Zanotelli' # The short X.Y version -version = '1.0.4' +version = '1.0.6' # The full version, including alpha/beta/rc tags -release = '1.0.4' +release = '1.0.6' # -- General configuration --------------------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index 400803f..0b9479d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [build-system] -requires = ["poetry>=0.12.17"] +requires = ["poetry>=1.0.3"] build-backend = "poetry.masonry.api" [tool.poetry] name = "imctools" -version = "1.0.5" +version = "1.0.6" description = "Tools to handle IMC data" license = "LICENSE" authors = [ diff --git a/setup.py b/setup.py index 931c40a..952e36a 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name='imctools', - version='1.0.5', + version='1.0.6', description='Tools to handle IMC data', long_description=readme, author='Vito Zanotelli',