Created
June 25, 2025 13:23
-
-
Save NicoKiaru/3fde85a6a5555b2b06b3789019da9381 to your computer and use it in GitHub Desktop.
Small macro that helps make sense of the positions file in FCS experiments #BIOP #Fiji LSM710
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* For Tessa Averink, Goenczy Lab | |
* To read positions of FCS coordinates used on the LSM710 at the BIOP | |
* | |
* Rationale: | |
* Coordinates are stores in the FCS file as X Y Z coordinates at the location of the 'PositionCoordinates' | |
* These are replicated as many times as there are positions recorded. | |
* | |
* The positions are stred in METERS and represent the X Y coordinates fromn the CENTER of the image. | |
* | |
* EDIT 01/06/2017 | |
* As it turns out, because the FCS coordinates are with respect to the field of view, | |
* if the user offsets the image acquisition position, our initial assumption that the | |
* center of the image is at 0,0 is wrong. We need to extract the XY offset metadata from the LSM file | |
* | |
* This is encoded by the 'Recording Sample 0X #1' and 'Recording Sample 0Y #1' metadata | |
* | |
* But this means we need to re-extract the metadata positions from the original file | |
*/ | |
macro "Get FCS Positions [F2]" { | |
roiManager("Reset"); | |
name = getTitle(); | |
getVoxelSize(vx,vy,vz,U); | |
getDimensions(width, height, c,z,t); | |
// Ask for FSC file | |
file = File.openDialog("FCS File Linked to Image "+name); | |
/* | |
* Fixing offet in field of view | |
* If the LSM file is inside the same folder, we can reopen it with Bioformats | |
* and get the offset. This metadata value is only for LSM files... | |
* | |
*/ | |
// Get the folder name to search for the lsm file again | |
directory = substring(file, 0, lastIndexOf(file, File.separator)+1); | |
// Default offset in X and Y | |
offsetX = 0; | |
offsetY = 0; | |
// If we find the file, we parse it | |
if(File.exists(directory+name)) { | |
run("Bio-Formats Macro Extensions"); | |
Ext.setId(directory+name); | |
Ext.getSeriesMetadataValue( "Recording Sample 0X #1", offsetX); | |
Ext.getSeriesMetadataValue( "Recording Sample 0Y #1", offsetY); | |
} | |
print("Offsets used for", name, ": ", "X:",offsetX,"Y:", offsetY); | |
str = split(File.openAsString(file), "\n"); | |
for(i=0; i<str.length; i++) { | |
temp = str[i]; | |
if(matches(temp, ".*PositionCoordinates.*")) { | |
nPos = parseInt(substring(temp, indexOf(temp, "=")+1, lastIndexOf(temp, " "))); | |
print(nPos+" Positions Found in "+file); | |
posx = newArray(nPos); | |
posy = newArray(nPos); | |
for(k=0; k<nPos;k++) { | |
postmp = split(str[i+k+1]," "); | |
posx[k] = parseFloat(postmp[0]); | |
posy[k] = parseFloat(postmp[1]); | |
} | |
i=str.length; | |
} | |
} | |
// Convert coordinates to the actual ROI positions; | |
print("----------------"); | |
print("Before Conversion"); | |
for(i=0; i<nPos; i++) { | |
print("X["+i+"]="+posx[i]+" ;Y["+i+"]="+posy[i]); | |
} | |
for(i=0; i<nPos; i++) { | |
posx[i] = (posx[i] * 1e6 - offsetX) /vx + width/2; | |
posy[i] = (posy[i] * 1e6 - offsetY) /vx + height/2; | |
makePoint(posx[i],posy[i]); | |
Roi.setName("Position "+(i+1)); | |
roiManager("Add"); | |
} | |
print("----------------"); | |
print("After Conversion in px with proper coordinates"); | |
for(i=0; i<nPos; i++) { | |
print("X["+i+"]="+posx[i]+" ;Y["+i+"]="+posy[i]); | |
} | |
roiManager("Show All with labels"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment