DHowett / qlbreader

"qlb reader" :P
0 stars 0 forks source link

Compensation #1

Closed seaaan closed 7 years ago

seaaan commented 7 years ago

There is overlap between channels 1 and 2 which needs to be manually subtracted, a process called "compensation". This can be seen in these plots:

ggplot(amplitude, aes(x = Ch1.Amplitude)) + geom_density() + ggtitle("Reference")
ggplot(result, aes(x = ch1h)) + geom_density()  + ggtitle("Derived")

ggplot(amplitude, aes(x = Ch2.Amplitude)) + geom_density() + xlim(c(0, 1E4)) + ggtitle("Reference")
ggplot(result, aes(x = ch2h)) + geom_density() + xlim(c(0, 1E4)) + ggtitle("Derived")

ggplot(amplitude, aes(x = Ch2.Amplitude, y = Ch1.Amplitude)) + geom_point() + ggtitle("Reference")
ggplot(result, aes(x = ch2h, y = ch1h)) + geom_point() + ggtitle("Derived")

Somewhere in the header is probably the magic numbers for the subtraction between the two channels. These numbers will differ between the files that have FAM and HEX vs. the files that have FAM and VIC, which might help us to find them. Otherwise we can reverse engineer them.

seaaan commented 7 years ago

ch1 - 0.375 * ch2 works pretty well for fam hex, no need for ch2 - ch1

seaaan commented 7 years ago

look what I found in Quantasoft > About:

Plate Color Compensation Matrix (FAM/VIC): 1.176431 -0.3418835 -1.124906 1.866206 Plate Color Compensation Matrix (FAM/HEX): 1.034385 -0.3602588 -0.394962 1.962357 Plate Color Compensation Matrix (EVA): 1.034385 -0.3602588 -0.394962 1.962357

Scaled Plate Color Compensation Matrix (FAM/VIC): 1.341881 -0.4155075 -1.204653 2.108128 Scaled Plate Color Compensation Matrix (FAM/HEX): 1.186966 -0.4539033 -0.4459926 2.267218 Scaled Plate Color Compensation Matrix (EVA): 1.186966 -0.4539033 -0.4459926 2.267218

seaaan commented 7 years ago

This is instrument-specfic, must be stored in the .qlp or .qlb files

DHowett commented 7 years ago

Looks like it's stored in the qlb file after the Ch1,Ch2\0 header:

          Ch1 |       Ch2
Ch1  1.176431 | -0.341884
Ch2 -1.124906 |  1.866206

          Ch1 |       Ch2
Ch1  1.176431 | -0.341884
Ch2 -1.124906 |  1.866206

          Ch1 |       Ch2
Ch1  1.034385 | -0.360259
Ch2 -0.394962 |  1.962357

          Ch1 |       Ch2
Ch1  1.034385 | -0.360259
Ch2 -0.394962 |  1.962357

It looks like the first comp matrix in the file is the one being used, and the other three are the static/per-instrument values.

seaaan commented 7 years ago

I'm embarrassingly bad at solving systems of equations and have repeatedly gotten the solution wrong for uncompensating compensated data, so here is the solution in code so I don't mess it up in the future.

a <- 1.034385 
b <- -0.3602588
c <- -0.394962 
d <- 1.962357

x <- plate_data(data) %>% 
   mutate(UncompensatedFam = (FAM / a - b * HEX / (d * a)) / (1 - b * c / (d * a)), 
      UncompensatedHex = (HEX - c * UncompensatedFam) / d, 
      RecompensatedFam = a * UncompensatedFam + b * UncompensatedHex, 
      RecompensatedHex = -0.5 * UncompensatedFam + d * UncompensatedHex)