macro "Calculate Ratios" { DefCats = newArray("Default", "Axon", "Dendrite", "Primary", "Secondary", "Tertiary", "Type 06", "Type 07"); Path = File.openDialog("Choose Results table"); Results = File.openAsString(Path); // Retrieve the Labels column, the mean intenisty column and the area column IMAGENAMES = getColumn(Results,"Slice"); TYPES = getColumn(Results,"ROI type#"); CATS = getColumn(Results,"ROI type"); if (IMAGENAMES == -1 || TYPES == -1 || CATS == -1) exit ("One of the required column doesn't exist!"); // Mean intensity used is the background-corrected mean (output by the "Measure Intensities" macro) or if no corrected mean column is found, the raw mean intensity. CORRMEAN = getColumn(Results,"Corr Mean"); if (CORRMEAN == -1) CORRMEAN = getColumn(Results,"Raw Mean"); if (CORRMEAN == -1) exit ("Mean intensity column doesn't exist!"); AREA = getColumn(Results, "Area"); if (AREA == -1) exit ("Area column doesn't exist!"); // gets the number of images (defines the per-image arrays length) U=getUnique(IMAGENAMES); UT = getUnique(CATS); UCATS = newArray(UT); UCATS[0] = CATS[0]; u = 0; for (i = 1; i < CATS.length; i++) { if (CATS[i] != CATS[i-1]) { u++; UCATS[u] = CATS[i]; } } Dialog.create("Calculate Ratios Options"); Dialog.addChoice("Numerator (N)", UCATS, UCATS[0]); Dialog.addChoice("Denominator (D)", UCATS, UCATS[UCATS.length-1]); Dialog.show(); CatNum = Dialog.getChoice(); CatDen = Dialog.getChoice(); CatNumN = getIndex(DefCats, CatNum); CatDenN = getIndex(DefCats, CatDen); // Define all per-image arrays // Names : name of the image // SumType: summed integrated intensities // LenType: summed areas // MoyType: SumType / LenType, i.e. overall mean intensity for all ROIs pooled // MoyType does not depend on the spatial scale as it is present as a multiplicative factor in SumType and LenType // Type: summed mean intensities // NType: number of ROIs // NMoy: Type / NType, i.e. average of mean intensities for each ROI as individual mean intensities // NType does not depend on the spatial scale // Ratio: ratio of MoyTypes, i.e. ratio of overall mean intensity for all ROIs pooled // NRatio: ratio og NMoy, i.e. ratio of averages for each ROI as individual mean intensities Names = newArray(U); SumTypeA = newArray(U); LenTypeA = newArray(U); MoyA = newArray(U); TypeA = newArray(U); NTypeA = newArray(U); NMoyA = newArray(U); SumTypeB = newArray(U); LenTypeB = newArray(U); MoyB = newArray(U); TypeB = newArray(U); NTypeB = newArray(U); NMoyB = newArray(U); RatioAB = newArray(U); NRatioAB = newArray(U); // Initialization for i = 0 (first Results Table line) Names[0] = IMAGENAMES[0]; // Stores values in the first per-image slot if the ROI in the current line is #A if (TYPES[0] == CatNumN){ LenTypeA[0] = 0 + AREA[0]; SumTypeA[0] = 0 + CORRMEAN[0] * AREA[0]; TypeA[0] = 0 + CORRMEAN[0]; NTypeA[0] = 1; typeflag = 1; } // Stores values in the first per-image slot if the ROI in the current line is #B if (TYPES[0] == CatDenN) { LenTypeB[0] = 0 + AREA[0]; SumTypeB[0] = 0 + CORRMEAN[0] * AREA[0]; TypeB[0] = 0 + CORRMEAN[0]; NTypeB[0] = 1; typeflag = 1; } // Loop on all following Results Table lines UIndex = 0; for (j = 1; j < IMAGENAMES.length; j++) { // This detects if it's a new image (new averages) and iterates UIndex to store in the next slot in the per-images array if (IMAGENAMES[j] != IMAGENAMES[j - 1]) { UIndex = UIndex+1; Names[UIndex] = IMAGENAMES[j]; } // Stores values in the current per-image slot if the ROI in the current line is #A if (TYPES[j] == CatNumN) { LenTypeA[UIndex] = LenTypeA[UIndex] + AREA[j]; SumTypeA[UIndex] = SumTypeA[UIndex] + CORRMEAN[j] * AREA[j]; TypeA[UIndex] = TypeA[UIndex] + CORRMEAN[j]; NTypeA[UIndex] = NTypeA[UIndex] + 1; } // Stores values in the current per-image slot if the ROI in the current line is #B if (TYPES[j] == CatDenN) { LenTypeB[UIndex] = LenTypeB[UIndex] + AREA[j]; SumTypeB[UIndex] = SumTypeB[UIndex] + CORRMEAN[j] * AREA[j]; TypeB[UIndex] = TypeB[UIndex] + CORRMEAN[j]; NTypeB[UIndex] = NTypeB[UIndex] + 1; } } // Loops on all per-image slots for (j=0; j