forked from serrano-pozo-lab/glia-ihc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reorder-channels.Rmd
108 lines (74 loc) · 3.89 KB
/
reorder-channels.Rmd
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
---
title: "Reorder Channels"
description: |
This ImageJ script allows the user to reorder imaging channels as necessary to facilitate downstream analysis.
author:
- first_name: "Ayush"
last_name: "Noori"
url: https://www.github.com/ayushnoori
affiliation: Massachusetts General Hospital
affiliation_url: https://www.serranopozolab.org
orcid_id: 0000-0003-1420-1236
output:
distill::distill_article:
toc: true
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(eval = FALSE)
```
This script is written in the ImageJ Macro Language (IJM).
``` {.ijm .IJM}
macro "Reorder Channels [r]" {
// setBatchMode(true); // will bypass GUI!
dir = "<insert your directory here>";
output = dir + "Converted TIFF Crops/Reordered Crops/";
input = getDirectory("Choose input data folder.");
files = getFileList(input);
Array.show(files);
for (f = 0; f < files.length; f++) {
open(input + files[f]);
////////////////////////////////////////////////////////////
///// LOAD IMAGE + DEFINE MARKERS
////////////////////////////////////////////////////////////
image = getTitle(); // get crop title
selectImage(image); // shift focus to the selected crop
filename = substring(image, 0, indexOf(image, ".tif"));
run("8-bit"); // convert to 8-bit, note that will lose fluorescence granularity
// create array to hold assigned slice names
titles = newArray(nSlices);
// list possible marker names
markerNames = newArray("GFAP", "DAPI", "MHC2", "TSPO", "EAAT2", "TMEM119", "CD68", "EAAT1", "ALDH1L1", "IBA1", "Vimentin", "Ferritin", "HuCD", "YKL40", "GS", "Abeta", "PHF1-tau");
for (i = 1; i <= nSlices; i++) {
setSlice(i);
run("Enhance Contrast...", "saturated=0.3"); // only for visualization purposes
// call dialog box to assign marker name to selected slice
Dialog.create("Which Marker Is This?");
Dialog.addChoice("Type:", markerNames);
Dialog.show();
marker = Dialog.getChoice();
// set slice name based on user choice
setMetadata("Label", marker);
titles[i-1] = getInfo("slice.label");
markerNames = Array.deleteValue(markerNames, marker); // prevents the same marker from being assigned to multiple slices
}
////////////////////////////////////////////////////////////
///// REORDER SLICES + DEFINE LUT
////////////////////////////////////////////////////////////
run("Stack to Images"); // separate each slice
// concatenate in right order - rearranges all slices
run("Concatenate...", " title=" + image + " open image1=DAPI image2=ALDH1L1 image3=IBA1 image4=GFAP image5=MHC2 image6=TSPO image7=EAAT2 image8=TMEM119 image9=CD68 image10=EAAT1 image11=Vimentin image12=Ferritin image13=YKL40 image14=GS image15=HuCD image16=Abeta image17=PHF1-tau");
// make composite image with color
run("Make Composite", "display=Color");
finalNames = newArray("DAPI", "ALDH1L1", "IBA1", "GFAP", "MHC2", "TSPO", "EAAT2", "TMEM119", "CD68", "EAAT1", "Vimentin", "Ferritin", "YKL40", "GS", "HuC/D", "Abeta", "PHF1-tau");
colorList = newArray("Blue", "Red", "Green", "Magenta", "Cyan", "Yellow", "Grays");
for (k = 1; k <= nSlices; k++) {
setSlice(k);
setMetadata("Label", finalNames[k-1]); // set final name of slice
run(colorList[(k-1) % colorList.length]); // apply distinct false color per slice
// add more data pre-processing if desired!
}
saveAs("Tiff", output + filename + "_Reordered.tif");
close();
}
}
```