-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeorge_mitophagy_Dmi8_looped.ijm
130 lines (108 loc) · 5.05 KB
/
George_mitophagy_Dmi8_looped.ijm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
macro 'mitophagy analysis in LIFs' {
/*
* - Based on earlier macro that converts LIF files into TIFF.
* - the macro ask for an input folder that should contain 1 or more lif files. Nothing else.
* - each series is saved as one tiff. The name of the series is appended to the file name.
* - if the series has more than one frame, a Max Intensity projection is also performed
* - before saving. The TIFFs are saved in a folder generated by the macro in the same
* - parent folder as the lifs, with the same prefix for the folder name, with TIFF suffix.
*
* Martin Hoehne, August 2015
*
* Update October 2015: works for Multichannel images as well
*
* Update Jan2016 (Glyn Nelson). Now also saves z stack as well as mip if it is a z stack.
* This works with SP8 images as long as they aren't in subfolders, such as Mark and Find: these
* images have a '/' in their name, so it throws an error when trying to save.
* Update Jan2016 (Glyn Nelson). Fixed. It will now remove '/' if it exists in the imagename before saving.
*
* Update Feb 2016 (Glyn Nelson). Now ignores other files in the folder with lifs (although it will give multiple finished
* messages for each extra file it finds...)
*
*
*
* September2019. Modified to automatically remove green signal from red mitphogay data in George's Dmi8 images
* REQUIREMENTS:
* mito-mKeima transfected cells used for this- ratiometric, excitation dependent upon pH
* https://www.nature.com/articles/nprot.2017.060
* https://www.fpbase.org/protein/mkeima/
* Single plane lif files with 2 channels, green (440ex) in channel1 and red (560ex) in channel2
* (can have more channels, but these two need to be the first and in this order)
*
* Notes. Could add to work on z stacks too, either as a projection, or each slice one at a time (would worry
* about spurious results from the out of focus planes in thsi case though).
*/
run("Bio-Formats Macro Extensions");
dir1 = getDirectory("Choose folder with lif files ");
list = getFileList(dir1);
setBatchMode(true);
// create folders for the tifs
dir1parent = File.getParent(dir1);
dir1name = File.getName(dir1);
dir2 = dir1parent+File.separator+dir1name+"_Tiffs";
if (File.exists(dir2)==false) {
File.makeDirectory(dir2); // new directory for tiff
}
for (i=0; i<list.length; i++) {
showProgress(i+1, list.length);
print("processing ... "+i+1+"/"+list.length+"\n "+list[i]);
filename = dir1 + list[i];
if (endsWith(filename, "lif")){
path=dir1+list[i];
//how many series in this lif file?
Ext.setId(path);//-- Initializes the given path (filename).
Ext.getSeriesCount(seriesCount); //-- Gets the number of image series in the active dataset.
for (j=1; j<=seriesCount; j++) {
run("Bio-Formats", "open=path autoscale color_mode=Default view=Hyperstack stack_order=XYCZT series_"+j);
name=File.nameWithoutExtension;
//retrieve name of the series from metadata
text=getMetadata("Info");
n1=indexOf(text," Name = ")+8;// the Line in the Metadata reads "Series 0 Name = ". Complete line cannot be taken, because
// The number changes of course. But at least in the current version of Metadata this line is the
// only occurence of " Name ="
n2=indexOf(text,"SizeC = "); // this is the next line in the Metadata
extractedname=substring(text,n1,n2-2);
cleanname=split(extractedname,"/"); // this is done here to remove the forward slash that is found in the image name
// if it is part of a mark and find subfolder, for example
//We still want both parts of the filenename. So if there are two parts to the array, then stick them together, otherwise just take the first:
if (cleanname.length==2){
seriesname=cleanname[0]+cleanname[1];
}
else seriesname=cleanname[0];
//Make masked Red channel with green removed and low signal red removed
rename("orig");
run("Duplicate...", "title=green duplicate channels=1");
setAutoThreshold("MaxEntropy dark");
setOption("BlackBackground", false);
run("Convert to Mask");
run("16-bit");
run("Multiply...", "value=257.000");
selectWindow("orig");
run("Duplicate...", "title=red duplicate channels=2");
imageCalculator("Subtract create", "red","green");
selectWindow("Result of red");
rename("redMasked");
selectWindow("redMasked");
setAutoThreshold("MaxEntropy dark");
run("Convert to Mask");
run("16-bit");
run("Multiply...", "value=257.000");
selectWindow("redMasked");
run("Invert");
imageCalculator("Subtract create", "red","redMasked");
selectWindow("Result of red");
rename("redFinal");
//stick modified red image onto end of orignal image and save as stack
run("Concatenate ", " title=[Concat] image_1=[orig] image_2=[redFinal] image_3=[-- None --]");
// Stack.setDisplayMode("composite");
run("Make Composite", "display=Composite");
saveAs("TIFF", dir2+File.separator+name+"_"+seriesname+".tif");
run("Close All");
// run("Collect Garbage");
}
}
run("Close All");
setBatchMode(false);
}
showMessage(" Well, I think we gave them a damn good thrashing there, what what??");
// macro