forked from serrano-pozo-lab/glia-ihc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phf1-extraction.Rmd
123 lines (94 loc) · 3.44 KB
/
phf1-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
121
122
123
---
title: "Tangle Channel Extraction"
description: |
This ImageJ script extracts the PHF1 and DAPI channels from multi-channel TIFF images, merges both channels, and assigns each image a random alphanumeric code for blinded tangle annotation and classification as intraneuronal vs. extraneuronal.
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 "PHF1 Channel Extraction" {
setBatchMode(true);
input = getDirectory("Choose input data folder.");
files = getFileList(input);
// Array.show(files);
dir = "<insert your directory here>";
datadir = dir + "Data/2 - Channel Extraction/Tangle/";
////////////////////////////////////////////////////////////
///// 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 PHF1 AND DAPI CHANNELS
////////////////////////////////////////////////////////////
// duplicate PHF1 channel and merge with HuC/D
selectImage(image); // shift focus to original
run("Duplicate...", "title=PHF1 duplicate channels=17");
selectImage(image);
run("Duplicate...", "title=DAPI duplicate channels=1");
// merge channels
run("Merge Channels...", "c2=PHF1 c3=DAPI create");
selectWindow("Composite"); // shift focus to original
saveAs("Png", datadir + condition + "/" + id + ".png");
close();
selectImage(image);
close();
}
// save table with mappings
Table.save(datadir + "ID Mappings.csv")
}
```