jiaxuanleong / SPIRO.Assays

ImageJ macros written to analyse data acquired by SPIRO imaging
BSD 2-Clause "Simplified" License
3 stars 0 forks source link

Suggestions and help #23

Closed L-103 closed 7 months ago

L-103 commented 8 months ago

Hey,

I have recently built and started to use your very cool SPIRO device. To start with, congrats, it is a very nice tool and easy to setup. I wanted to discuss with you about a few points:

1- Filenaming In my case, I cannot, or rather don't want to go through the trouble of running the RPI on the local network. This leads to file that are wrongly dated and timed. I wanted to share with you the solution that I made for myself hoping it could help someone else. I am running this Python script on my folder, with the only information required being the start date and time of your experiment (that you note on the side when you start your experiment...):

import os
from datetime import datetime, timedelta

def rename_files(start_date, start_time, directory):
    # Convert start_date and start_time to datetime object
    start_datetime = datetime.strptime(start_date + start_time, '%Y%m%d%H:%M:%S')

    # Find the minimum datetime among all files
    min_datetime = None
    for root, dirs, files in os.walk(directory):
        for filename in files:
            if filename.endswith('.png'):
                parts = filename.split('-')
                file_datetime = datetime.strptime(parts[1] + parts[2], '%Y%m%d%H%M%S')
                if min_datetime is None or file_datetime < min_datetime:
                    min_datetime = file_datetime

    # Iterate through files in directory and subdirectories
    for root, dirs, files in os.walk(directory):
        for filename in files:
            if filename.endswith('.png'):
                parts = filename.split('-')
                plate_number = parts[0]
                dayornight = parts[3]
                file_datetime = datetime.strptime(parts[1] + parts[2], '%Y%m%d%H%M%S')

                # Calculate time difference between start and current file
                time_difference = file_datetime - min_datetime

                # Calculate new timestamp for the file
                new_datetime = start_datetime +  time_difference

                # Rename the file with new timestamp
                new_filename = f'{plate_number}-{new_datetime.strftime("%Y%m%d-%H%M%S")}-{dayornight}'
                os.rename(os.path.join(root, filename), os.path.join(root, new_filename))

    print("Files renamed successfully!")

# Example usage:
start_date = input("Enter start date (YYYYMMDD): ")
start_time = input("Enter start time (HH:MM:SS): ")
directory = input("Enter path to folder. (Double backslash instead of simple backslash and end with double backslash as well): ")

rename_files(start_date, start_time, directory)

2- Error in R code? While going through the pipeline to get root growth length, I stumbled upon an error.

In process_rootgrowth_data.R, I had to remove the "[0,24,48,72,96,120,144]" from the following line (59 and also 73):

  fit.glmmTMB %>% ggeffect(terms = c("RelativeElapsedHours","Group")) -> glmmTMB_model_ggeffects

Other than that, the pipeline runs smoothly and you did a nice job to describe it.

3- Your opinion? After the first running of the experiment, I tend to have very noisy data with growth curves jumping up and down. Model prediction overview.pdf Root length barchart.pdf

I can see that I have some breaks in the segmentation, mostly during the night when the green lamp turns on. Could it be my issue? What would be your recommendation to improve the smoothness of the results? Do you need some more graphs to give me an answer?

Thanks a lot

jonasoh commented 8 months ago

Hi L-103, happy to hear your SPIRO is working well! The script for renaming files looks brilliant. We have ours connected to the net so hadn't reflected on this. If you're ok with it, I'll put it in an "Extras" folder or something like this so it is easier to find? I should probably also add a method for setting the system date via the web UI.

Regarding the R error, I'd have to investigate it. What was the error you were getting?

Your data does indeed look messy. On plate4, it also seems the germination detection algorithm has failed. This should be obvious from the pre-analysis graphs (generated after running the Consolidate rootgrowth data script). If germination times are off, they can be manually changed in the germination-perseed file.

I personally do not work on the imaging and plating side of things, but there are some things to try for improving the quality of images: Tweak your image exposure settings in the web UI. Don't use too much medium on your plates. If possible, use the anti-reflection lids. The distance between the camera and the cube, and the LED illuminator and the cube also impact image quality.

There is also a root skeleton overlay which could be enabled in the macro when running in debug mode, but its use is not recommended since it adds artifacts. I'd try to tweak the image quality first.

L-103 commented 8 months ago

Hey,

I am totally fine with whatever you want to do with this code. Indeed, in our case, we don't have the SPIRO running all the time and we unplug it often. Having the possibility to setup the date and time before the start of the experiment could be useful for people that don't have it connected to internet.

Well, I don't remember exactly what the R error was but it was along the line that I wasn't using numerical values for my graph. I only realized that the column that was referred to in the code had a header without the "[0,24,48,72,96,120,144]" part. So I removed it and it worked...

Thanks for the advice I will look into that. If you could somehow get a hold of some information or put me in contact with people using the device regularly it would be nice. All these parameters you are talking about can indeed be tuned and I guess your people have way more experience than me :-) If I can save myself some trouble...

jonasoh commented 8 months ago

Well if you run into the error again, please copy it here :) The syntax should be correct for ggeffects as far as I can tell. It's to give predictions for these specific timepoints instead of the 10-hour intervals you get in your graph.

For image quality issues, I'd ping Alyona (last author on the paper: https://onlinelibrary.wiley.com/doi/10.1111/tpj.16587). She knows that stuff best.

L-103 commented 8 months ago

Hey,

Here is the error I am getting if I keep the part between brackets.

Error in round(at_values[[1]], 5) : 
  non-numeric argument to mathematical function

Will do then.

jonasoh commented 8 months ago

Hm, not sure what is going on there. Could you attach your rootgrowth.postQC.tsv and germination-perseed.tsv files for me to have a look?

L-103 commented 8 months ago

I'm very new to Github, I can apparently not share .tsv files? Here are the txt file version.

Thanks for your time!

germination-perseed.txt rootgrowth.postQC.txt

jonasoh commented 8 months ago

Perfect. I can reproduce the error here. Will look into it.

jonasoh commented 7 months ago

Hi again, this error was caused by a problem in the ggeffects package. It's now been fixed but the updated package (version 1.5.1.4) isn't yet available on CRAN. As soon as it's updated on CRAN you should be able to update your packages and get normal-looking charts!

L-103 commented 7 months ago

Thanks. I will check on that on the new run I am doing now. I have reduced the quantity of gel in the plate (as it is described in the protocol... if only I could read!) and indeed, I can see the seedlings better so I feel like the image analysis is going to be smoother!

jonasoh commented 7 months ago

Excellent! Get in touch if you have any more issues!