To begin using R, you need to install R from this site. You also need to download and install a development environment. We recommend RStudio. A good walkthrough is available here.
Once you’ve started R, the InflammationIndex package can be installed first by installing and loading devtools to enable installing packages directly from GitHub, then installing the InflammationIndex package from GitHub.
To do this, type in and execute the following code:
require(devtools)
install_github("BrainEnergyLab/Inflammation-Index/R Package")
Then load in the package using:
require(InflammationIndex)
You’ll also want to install and load the data.table package, which we use in the InflammationIndex functions, and in this README, using the following code:
install.packages('data.table')
require(data.table)
This README contains links to example datasets users can download in order to follow along with. These are the:
- Fji example output
directory
- Users can download this directory and then pass the location of the ‘Image Storage Directory’ and ‘Working Directory/Output’ folders as strings to InflammationIndex package functions to following the examples for Step 1: Loading in Data (morphPreProcessing() function).
- Example morphPreProcessing() Function
Output
- Users can download this file, which is an example of what is output by the morphPreProcessing() function in the InflammationIndex package, so that they can follow along with the examples in Step 2: Constructing the Inflammation Index (constructInfInd() function) and Step 3: Apply the Inflammation Index to test data (applyInfInd()).
After users have run the Microglia Morphology Analysis Fiji plugin (see here), the morphPreProcessing() function from the InflammationIndex R package can be used to read in and collate all the morphological metrics extracted.
This function reads in the .csv files produced by the Fiji plugin e.g.
As well as the .txt files generated by the FracLac plugin e.g.
This function requires users to specify:
- pixelSize: The pixel size in microns (assuming a square pixel)
- Double
- e.g. 0.58
- morphologyWD: The file path to the ‘Output’ folder of the
‘Working Directory’ of the Fiji plugin passed as a string
- String
- e.g. ‘/Working Directory/Output’
- For the examples here we are using a path to ‘Working Directory/Output/’ from this Fji example output directory.
- animalIDs: A string vector where each element is the ID of an
animal that users want to extract data for
- String vector
- e.g. c(‘Animal1’, ‘Animal2’)
- treatmentIDs: A string vector where each element is the ID of
the treatment applied that users want to extract data for
- String vector
- e.g. c(‘Timepoint1’, ‘Timepoint2’)
Optional inputs:
- TCSExclude: a numeric vector of mask size values that users want
to exclude from the data collation
- Integer vector
- e.g. c(600, 700)
- Defaults to NULL (no values are excluded)
- useFrac: a boolean that indicates whether the user wants to
include data from FracLac in their collation
- Boolean
- e.g. TRUE
- Defaults to False
The output of the function is a data.table where each row is a cell and the columns indicate morphological metrics.
Here we are specifying our arguments, note we’ve opted to include the data obtained from the FracLac ImageJ plugin:
# Pixel size in microns
pixelSize = 0.58
# Output directory of the MicroMorph.ijm script as a string
morphologyWD = "/Microglial Morphology/Output"
# Vector of strings identifying the names of the animals images were captured
# from and matching the names of the Animal level folders
animalIDs = c('HIPP5', 'HIPP6', 'HIPP7')
# Vector of strings identifying different treatments and matching the names
# of the Treatment level folders
treatmentIDs = c('Pre-LPS', 'Post-LPS')
# Optional:
# Boolean indicating whether to use the output of the FracLac plugin
useFrac = TRUE
# String vector of mask sizes to exclude from the preprocessing function, can also take NULL
TCSExclude = NULL
# Alternatively:
# TCSExclude = c(400, 500, 600)
To avoid having to manually input the animal and treatment IDs, users can use the getAnimalAndTreatmentIDs() function to return a list, the only input is:
- imageStorageDirectory: the file path to the ‘Image Storage
directory’ that users used with the Fiji plugin, passed as a string
- String
- e.g. ‘Image Storage Directory/’
The function returns a list with two elements:
- treatmentIDs: a string vector of treatment IDs
- animalIDs: a string vector of animal IDs
These can be passed directly to the treatmentIDs and animalIDs arguments in morphPreProcessing().
Here we’re using a path to the ‘Image Storage Directory’ in the example data found at our Fiji example data directory as our input argument imageStorageDirectory.
# e.g.
# imageStorageDirectory = '/Users/Downloads/Image Storage Directory/'
idList = getAnimalAndTreatmentIDs(imageStorageDirectory)
treatmentIDs = idList$treatmentIDs
animalIDs = idList$animalIDs
idList
## $treatmentIDs
## [1] "HFD21"
##
## $animalIDs
## [1] "CE1L"
Here we’re using a path to the ‘Working Directory/Output’ in the example data found at our Fiji example data directory as our morphologyWD argument. The value for pixelSize was specified earlier as 0.58, as was the value for useFrac. The animalIDs and treatmentIDs values are being passed from the output of getAnimalAndTreatmentIDs as demonstrated in the cell above.
output =
morphPreProcessing(
pixelSize = pixelSize, morphologyWD = morphologyWD,
animalIDs = animalIDs, treatmentIDs = treatmentIDs,
useFrac = useFrac)
The returned value, output, is a data.table object. This data.table is a table that combines all the measurements taken by our Fiji plugin. The columns in the output table are:
- Animal: animal ID
- String
- These values match the values in the animalIDs input
- Treatment: treatment ID
- String
- These values match the values in the treatmentIDs input
- TCSValue: The mask size value this row’s metrics relate to
- Integer
- UniqueID: is a unique identifier for each row (a combination of
animal, treatment, mask size, and name of the mask file)
- String
- CellNo: (second to last column) is an identifier for each cell
that is duplicated if a cell has measurements taken at multiple
TCSValue levels.
- Integer
All other columns are morphological metrics, e.g. CellSpread. Below is a print out of the first 10 rows of our output table ordered by Animal, then CellNo, then TCSValue.
Note here that some rows have identical measurements. This can occur when automated cell segmentation creates the same mask for a given cell across multiple TCSValue values. This is a result of the cell segmentation converging on a certain threshold to use for segmentation. This is intended behaviour.
head(output[order(Animal,CellNo, TCSValue)], 10)
## Animal Treatment TCSValue
## 1: CE1L HFD21 300
## 2: CE1L HFD21 400
## 3: CE1L HFD21 500
## 4: CE1L HFD21 600
## 5: CE1L HFD21 700
## 6: CE1L HFD21 800
## 7: CE1L HFD21 200
## 8: CE1L HFD21 300
## 9: CE1L HFD21 400
## 10: CE1L HFD21 500
## UniqueID
## 1: ce1lhfd21300candidate mask for 10-20 x 17828 y 433108 tif
## 2: ce1lhfd21400candidate mask for 10-20 x 17828 y 433108 tif
## 3: ce1lhfd21500candidate mask for 10-20 x 17828 y 433108 tif
## 4: ce1lhfd21600candidate mask for 10-20 x 17828 y 433108 tif
## 5: ce1lhfd21700candidate mask for 10-20 x 17828 y 433108 tif
## 6: ce1lhfd21800candidate mask for 10-20 x 17828 y 433108 tif
## 7: ce1lhfd21200candidate mask for 10-20 x 228978 y 298356 tif
## 8: ce1lhfd21300candidate mask for 10-20 x 228978 y 298356 tif
## 9: ce1lhfd21400candidate mask for 10-20 x 228978 y 298356 tif
## 10: ce1lhfd21500candidate mask for 10-20 x 228978 y 298356 tif
## CellParametersPerimeter CellSpread Eccentricity Roundness SomaSize MaskSize
## 1: 337.5485 24.0163 2.1762 0.03985 27.9212 361.2940
## 2: 337.5485 24.0163 2.1762 0.03985 27.9212 361.2940
## 3: 337.5485 24.0163 2.1762 0.03985 27.9212 361.2940
## 4: 337.5485 24.0163 2.1762 0.03985 27.9212 361.2940
## 5: 337.5485 24.0163 2.1762 0.03985 27.9212 361.2940
## 6: 337.5485 24.0163 2.1762 0.03985 27.9212 361.2940
## 7: 85.4561 8.9277 1.3486 0.19510 20.1840 113.3669
## 8: 245.3896 17.0824 1.4252 0.06564 20.1840 314.5343
## 9: 245.3896 17.0824 1.4252 0.06564 20.1840 314.5343
## 10: 245.3896 17.0824 1.4252 0.06564 20.1840 314.5343
## #Branches #Junctions #End-pointvoxels #Junctionvoxels #Slabvoxels
## 1: 35 15 20 41 191
## 2: 35 15 20 41 191
## 3: 35 15 20 41 191
## 4: 35 15 20 41 191
## 5: 35 15 20 41 191
## 6: 35 15 20 41 191
## 7: 10 4 7 9 50
## 8: 30 13 17 39 149
## 9: 30 13 17 39 149
## 10: 30 13 17 39 149
## AverageBranchLength #Triplepoints #Quadruplepoints MaximumBranchLength
## 1: 5.0535 11 3 13.4753
## 2: 5.0535 11 3 13.4753
## 3: 5.0535 11 3 13.4753
## 4: 5.0535 11 3 13.4753
## 5: 5.0535 11 3 13.4753
## 6: 5.0535 11 3 13.4753
## 7: 4.6581 3 1 7.9210
## 8: 4.8348 10 2 13.2817
## 9: 4.8348 10 2 13.2817
## 10: 4.8348 10 2 13.2817
## LongestShortestPath SkelArea CriticalValue EnclosingRadius
## 1: 73.4044 84.7729 2.277565e+00 34.10392
## 2: 73.4044 84.7729 2.277565e+00 34.10392
## 3: 73.4044 84.7729 2.277565e+00 34.10392
## 4: 73.4044 84.7729 2.277565e+00 34.10392
## 5: 73.4044 84.7729 2.277565e+00 34.10392
## 6: 73.4044 84.7729 2.277565e+00 34.10392
## 7: 22.6403 22.2024 1.690778e+14 14.46011
## 8: 63.5910 68.9621 NA 20.84011
## 9: 63.5910 68.9621 NA 20.84011
## 10: 63.5910 68.9621 NA 20.84011
## MaximumNumberofIntersections Skewness(sampled)
## 1: 7 -0.2103932
## 2: 7 -0.2103932
## 3: 7 -0.2103932
## 4: 7 -0.2103932
## 5: 7 -0.2103932
## 6: 7 -0.2103932
## 7: 3 -0.2937964
## 8: 8 0.2661271
## 9: 8 0.2661271
## 10: 8 0.2661271
## RegressionIntercept(Semi-log)[P10-P90] RegressionCoefficient(semi-log)
## 1: -1.913573 -0.1819827
## 2: -1.913573 -0.1819827
## 3: -1.913573 -0.1819827
## 4: -1.913573 -0.1819827
## 5: -1.913573 -0.1819827
## 6: -1.913573 -0.1819827
## 7: -2.617455 -0.2387706
## 8: -2.127898 -0.1902941
## 9: -2.127898 -0.1902941
## 10: -2.127898 -0.1902941
## MeanValue RegressionIntercept(semi-log) RamificationIndex(fit)
## 1: 3.720781 -2.206013 6.595027
## 2: 3.720781 -2.206013 6.595027
## 3: 3.720781 -2.206013 6.595027
## 4: 3.720781 -2.206013 6.595027
## 5: 3.720781 -2.206013 6.595027
## 6: 3.720781 -2.206013 6.595027
## 7: 2.142856 -2.528711 3.160871
## 8: NA -2.271791 NA
## 9: NA -2.271791 NA
## 10: NA -2.271791 NA
## Kurtosis(sampled) PolynomialDegree IntersectingRadii CentroidRadius
## 1: -1.5171886 27 54 18.733908
## 2: -1.5171886 27 54 18.733908
## 3: -1.5171886 27 54 18.733908
## 4: -1.5171886 27 54 18.733908
## 5: -1.5171886 27 54 18.733908
## 6: -1.5171886 27 54 18.733908
## 7: -1.5878508 14 21 8.660103
## 8: -0.4671162 NA 32 11.850105
## 9: -0.4671162 NA 32 11.850105
## 10: -0.4671162 NA 32 11.850105
## RegressionCoefficient(Log-log)[P10-P90] MaxIntersectionRadius
## 1: -3.008099 10.323904
## 2: -3.008099 10.323904
## 3: -3.008099 10.323904
## 4: -3.008099 10.323904
## 5: -3.008099 10.323904
## 6: -3.008099 10.323904
## 7: -1.689856 4.600101
## 8: -1.889429 12.140105
## 9: -1.889429 12.140105
## 10: -1.889429 12.140105
## PrimaryBranches MedianofIntersections
## 1: 1 4.5
## 2: 1 4.5
## 3: 1 4.5
## 4: 1 4.5
## 5: 1 4.5
## 6: 1 4.5
## 7: 1 2.0
## 8: 1 4.0
## 9: 1 4.0
## 10: 1 4.0
## RegressionCoefficient(semi-log)[P10-P90] RegressionIntercept(Log-log)
## 1: -0.1957838 1.3719607
## 2: -0.1957838 1.3719607
## 3: -0.1957838 1.3719607
## 4: -0.1957838 1.3719607
## 5: -0.1957838 1.3719607
## 6: -0.1957838 1.3719607
## 7: -0.2254427 -0.9958107
## 8: -0.1971739 -0.5304139
## 9: -0.1971739 -0.5304139
## 10: -0.1971739 -0.5304139
## RamificationIndex(sampled) RegressionIntercept(Log-log)[P10-P90]
## 1: 7 2.94181923
## 2: 7 2.94181923
## 3: 7 2.94181923
## 4: 7 2.94181923
## 5: 7 2.94181923
## 6: 7 2.94181923
## 7: 3 -1.03891847
## 8: 8 0.04722433
## 9: 8 0.04722433
## 10: 8 0.04722433
## RegressionCoefficient(Log-log) SumofIntersections Kurtosis(fit)
## 1: -2.517894 201 -1.568975
## 2: -2.517894 201 -1.568975
## 3: -2.517894 201 -1.568975
## 4: -2.517894 201 -1.568975
## 5: -2.517894 201 -1.568975
## 6: -2.517894 201 -1.568975
## 7: -1.747633 45 -1.579314
## 8: -1.705895 134 NA
## 9: -1.705895 134 NA
## 10: -1.705895 134 NA
## CentroidValue CriticalRadius MeanofIntersections
## 1: 3.722222 28.33172 3.722222
## 2: 3.722222 28.33172 3.722222
## 3: 3.722222 28.33172 3.722222
## 4: 3.722222 28.33172 3.722222
## 5: 3.722222 28.33172 3.722222
## 6: 3.722222 28.33172 3.722222
## 7: 2.142857 17.58189 2.142857
## 8: 4.187500 NA 4.187500
## 9: 4.187500 NA 4.187500
## 10: 4.187500 NA 4.187500
## Density=ForegroundPixels/HullArea SpanRatio(major/minoraxis)
## 1: 0.1044186 1.9135
## 2: 0.1044186 1.9135
## 3: 0.1044186 1.9135
## 4: 0.1044186 1.9135
## 5: 0.1044186 1.9135
## 6: 0.1044186 1.9135
## 7: 0.2076261 1.1423
## 8: 0.1452239 1.2212
## 9: 0.1452239 1.2212
## 10: 0.1452239 1.2212
## MaximumSpanAcrossHull Area HullandCircularityPerimeter Circularity
## 1: 55.68302 1163.9440 141.15982 0.7340
## 2: 55.68302 1163.9440 141.15982 0.7340
## 3: 55.68302 1163.9440 141.15982 0.7340
## 4: 55.68302 1163.9440 141.15982 0.7340
## 5: 55.68302 1163.9440 141.15982 0.7340
## 6: 55.68302 1163.9440 141.15982 0.7340
## 7: 17.40969 183.6744 51.09591 0.8841
## 8: 35.39902 728.6424 101.58770 0.8872
## 9: 35.39902 728.6424 101.58770 0.8872
## 10: 35.39902 728.6424 101.58770 0.8872
## MaximumRadiusfromHull'sCentreofMass Max/MinRadii CVforallRadii MeanRadius
## 1: 33.89595 2.4700 0.2527 23.80326
## 2: 33.89595 2.4700 0.2527 23.80326
## 3: 33.89595 2.4700 0.2527 23.80326
## 4: 33.89595 2.4700 0.2527 23.80326
## 5: 33.89595 2.4700 0.2527 23.80326
## 6: 33.89595 2.4700 0.2527 23.80326
## 7: 10.68870 1.6847 0.1519 8.46742
## 8: 18.94524 1.3895 0.1094 16.52756
## 9: 18.94524 1.3895 0.1094 16.52756
## 10: 18.94524 1.3895 0.1094 16.52756
## DiameterofBoundingCircle MaximumRadiusfromCircle'sCentre
## 1: 56.34538 28.172688
## 2: 56.34538 28.172688
## 3: 56.34538 28.172688
## 4: 56.34538 28.172688
## 5: 56.34538 28.172688
## 6: 56.34538 28.172688
## 7: 17.67962 8.839838
## 8: 36.40996 18.204982
## 9: 36.40996 18.204982
## 10: 36.40996 18.204982
## Max/MinRadiifromCircle'sCentre CVforallRadiifromCircle'sCentre
## 1: 1.4317 0.1286
## 2: 1.4317 0.1286
## 3: 1.4317 0.1286
## 4: 1.4317 0.1286
## 5: 1.4317 0.1286
## 6: 1.4317 0.1286
## 7: 1.1591 0.0488
## 8: 1.3701 0.0985
## 9: 1.3701 0.0985
## 10: 1.3701 0.0985
## MeanRadiusfromCircle'sCentre FractalDimension Lacunarity CellNo
## 1: 25.461014 1.3991 0.6822 1
## 2: 25.461014 1.3991 0.6822 1
## 3: 25.461014 1.3991 0.6822 1
## 4: 25.461014 1.3991 0.6822 1
## 5: 25.461014 1.3991 0.6822 1
## 6: 25.461014 1.3991 0.6822 1
## 7: 8.485574 1.3704 0.5695 2
## 8: 16.707074 1.4293 0.5832 2
## 9: 16.707074 1.4293 0.5832 2
## 10: 16.707074 1.4293 0.5832 2
## BranchingDensity
## 1: 0.07283246
## 2: 0.07283246
## 3: 0.07283246
## 4: 0.07283246
## 5: 0.07283246
## 6: 0.07283246
## 7: 0.12087912
## 8: 0.09464464
## 9: 0.09464464
## 10: 0.09464464
Once users have an output from the morphPreProcessing() function, descibed in detail in Step #1, they can use this to generate an Inflammation Index based on training conditions using the constructInfInd() function. This function takes one required arguments:
- procDat: this is the filtered data.table output by the
morphPreProcessing() function that is limited to your positive
control / training conditions in the ‘Treatment’ column
- This table should have two unique values in the ‘Treatment’ column.
- This table should have multiple ‘TCSValue’ values as the function compares TCS value against one another to pick the value that provides the best morphological discrimination between training conditions.
- We will be filtering the Example morphPreProcessing() Function Output to match these requirements for our example code.
For the following examples we’re going to run this function on the Example morphPreProcessing() Function Output. It’s worth noting that this data was processed with a legacy version of the Fiji plugin, and also collated with a legacy version of the morphPreProcessing function. In addition, it doesn’t have any FracLac data included. However, it has the same structure as the data that is output by the current version of this function and can still be used for all the functions we’re demonstrating here.
We’re not running the examples on the data we extracted using morphPreProcessing() in Step #1 as that example data only covers a single animal at a single treatment level.
Here we use the fread function to read in a .csv file as a data.table - our pathToExampleData argument is just a string that is the path to where we’ve downloaded the Example morphPreProcessing() Function Output. Note that this string must include the name of the file you’ve saved e.g. ‘Users/Test/Downloads/ExampleData.csv’.
# Read in our example data
output = fread(pathToExampleData)
# Show that this data has the same format as the output of morphPreProcessing()
head(output)
## TCSValue Animal Treatment
## 1: 800 BT1R D49
## 2: 500 HIPP17 D30
## 3: 500 CE1L D2HOURS
## 4: 800 WICKET D14
## 5: 800 BT1R D3
## 6: 500 BU2L D1
## UniqueID Perimeter CellSpread
## 1: BT1RD49CANDIDATEMASKFORSUBSTACK(21-30)X100Y159800 444.190 27.598
## 2: HIPP17D30CANDIDATEMASKFORSUBSTACK(21-30)X100Y249500 327.259 24.864
## 3: CE1LD2HOURSCANDIDATEMASKFORSUBSTACK(21-30)X100Y348500 263.188 21.937
## 4: WICKETD14CANDIDATEMASKFORSUBSTACK(21-30)X100Y375800 480.572 30.771
## 5: BT1RD3CANDIDATEMASKFORSUBSTACK(21-30)X100Y380800 402.979 23.340
## 6: BU2LD1CANDIDATEMASKFORSUBSTACK(21-30)X100Y61500 381.371 24.091
## Eccentricity Roundness SomaSize MaskSize #Branches #Junctions
## 1: 1.783 0.041 47.432 637.478 59 29
## 2: 1.758 0.053 51.133 450.776 32 15
## 3: 1.632 0.067 37.004 372.058 29 13
## 4: 1.411 0.034 38.350 631.759 54 25
## 5: 1.991 0.050 31.622 646.224 61 32
## 6: 1.233 0.049 66.271 562.461 42 19
## #End-pointvoxels #Junctionvoxels #Slabvoxels AverageBranchLength
## 1: 23 55 301 4.565
## 2: 17 31 214 5.555
## 3: 17 33 165 5.103
## 4: 28 54 320 5.232
## 5: 15 55 330 4.674
## 6: 22 37 261 5.225
## #Triplepoints #Quadruplepoints MaximumBranchLength LongestShortestPath
## 1: 21 8 16.902 89.368
## 2: 13 2 20.424 71.090
## 3: 12 0 12.618 61.586
## 4: 22 1 17.043 106.993
## 5: 21 11 15.403 126.398
## 6: 15 3 18.062 72.768
## SkelArea Ibranches(inferred) Intersectingradii Suminters. Meaninters.
## 1: 127.496 1 65 250 3.85
## 2: 88.137 2 45 182 4.04
## 3: 72.326 1 46 157 3.41
## 4: 135.233 1 61 285 4.67
## 5: 134.560 1 58 240 4.14
## 6: 107.648 1 45 235 5.22
## Medianinters. Skewness(sampled) Kurtosis(sampled) Maxinters.
## 1: 4.0 -0.0006346 -1.12 8
## 2: 4.0 0.5800000 -0.10 10
## 3: 3.5 0.4500000 -0.40 8
## 4: 5.0 0.0900000 -0.69 9
## 5: 2.0 0.7100000 -1.01 11
## 6: 5.0 0.2700000 -0.99 12
## Maxinters.radius Ramificationindex(sampled) Centroidradius Centroidvalue
## 1: 15.49 8 26.53 4.77
## 2: 12.73 5 18.51 5.31
## 3: 10.39 8 20.45 4.78
## 4: 11.03 9 42.67 9.08
## 5: 14.19 11 18.91 4.45
## 6: 13.87 12 15.93 5.43
## Enclosingradius Criticalvalue Criticalradius Meanvalue
## 1: 41.01 6.04 15.45 3.88
## 2: 29.55 7.27 13.45 4.10
## 3: 29.53 5.62 10.04 3.47
## 4: 38.29 7.34 10.10 4.73
## 5: 36.23 9.47 13.75 4.19
## 6: 30.11 10.24 13.29 5.31
## Ramificationindex(fit) Skewness(fit) Kurtosis(fit) Polyn.degree
## 1: 6.04 -0.16 -1.53 7
## 2: 3.64 0.16 -1.20 7
## 3: 5.62 0.05 -1.24 8
## 4: 7.34 -0.18 -0.99 8
## 5: 9.47 0.52 -1.34 8
## 6: 10.24 0.13 -1.30 7
## Regressioncoefficient(Semi-log) Regressionintercept(Semi-log)
## 1: 0.15 -2.60
## 2: 0.18 -2.21
## 3: 0.18 -2.41
## 4: 0.13 -2.72
## 5: 0.17 -2.36
## 6: 0.18 -2.17
## Regressioncoefficient(Semi-log)[P10-P90]
## 1: 0.16
## 2: 0.18
## 3: 0.19
## 4: 0.15
## 5: 0.20
## 6: 0.19
## Regressionintercept(Semi-log)[P10-P90] Regressioncoefficient(Log-log)
## 1: -2.34 2.48
## 2: -2.14 2.40
## 3: -2.24 2.27
## 4: -2.37 2.09
## 5: -1.79 2.39
## 6: -1.77 2.30
## Regressionintercept(Log-log) Regressioncoefficient(Log-log)[P10-P90]
## 1: 1.44 3.02
## 2: 1.14 2.60
## 3: 0.67 2.64
## 4: 0.54 2.73
## 5: 1.02 3.16
## 6: 1.04 2.73
## Regressionintercept(Log-log)[P10-P90] CellNo
## 1: 3.19 4083
## 2: 1.91 1
## 3: 1.87 2
## 4: 2.54 4084
## 5: 3.46 4085
## 6: 2.55 3
In order to construct an inflammation index from this data, we need to subset out the rows that correspond to our positive control conditions. Here we’re specifying these conditions in the vector LPSGroups that we then used to filter our output object (which is just this Example morphPreProcessing() Function Output).
# A string vector indicating the treatment labels that ID our training data
LPSGroups = c('D56', 'LPS')
# The output of the morphPreProcessing() function filtered to only include our
# training data
inDat = output[Treatment %in% LPSGroups]
# Show our filtered data
head(inDat[order(Animal, Treatment, UniqueID)],10)
## TCSValue Animal Treatment UniqueID
## 1: 200 BR1R D56 BR1RD56CANDIDATEMASKFORSUBSTACK(21-30)X148Y164200
## 2: 300 BR1R D56 BR1RD56CANDIDATEMASKFORSUBSTACK(21-30)X148Y164300
## 3: 400 BR1R D56 BR1RD56CANDIDATEMASKFORSUBSTACK(21-30)X148Y164400
## 4: 500 BR1R D56 BR1RD56CANDIDATEMASKFORSUBSTACK(21-30)X148Y164500
## 5: 600 BR1R D56 BR1RD56CANDIDATEMASKFORSUBSTACK(21-30)X148Y164600
## 6: 700 BR1R D56 BR1RD56CANDIDATEMASKFORSUBSTACK(21-30)X148Y164700
## 7: 800 BR1R D56 BR1RD56CANDIDATEMASKFORSUBSTACK(21-30)X148Y164800
## 8: 200 BR1R D56 BR1RD56CANDIDATEMASKFORSUBSTACK(21-30)X150Y28200
## 9: 200 BR1R D56 BR1RD56CANDIDATEMASKFORSUBSTACK(21-30)X167Y466200
## 10: 300 BR1R D56 BR1RD56CANDIDATEMASKFORSUBSTACK(21-30)X167Y466300
## Perimeter CellSpread Eccentricity Roundness SomaSize MaskSize #Branches
## 1: 183.415 17.194 1.803 0.112 59.206 298.723 19
## 2: 157.929 16.749 1.969 0.114 59.206 225.388 13
## 3: 183.415 17.194 1.803 0.112 59.206 298.723 19
## 4: 183.415 17.194 1.803 0.112 59.206 298.723 19
## 5: 218.603 22.235 1.523 0.100 59.206 380.132 23
## 6: 218.603 22.235 1.523 0.100 59.206 380.132 23
## 7: 404.420 26.811 1.636 0.052 59.206 679.864 40
## 8: 95.100 9.659 1.451 0.163 32.967 117.067 8
## 9: 73.036 8.609 1.217 0.262 45.414 111.012 7
## 10: 96.658 10.065 1.237 0.228 45.414 169.209 16
## #Junctions #End-pointvoxels #Junctionvoxels #Slabvoxels AverageBranchLength
## 1: 9 11 13 118 5.113
## 2: 6 8 14 101 6.293
## 3: 9 11 13 118 5.113
## 4: 9 11 13 118 5.113
## 5: 10 13 23 158 5.932
## 6: 10 13 23 158 5.932
## 7: 18 23 41 284 6.094
## 8: 3 6 9 60 6.626
## 9: 3 5 7 40 4.981
## 10: 7 10 14 58 3.485
## #Triplepoints #Quadruplepoints MaximumBranchLength LongestShortestPath
## 1: 9 0 13.903 50.608
## 2: 6 0 13.903 45.786
## 3: 9 0 13.903 50.608
## 4: 9 0 13.903 50.608
## 5: 7 3 17.524 55.488
## 6: 7 3 17.524 55.488
## 7: 15 3 23.365 103.333
## 8: 2 1 14.582 32.686
## 9: 3 0 11.202 25.884
## 10: 6 1 7.138 27.761
## SkelArea Ibranches(inferred) Intersectingradii Suminters. Meaninters.
## 1: 47.769 3 40 109 2.73
## 2: 41.377 3 39 98 2.51
## 3: 47.769 3 40 109 2.73
## 4: 47.769 3 40 109 2.73
## 5: 65.262 3 42 142 3.38
## 6: 65.262 3 42 142 3.38
## 7: 117.067 2 62 248 4.00
## 8: 25.230 1 22 58 2.64
## 9: 17.493 4 13 40 3.08
## 10: 27.585 4 18 56 3.11
## Medianinters. Skewness(sampled) Kurtosis(sampled) Maxinters.
## 1: 3 0.54 -1.10 6
## 2: 2 0.34 -1.22 5
## 3: 3 0.54 -1.10 6
## 4: 3 0.54 -1.10 6
## 5: 3 -0.02 -1.49 6
## 6: 3 -0.02 -1.49 6
## 7: 3 0.53 -0.67 10
## 8: 2 0.56 -0.78 6
## 9: 3 -0.46 -0.50 5
## 10: 3 -0.22 -0.09 5
## Maxinters.radius Ramificationindex(sampled) Centroidradius Centroidvalue
## 1: 7.82 2.00 13.77 2.41
## 2: 8.98 1.67 14.07 2.28
## 3: 7.82 2.00 13.77 2.41
## 4: 7.82 2.00 13.77 2.41
## 5: 7.82 2.00 -13.35 -4.57
## 6: 7.82 2.00 -13.35 -4.57
## 7: 17.10 5.00 25.10 5.39
## 8: 5.56 6.00 9.31 3.04
## 9: 9.60 1.25 5.28 2.14
## 10: 6.70 1.25 10.92 3.40
## Enclosingradius Criticalvalue Criticalradius Meanvalue
## 1: 26.96 5.44 9.46 2.74
## 2: 26.38 4.62 8.88 2.53
## 3: 26.96 5.44 9.46 2.74
## 4: 26.96 5.44 9.46 2.74
## 5: 28.12 5.57 9.01 3.43
## 6: 28.12 5.57 9.01 3.43
## 7: 39.72 7.33 14.57 4.04
## 8: 15.42 5.04 5.39 2.73
## 9: 10.76 4.36 9.05 3.12
## 10: 13.66 4.17 3.80 3.14
## Ramificationindex(fit) Skewness(fit) Kurtosis(fit) Polyn.degree
## 1: 1.81 0.32 -1.54 8
## 2: 1.54 0.21 -1.52 8
## 3: 1.81 0.32 -1.54 8
## 4: 1.81 0.32 -1.54 8
## 5: 1.86 -0.48 -1.22 8
## 6: 1.86 -0.48 -1.22 8
## 7: 3.66 0.36 -1.18 8
## 8: 5.04 0.45 -1.30 8
## 9: 1.09 -0.76 -0.37 8
## 10: 1.04 -1.37 2.05 8
## Regressioncoefficient(Semi-log) Regressionintercept(Semi-log)
## 1: 0.24 -1.92
## 2: 0.23 -2.04
## 3: 0.24 -1.92
## 4: 0.24 -1.92
## 5: 0.22 -1.97
## 6: 0.22 -1.97
## 7: 0.15 -2.61
## 8: 0.34 -1.45
## 9: 0.42 -0.97
## 10: 0.33 -1.43
## Regressioncoefficient(Semi-log)[P10-P90]
## 1: 0.27
## 2: 0.25
## 3: 0.27
## 4: 0.27
## 5: 0.24
## 6: 0.24
## 7: 0.16
## 8: 0.42
## 9: 0.27
## 10: 0.29
## Regressionintercept(Semi-log)[P10-P90] Regressioncoefficient(Log-log)
## 1: -1.57 3.15
## 2: -1.85 3.03
## 3: -1.57 3.15
## 4: -1.57 3.15
## 5: -1.54 2.85
## 6: -1.54 2.85
## 7: -2.40 2.48
## 8: -0.77 2.72
## 9: -1.88 2.79
## 10: -1.71 2.57
## Regressionintercept(Log-log) Regressioncoefficient(Log-log)[P10-P90]
## 1: 2.63 3.72
## 2: 2.29 3.37
## 3: 2.63 3.72
## 4: 2.63 3.72
## 5: 2.14 3.43
## 6: 2.14 3.43
## 7: 1.49 2.96
## 8: 1.20 3.50
## 9: 1.42 1.92
## 10: 1.12 2.32
## Regressionintercept(Log-log)[P10-P90] CellNo
## 1: 4.25 5994
## 2: 3.28 5994
## 3: 4.25 5994
## 4: 4.25 5994
## 5: 3.82 5994
## 6: 3.82 5994
## 7: 3.09 5994
## 8: 2.95 5996
## 9: -0.10 6002
## 10: 0.67 6002
We can now pass this filtered table object to our constructInfInd() function as the procDat argument. Again, the constructInfInd() function takes as inputs:
One required arguments:
- procDat: this is the filtered data.table output by the
morphPreProcessing() function that is limited to your positive
control / training conditions in the ‘Treatment’ column
- This table should have two unique values in the ‘Treatment’ column.
- This table should have multiple ‘TCSValue’ values as the function compares TCS value against one another to pick the value that provides the best morphological discrimination between training conditions.
And four optional argument:
- method: this is a string identifying which method users want to
use to optimise the Inflammation Index
- String
- ‘p value’ uses the smallest p value
- ‘AUC’ uses a ROC-AUC analysis
- Defaults to ‘AUC’
- noDesc: this is an integer vector of the number of ‘best’
descriptors to compare to one another
- Integer vector
- e.g. c(5,6,7,8)
- Defaults to 5:15 (this ‘:’ notation is another way of constructing an integer vector like c(5,6,7…14,15))
- labCols: this is a string vector containing the names of
non-metric columns that defaults to the identifier columns provided
by morphPreProcessing():
- String vector
- e.g. c(‘Animal’, ‘Treatment’, ‘TCSValue’, ‘UniqueID’, ‘CellNo’)
- Defaults to c(Animal, Treatment, TCSValue, UniqueID, CellNo)
- correlationCutoff: this is a decimal value that indicates the
threshold at which highly correlated metrics will be dropped e.g a
value of 0.9 means if two metrics correlate at this value or above,
the worst performing one will be dropped from consideration
- Double
- e.g. 0.56
- Defaults to 0.9
The function returns a list containing:
- PCA
- A PCA object, trained to be discriminate between the training conditions
- Metrics Correlation
- A correlation matrix of the metrics included in the PCA so users can see what was used, and how they relate
- Optimal TCS
- The TCS value identified as optimal for detecting differences in morphology between training conditions
In addition when executed the constructInfInd() function will print out the mask size (i.e. TCSValue) and number of descriptors that created the inflammation index that was most sensitive to the differences in morphology between the positive control conditions according to the method passed in the method argument (e.g. p value or AUC). It will also print the discriminators that were retained after cleaning (removing variants of the same metrics, removing highly correlated metrics) and these are the ones included in the index. Finally, it prints the value (AUC or p value) of the index’s ability to discriminate between training conditions.
infIndOut =
constructInfInd(procDat = inDat)
## [1] "Best TCS 500"
## [1] "Best No. Discriminators (Pre Cleaning): 5"
## [1] "Discriminators chosen (Post Cleaning): MaskSize, #Slabvoxels, Criticalradius"
## [1] "AUC 0.741221374045801"
Here we can also look at the Metrics Correlations returned list element. This may also be of interest to users.
infIndOut$`Metric Correlations`
## MaskSize #Slabvoxels Criticalradius
## MaskSize 1.0000000 0.8478799 0.5107622
## #Slabvoxels 0.8478799 1.0000000 0.4253839
## Criticalradius 0.5107622 0.4253839 1.0000000
Having produced an output from the constructInfInd() function, i.e., having generated an inflammation index optimised to detect morphological differences between their specified training conditions, users can use the applyInfInd() function to generate that inflammation index for novel data using the PCA object output by constructInfInd().
This simply requires that the novel dataset have is the same metrics that were available in the training dataset, and that the data collected in the novel dataset was collected at the identified optimal TCS value. This value is printed during executing of the constructInfInd() function, and is also found in the Optimal TCS element of the list output by that function.
Here we are simply going to generate our inflammation for the rest of
our output data (the Example morphPreProcessing() Function
Output
treatment conditions that weren’t included in the LPSGroups vector we
used to filter the data in order to generate our inflammation index). To
do this, we filter that data so it only contains rows that match the
$Optimal TCS
value, and rows that containt Treatment values that
aren’t in the LPSGroups vector.
outputToApplyTo = output[TCSValue == infIndOut$`Optimal TCS` & !(Treatment %in% LPSGroups)]
Now we apply our inflammation index to this data. The applyInfInd() function:
Takes two required arguments:
- infIndOutput: A PCA object output by the constructInfInd() function (this is held in the $PCA element returned from the constructInfInd() function)
- applyTo: A data.table object that contains the same columns as
the data.table that constructInfInd() was run on. It must also
contain rows with a TCSValue of the same value as the $
Optimal TCS
element returned from the list output by the constructInfInd() function.
The function returns:
- A data.table that is a copy of the input data.table passed in applyTo, except with an extra column ‘InfInd’ added, which contains the inflammation index value for each row in the dataset.
dataWithInfIndex = applyInfInd(infIndOut$PCA, outputToApplyTo[TCSValue == infIndOut$`Optimal TCS`])
Here we can see our output has had its inflammation index calculated and added:
head(dataWithInfIndex[, list(Animal, Treatment, TCSValue, CellNo, InfInd)])
## Animal Treatment TCSValue CellNo InfInd
## 1: HIPP17 D30 500 1 0.9762437
## 2: CE1L D2HOURS 500 2 -0.4894777
## 3: BU2L D1 500 3 2.0586940
## 4: BG1L D7 500 4 -1.4928852
## 5: HIPP12 D4HOURS 500 5 -1.4916847
## 6: BR1R D-1 500 6 -1.0283423
If you want to save this table, use the fwrite function:
fwrite(dataWithInfIndex,'Users/Test/Downloads/InfIndData.csv')
Now that you are familiar with how to use this R package, you can train and calculate an inflammation index for your own data. You can compare this index between groups using statistical tests to evaluate if a difference in morphology exists.