Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Thibault Tabarin committed Jun 28, 2022
1 parent 63e8d08 commit b60779f
Show file tree
Hide file tree
Showing 11 changed files with 1,387 additions and 0 deletions.
59 changes: 59 additions & 0 deletions Scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
FROM ubuntu:20.04

# Label
LABEL org.opencontainers.image.title="fish cropping and trait morphology"
LABEL org.opencontainers.image.authors=" T. Tabarin"
LABEL org.opencontainers.image.source="https://github.com/hdr-bgnn/BGNN_Snakemake"

# Install some basic utilities
RUN apt-get update && apt-get install -y \
curl \
ca-certificates \
sudo \
git \
bzip2 \
libx11-6 \
wget \
&& rm -rf /var/lib/apt/lists/*

# Create a working directory
RUN mkdir /app
WORKDIR /app

# Create a non-root user and switch to it
RUN adduser --disabled-password --gecos '' --shell /bin/bash user \
&& chown -R user:user /app
RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user
USER user

# All users can use /home/user as their home directory
ENV HOME=/home/user
RUN chmod 777 /home/user

# Set up the Conda environment
ENV CONDA_AUTO_UPDATE_CONDA=false \
PATH=/home/user/miniconda/bin:$PATH
COPY morphology_env.yml /app/environment.yml
RUN curl -sLo ~/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-py38_4.9.2-Linux-x86_64.sh \
&& chmod +x ~/miniconda.sh \
&& ~/miniconda.sh -b -p ~/miniconda \
&& rm ~/miniconda.sh \
&& conda env update -n base -f /app/environment.yml \
&& rm /app/environment.yml \
&& conda clean -ya

WORKDIR /pipeline

# Setup pipeline specific scripts
ENV PATH="/pipeline/Morphology:${PATH}"
ENV PATH="/pipeline/Crop:${PATH}"
ENV PATH="/pipeline/Merge_files:${PATH}"
ADD Crop_image/Crop_image_main.py /pipeline/Crop/Crop_image_main.py
ADD Morphology/Traits_class.py /pipeline/Morphology/Traits_class.py
ADD Morphology/Morphology_main.py /pipeline/Morphology/Morphology_main.py
ADD Merge_files/Merge_files_main.py /pipeline/Merge_files/Merge_files_main.py

# Set the default command to a usage statement
CMD echo "Usage crop: Crop_image_main.py <input_image.jpg> <image_metadata.json> <image_cropped.png>\n"\
"Usage Morphology: Morphology_main.py <input_file> <measure.json> <landmark.json> <presence.json> <image_lm.png>\n"\
"Usage Merge_file: Merge_files_main.py <input_directory> <merge.csv> <merge.json>"
405 changes: 405 additions & 0 deletions Scripts/Morphology_dev.ipynb

Large diffs are not rendered by default.

75 changes: 75 additions & 0 deletions Scripts/Morphology_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue May 24 09:21:33 2022
@author: thibault
"""
import Traits_class as tc
import json, sys

def get_scale(metadata_file):

'''
extract the scale value from metadata file
'''

f = open(metadata_file)
data = json.load(f)
metadata_dict = list(data.values())[0]

if 'scale' in metadata_dict :

scale = round(metadata_dict['scale'],3)
unit = metadata_dict['unit']
else:
scale =[None]
unit =[None]
return scale , unit


def main(input_file, metadata_file, output_measure, output_landmark, output_presence,
output_lm_image=None):

img_seg = tc.segmented_image(input_file)
measurement = img_seg.measurement
landmark = img_seg.landmark
presence_matrix = img_seg.presence_matrix

# Extract the scale from metadata file
# and add it to measurement dict
scale , unit = get_scale(metadata_file)
measurement['scale'] = scale
measurement['unit'] = unit

# Save the dictionnaries in json file
with open(output_measure, 'w') as f:
json.dump(measurement, f)

with open(output_landmark, 'w') as f:
json.dump(landmark, f)

with open(output_presence, 'w') as f:
json.dump(presence_matrix, f)

if output_lm_image:

img_landmark = img_seg.visualize_landmark()
img_landmark.save(output_lm_image)


if __name__ == '__main__':

input_file = sys.argv[1]
metadata_file = sys.argv[2]
output_measure = sys.argv[3]
output_landmark = sys.argv[4]
output_presence = sys.argv[5]
output_lm_image = None


if len(sys.argv)==7:
output_lm_image = sys.argv[6]

main(input_file, metadata_file, output_measure, output_landmark, output_presence,
output_lm_image=output_lm_image)
Loading

0 comments on commit b60779f

Please sign in to comment.