def update_tifs(animal, channel): """ Args: animal: the prep id of the animal channel: the channel of the stack to process njobs: number of jobs for parallel computing Returns: nothing """ fileLocationManager = FileLocationManager(animal) sqlController = SqlController(animal) tifs = sqlController.get_distinct_section_filenames(animal, channel) INPUT = os.path.join(fileLocationManager.prep, 'CH1', 'full') # Update TIFs' size try: os.listdir(INPUT) except OSError as e: print(e) sys.exit() for i, tif in enumerate(tqdm(tifs)): print(tif.file_name) input_path = os.path.join(INPUT, str(i).zfill(3) + '.tif') if os.path.exists(input_path): print(input_path) tif.file_size = os.path.getsize(input_path) sqlController.update_row(tif)
def make_tifs(animal, channel, njobs): """ This method will: 1. Fetch the sections from the database 2. Yank the tif out of the czi file according to the index and channel with the bioformats tool. 3. Then updates the database with updated meta information Args: animal: the prep id of the animal channel: the channel of the stack to process njobs: number of jobs for parallel computing compression: default is no compression so we can create jp2 files for CSHL. The files get compressed using LZW when running create_preps.py Returns: nothing """ logger = get_logger(animal) fileLocationManager = FileLocationManager(animal) sqlController = SqlController(animal) INPUT = fileLocationManager.czi OUTPUT = fileLocationManager.tif os.makedirs(OUTPUT, exist_ok=True) sections = sqlController.get_distinct_section_filenames(animal, channel) sqlController.set_task(animal, QC_IS_DONE_ON_SLIDES_IN_WEB_ADMIN) sqlController.set_task(animal, CZI_FILES_ARE_CONVERTED_INTO_NUMBERED_TIFS_FOR_CHANNEL_1) commands = [] for section in sections: input_path = os.path.join(INPUT, section.czi_file) output_path = os.path.join(OUTPUT, section.file_name) cmd = ['/usr/local/share/bftools/bfconvert', '-bigtiff', '-separate', '-series', str(section.scene_index), '-channel', str(section.channel_index), '-nooverwrite', input_path, output_path] if not os.path.exists(input_path): continue if os.path.exists(output_path): continue commands.append(cmd) with Pool(njobs) as p: p.map(workernoshell, commands)
def test_tif(animal, channel): sqlController = SqlController(animal) checks = ['tif'] fileLocationManager = FileLocationManager(animal) # tifs for name, dir in zip(checks, [fileLocationManager.tif]): db_files = sqlController.get_distinct_section_filenames( animal, channel) valid_file_length = db_files.count() dir_exists, lfiles, badsize = directory_filled(dir, channel) if not dir_exists: print("{} does not exist.".format(dir)) missings = find_missing(dir, db_files) if len(missings) > 0: print("Missing files:") count = 1 for missing in missings: print(count, missing) count += 1