-
Notifications
You must be signed in to change notification settings - Fork 2
/
iba1-extraction.Rmd
120 lines (91 loc) · 3.34 KB
/
iba1-extraction.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
109
110
111
112
113
114
115
116
117
118
119
120
---
title: "Microglia Channel Extraction"
description: |
This ImageJ script extracts the IBA1 channel from multi-channel TIFF images and assigns each image a random alphanumeric code for blinded microglia annotation.
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 "IBA1 Channel Extraction" {
setBatchMode(true);
input = getDirectory("Choose input data folder.");
files = getFileList(input);
// Array.show(files);
dir = "C:/Users/ayush/Dropbox (Partners HealthCare)/Single-Cell Multiplex IHC/Multiplex IHC Project/Multiplex IHC (GitLab)/";
datadir = dir + "Data/2 - Channel Extraction/Microglia/";
////////////////////////////////////////////////////////////
///// FUNCTION FOR RANDOM ID
////////////////////////////////////////////////////////////
function randomString(length, chars) {
result = "";
for (i = 0; i < length; i++) {
maxlen = lengthOf(chars)-1;
rand = round(random * maxlen);
result += substring(chars, rand, rand+1);
}
return result;
}
////////////////////////////////////////////////////////////
///// ITERATE OVER IMAGES
////////////////////////////////////////////////////////////
for (f = 0; f < files.length; f++) {
open(input + files[f]);
Roi.remove; // remove active selection, if any
////////////////////////////////////////////////////////////
///// LOAD IMAGE + DEFINE MARKERS
////////////////////////////////////////////////////////////
image = getTitle(); // get crop title
selectImage(image); // shift focus to the selected crop
filename = substring(image, 0, indexOf(image, "_Reordered.tif"));
splitname = split(filename, "_");
sample = splitname[0];
layer = splitname[1];
crop = splitname[2];
crop = substring(crop, 4);
if (sample == "1190" || sample == "1301" || sample == "1619" || sample == "2169" || sample == "2191" || sample == "2250" || sample == "2274") {
condition = "CTRL";
} else {
condition = "AD";
}
print(filename);
////////////////////////////////////////////////////////////
///// RANDOMIZE CROP
////////////////////////////////////////////////////////////
id = randomString(6, "0123456789abcdefghijklmnopqrstuvwxyz");
// print(id);
Table.set("ID", f, id);
Table.set("Sample", f, sample);
Table.set("Layer", f, layer);
Table.set("Crop", f, crop);
Table.set("Condition", f, condition);
Table.set("File", f, filename);
Table.update();
////////////////////////////////////////////////////////////
///// SAVE IBA1 CHANNEL
////////////////////////////////////////////////////////////
// duplicate IBA1 channel
selectImage(image); // shift focus to original
run("Duplicate...", "title=IBA1 duplicate channels=3");
run("Enhance Contrast...", "saturated=0.1"); // only for visualization purposes
selectWindow("IBA1"); // shift focus to original
saveAs("Png", datadir + condition + "/" + id + ".png");
close();
selectImage(image);
close();
}
// save table with mappings
Table.save(datadir + "ID Mappings.csv")
}
```