diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a45fea..87fbd6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.1.3] - 2021-01-21 +- Option to force usage of TXT files in `mcdfolder_to_imcfolder` when dealing with partially corrupted MCD files + ## [2.1.2] - 2021-01-21 - Prevent crash on corrupted MCD acquisitions in order to keep valid ones diff --git a/README.md b/README.md index ed8ebf8..3df4167 100755 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Version 1.x documentation (deprecated): https://imctools.readthedocs.io Preferable way to install `imctools` is via official PyPI registry. Please define package version explicitly in order to avoid incompatibilities between v1.x and v2.x versions: ``` -pip install imctools==2.1.2 +pip install imctools==2.1.3 ``` In old IMC segmentation pipelines versions 1.x should be used! ``` diff --git a/docs/cli.html b/docs/cli.html index 257065d..cd50247 100644 --- a/docs/cli.html +++ b/docs/cli.html @@ -67,7 +67,7 @@

Module imctools.cli

def _add_mcdfolder2imcfolder_parser(subparsers: argparse._SubParsersAction): def func(args): - mcdfolder_to_imcfolder(args.input, args.output_folder, args.zip) + mcdfolder_to_imcfolder(args.input, args.output_folder, args.zip, args.parse_txt) parser = subparsers.add_parser( "mcdfolder-to-imcfolder", @@ -77,6 +77,7 @@

Module imctools.cli

parser.add_argument("input", help="Path to the folder/zip archive containing the IMC raw data.") parser.add_argument("output_folder", help="Path to the output folder.") parser.add_argument("--zip", action="store_true", help="Whether to create an output as .zip file.") + parser.add_argument("--parse_txt", action="store_true", help="Always use TXT files if present to get acquisition image data.") parser.set_defaults(func=func) diff --git a/docs/converters/mcdfolder2imcfolder.html b/docs/converters/mcdfolder2imcfolder.html index d85b63f..8e0b56e 100644 --- a/docs/converters/mcdfolder2imcfolder.html +++ b/docs/converters/mcdfolder2imcfolder.html @@ -41,7 +41,7 @@

Module imctools.converters.mcdfolder2imcfolderModule imctools.converters.mcdfolder2imcfolderModule imctools.converters.mcdfolder2imcfolderModule imctools.converters.mcdfolder2imcfolder @@ -118,7 +123,7 @@

Module imctools.converters.mcdfolder2imcfolderFunctions

-def mcdfolder_to_imcfolder(input: Union[str, pathlib.Path], output_folder: Union[str, pathlib.Path], create_zip: bool = False) +def mcdfolder_to_imcfolder(input: Union[str, pathlib.Path], output_folder: Union[str, pathlib.Path], create_zip: bool = False, parse_txt: bool = False)

Converts folder (or zipped folder) containing raw acquisition data (mcd and txt files) to IMC folder containing standardized files.

@@ -131,12 +136,14 @@

Parameters

Path to the output folder.
create_zip
Whether to create an output as .zip file.
+
parse_txt
+
Always use TXT files if present to get acquisition image data.
Expand source code -
def mcdfolder_to_imcfolder(input: Union[str, Path], output_folder: Union[str, Path], create_zip: bool = False):
+
def mcdfolder_to_imcfolder(input: Union[str, Path], output_folder: Union[str, Path], create_zip: bool = False, parse_txt: bool = False):
     """Converts folder (or zipped folder) containing raw acquisition data (mcd and txt files) to IMC folder containing standardized files.
 
     Parameters
@@ -147,6 +154,8 @@ 

Parameters

Path to the output folder. create_zip Whether to create an output as .zip file. + parse_txt + Always use TXT files if present to get acquisition image data. """ if isinstance(input, str): input = Path(input) @@ -178,7 +187,7 @@

Parameters

txt_files = glob.glob(str(input_folder / f"*[0-9]{TXT_FILE_EXTENSION}")) txt_acquisitions_map = {TxtParser.extract_acquisition_id(f): f for f in txt_files} - imc_writer = ImcWriter(output_folder, mcd_parser, txt_acquisitions_map) + imc_writer = ImcWriter(output_folder, mcd_parser, txt_acquisitions_map, parse_txt) imc_writer.write_imc_folder(create_zip=create_zip) finally: if mcd_parser is not None: diff --git a/docs/index.html b/docs/index.html index a3ab055..b8eb221 100644 --- a/docs/index.html +++ b/docs/index.html @@ -49,7 +49,7 @@

Prerequisites

Installation

Preferable way to install imctools is via official PyPI registry. Please define package version explicitly in order to avoid incompatibilities between v1.x and v2.x versions:

-
pip install imctools==2.1.2
+
pip install imctools==2.1.3
 

In old IMC segmentation pipelines versions 1.x should be used!

pip install imctools==1.0.8
@@ -140,7 +140,7 @@ 

Usage of previous version 1.x

__author__ = """Vito Zanotelli, Anton Rau""" __email__ = "vito.zanotelli@uzh.ch, anton.rau@uzh.ch" -__version__ = "2.1.1"
+__version__ = "2.1.3"
diff --git a/docs/io/imc/imcwriter.html b/docs/io/imc/imcwriter.html index 8006fc6..403c073 100644 --- a/docs/io/imc/imcwriter.html +++ b/docs/io/imc/imcwriter.html @@ -50,6 +50,7 @@

Module imctools.io.imc.imcwriter

root_output_folder: Union[str, Path], mcd_parser: McdParser, txt_acquisitions_map: Dict[int, Union[str, Path]] = None, + parse_txt: bool = False ): """ Initializes an ImcFolderWriter that can be used to write out an imcfolder and compress it to zip. @@ -59,6 +60,7 @@

Module imctools.io.imc.imcwriter

self.root_output_folder = root_output_folder self.mcd_parser = mcd_parser self.txt_acquisitions_map = txt_acquisitions_map + self.parse_txt = parse_txt @property def folder_name(self): @@ -84,7 +86,7 @@

Module imctools.io.imc.imcwriter

# Save acquisition images in OME-TIFF format for acquisition in session.acquisitions.values(): acquisition_data = self.mcd_parser.get_acquisition_data(acquisition.id) - if not acquisition_data.is_valid: + if self.parse_txt or not acquisition_data.is_valid: if self.txt_acquisitions_map is not None and acquisition.id in self.txt_acquisitions_map: logger.warning(f"Using TXT file for acquisition: {acquisition.id}") try: @@ -161,7 +163,7 @@

Classes

class ImcWriter -(root_output_folder: Union[str, pathlib.Path], mcd_parser: McdParser, txt_acquisitions_map: Dict[int, Union[str, pathlib.Path]] = None) +(root_output_folder: Union[str, pathlib.Path], mcd_parser: McdParser, txt_acquisitions_map: Dict[int, Union[str, pathlib.Path]] = None, parse_txt: bool = False)

Write IMC session data to IMC folder structure.

@@ -178,6 +180,7 @@

Classes

root_output_folder: Union[str, Path], mcd_parser: McdParser, txt_acquisitions_map: Dict[int, Union[str, Path]] = None, + parse_txt: bool = False ): """ Initializes an ImcFolderWriter that can be used to write out an imcfolder and compress it to zip. @@ -187,6 +190,7 @@

Classes

self.root_output_folder = root_output_folder self.mcd_parser = mcd_parser self.txt_acquisitions_map = txt_acquisitions_map + self.parse_txt = parse_txt @property def folder_name(self): @@ -212,7 +216,7 @@

Classes

# Save acquisition images in OME-TIFF format for acquisition in session.acquisitions.values(): acquisition_data = self.mcd_parser.get_acquisition_data(acquisition.id) - if not acquisition_data.is_valid: + if self.parse_txt or not acquisition_data.is_valid: if self.txt_acquisitions_map is not None and acquisition.id in self.txt_acquisitions_map: logger.warning(f"Using TXT file for acquisition: {acquisition.id}") try: @@ -309,7 +313,7 @@

Methods

# Save acquisition images in OME-TIFF format for acquisition in session.acquisitions.values(): acquisition_data = self.mcd_parser.get_acquisition_data(acquisition.id) - if not acquisition_data.is_valid: + if self.parse_txt or not acquisition_data.is_valid: if self.txt_acquisitions_map is not None and acquisition.id in self.txt_acquisitions_map: logger.warning(f"Using TXT file for acquisition: {acquisition.id}") try: diff --git a/imctools/__init__.py b/imctools/__init__.py index c220f22..dfc153f 100644 --- a/imctools/__init__.py +++ b/imctools/__init__.py @@ -6,4 +6,4 @@ __author__ = """Vito Zanotelli, Anton Rau""" __email__ = "vito.zanotelli@uzh.ch, anton.rau@uzh.ch" -__version__ = "2.1.1" +__version__ = "2.1.3" diff --git a/imctools/cli.py b/imctools/cli.py index 2d20391..383a167 100644 --- a/imctools/cli.py +++ b/imctools/cli.py @@ -38,7 +38,7 @@ def main(): def _add_mcdfolder2imcfolder_parser(subparsers: argparse._SubParsersAction): def func(args): - mcdfolder_to_imcfolder(args.input, args.output_folder, args.zip) + mcdfolder_to_imcfolder(args.input, args.output_folder, args.zip, args.parse_txt) parser = subparsers.add_parser( "mcdfolder-to-imcfolder", @@ -48,6 +48,7 @@ def func(args): parser.add_argument("input", help="Path to the folder/zip archive containing the IMC raw data.") parser.add_argument("output_folder", help="Path to the output folder.") parser.add_argument("--zip", action="store_true", help="Whether to create an output as .zip file.") + parser.add_argument("--parse_txt", action="store_true", help="Always use TXT files if present to get acquisition image data.") parser.set_defaults(func=func) diff --git a/imctools/converters/mcdfolder2imcfolder.py b/imctools/converters/mcdfolder2imcfolder.py index a37d80e..62380fd 100644 --- a/imctools/converters/mcdfolder2imcfolder.py +++ b/imctools/converters/mcdfolder2imcfolder.py @@ -13,7 +13,7 @@ logger = logging.getLogger(__name__) -def mcdfolder_to_imcfolder(input: Union[str, Path], output_folder: Union[str, Path], create_zip: bool = False): +def mcdfolder_to_imcfolder(input: Union[str, Path], output_folder: Union[str, Path], create_zip: bool = False, parse_txt: bool = False): """Converts folder (or zipped folder) containing raw acquisition data (mcd and txt files) to IMC folder containing standardized files. Parameters @@ -24,6 +24,8 @@ def mcdfolder_to_imcfolder(input: Union[str, Path], output_folder: Union[str, Pa Path to the output folder. create_zip Whether to create an output as .zip file. + parse_txt + Always use TXT files if present to get acquisition image data. """ if isinstance(input, str): input = Path(input) @@ -55,7 +57,7 @@ def mcdfolder_to_imcfolder(input: Union[str, Path], output_folder: Union[str, Pa txt_files = glob.glob(str(input_folder / f"*[0-9]{TXT_FILE_EXTENSION}")) txt_acquisitions_map = {TxtParser.extract_acquisition_id(f): f for f in txt_files} - imc_writer = ImcWriter(output_folder, mcd_parser, txt_acquisitions_map) + imc_writer = ImcWriter(output_folder, mcd_parser, txt_acquisitions_map, parse_txt) imc_writer.write_imc_folder(create_zip=create_zip) finally: if mcd_parser is not None: @@ -71,12 +73,15 @@ def mcdfolder_to_imcfolder(input: Union[str, Path], output_folder: Union[str, Pa mcdfolder_to_imcfolder( # Path("/home/anton/Downloads/20170905_Fluidigmworkshopfinal_SEAJa.zip"), - "/home/anton/Downloads/20170905_Fluidigmworkshopfinal_SEAJa", + # "/home/anton/Downloads/20170905_Fluidigmworkshopfinal_SEAJa", + "/home/anton/Data/forAnton_MCD/6505_Lympho", # "/home/anton/Documents/merrick/IMC/20200904_MS_XRF_epithelial_panel_4_titration.zip", # "/home/anton/Documents/IMC Workshop 2019/Data/iMC_workshop_2019/20190919_FluidigmBrCa_SE", # "/home/anton/Downloads/test", # "/home/anton/Data/ForAnton/20200123_IMMUcan_reproducibility_day1_sl1_cp_panel_1_1.06.zip", Path("/home/anton/Downloads/imc_folder_v2"), + create_zip=False, + parse_txt=True ) print(timeit.default_timer() - tic) diff --git a/imctools/io/imc/imcwriter.py b/imctools/io/imc/imcwriter.py index e48693d..52d1599 100644 --- a/imctools/io/imc/imcwriter.py +++ b/imctools/io/imc/imcwriter.py @@ -22,6 +22,7 @@ def __init__( root_output_folder: Union[str, Path], mcd_parser: McdParser, txt_acquisitions_map: Dict[int, Union[str, Path]] = None, + parse_txt: bool = False ): """ Initializes an ImcFolderWriter that can be used to write out an imcfolder and compress it to zip. @@ -31,6 +32,7 @@ def __init__( self.root_output_folder = root_output_folder self.mcd_parser = mcd_parser self.txt_acquisitions_map = txt_acquisitions_map + self.parse_txt = parse_txt @property def folder_name(self): @@ -56,7 +58,7 @@ def write_imc_folder(self, create_zip: bool = True, remove_folder: bool = None): # Save acquisition images in OME-TIFF format for acquisition in session.acquisitions.values(): acquisition_data = self.mcd_parser.get_acquisition_data(acquisition.id) - if not acquisition_data.is_valid: + if self.parse_txt or not acquisition_data.is_valid: if self.txt_acquisitions_map is not None and acquisition.id in self.txt_acquisitions_map: logger.warning(f"Using TXT file for acquisition: {acquisition.id}") try: diff --git a/pyproject.toml b/pyproject.toml index a786249..6fdaab5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "imctools" -version = "2.1.2" +version = "2.1.3" description = "Tools to handle Fluidigm IMC data" license = "MIT" authors = ["Vito Zanotelli ", "Anton Rau "] diff --git a/setup.cfg b/setup.cfg index b010eab..67c016c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.1.2 +current_version = 2.1.3 commit = False tag = False