RGLab / flowWorkspace

flowWorkspace
GNU Affero General Public License v3.0
45 stars 21 forks source link

Problems Reading Spectral Flow FCS Files #317

Closed DillonHammill closed 4 years ago

DillonHammill commented 4 years ago

Hi @mikejiang & @jacobpwagner,

Sorry to bug you, I know that you are very busy!

I am having some issues reading in some spectral flow FCS files and I was hoping that you may have a solution.

I am able to load the files into a cytoset successfully using load_cytoset_from_fcs but get an error when trying to extract a cytoframe.

cs[[1]]
Error in string_to_spill(txt) : 
  bad lexical cast: source type value could not be interpreted as target

Here is the traceback:

11: stop(list(message = "bad lexical cast: source type value could not be interpreted as target", 
        call = string_to_spill(txt), cppstack = NULL))
10: string_to_spill(txt)
9: flowCore:::txt2spillmatrix(sp)
8: process_spill_keyword(desc)
7: .local(object, ...)
6: keyword(fr)
5: keyword(fr)
4: cytoframe_to_flowFrame(fr)
3: .local(x, i, j, ...)
2: cs[[1]]
1: cs[[1]]

It looks like it is related to the spill keyword? Not all files seem to be affected, I have attached a couple of problematic ones and one that works.

Problematic FCS Files.zip

OK FCS Files.zip

Appreciate your help!

Dillon

jacobpwagner commented 4 years ago

Not bugging at all. Thanks for bringing this to our attention. I found the issue. It looks like the C++ parser isn't handling the extra padding whitespaces in the $SPILLOVER value for the "bad" FCS files.

$SPILLOVER/22,B1-A,B2-A,B3-A,B4-A,B5-A,B6-A,B7-A,B8-A,B9-A,B10-A,B11-A,B12-A,B13-A,B14-A,R1-A,R2-A,R3-A,R4-A,R5-A,R6-A,R7-A,R8-A,                1,                0,                0,

I'll update the parser to handle those like as.numeric was doing in the R parser here: https://github.com/RGLab/flowCore/blob/38f42215a8fc5692e04b4da7e095ae4bee1a6b6e/R/IO.R#L415 And I'll ping you when the fix is ready.

jacobpwagner commented 4 years ago

@DillonHammill , https://github.com/RGLab/cytolib/commit/2108e3c9038cfd8a4bb0623727a1fc38db529dd1 should fix it. Please pull and rebuild cytolib and flowCore. I don't think you'll need to rebuild flowWorkspace for this one because the change is handled by flowCore::text2spillmatrix: https://github.com/RGLab/flowWorkspace/blob/86fdb21985ea5c75f032ce443cb0ee600f9f5366/R/cytoframe.R#L493-L502

DillonHammill commented 4 years ago

Thanks @jacobpwagner!

I am also having trouble updating the parameter names:

colnames(cs) <- colnames(cs)
Error in set_all_channels(x@pointer, value) : 
  bad lexical cast: source type value could not be interpreted as target

Traceback:

6: stop(list(message = "bad lexical cast: source type value could not be interpreted as target", 
       call = set_all_channels(x@pointer, value), cppstack = NULL))
5: set_all_channels(x@pointer, value)
4: `colnames<-`(`*tmp*`, value = value)
3: `colnames<-`(`*tmp*`, value = value)
2: `colnames<-`(`*tmp*`, value = c("Time", "FSC-H", "FSC-A", "SSC-H", 
   "SSC-A", "B1-A", "B2-A", "B3-A", "B4-A", "B5-A", "B6-A", "B7-A", 
   "B8-A", "B9-A", "B10-A", "B11-A", "B12-A", "B13-A", "B14-A", 
   "R1-A", "R2-A", "R3-A", "R4-A", "R5-A", "R6-A", "R7-A", "R8-A"
   ))
1: `colnames<-`(`*tmp*`, value = c("Time", "FSC-H", "FSC-A", "SSC-H", 
   "SSC-A", "B1-A", "B2-A", "B3-A", "B4-A", "B5-A", "B6-A", "B7-A", 
   "B8-A", "B9-A", "B10-A", "B11-A", "B12-A", "B13-A", "B14-A", 
   "R1-A", "R2-A", "R3-A", "R4-A", "R5-A", "R6-A", "R7-A", "R8-A"
   ))
jacobpwagner commented 4 years ago

Hmm. Can you give an example with the files you attached? Or others? I can't seem to reproduce this. This is successful for me after fixing the spillover parse issue:

> library(flowWorkspace)
> bad_files <- list.files("...Problematic FCS Files/", full.names = TRUE)
> cs <- load_cytoset_from_fcs(bad_files)
> colnames(cs) <- colnames(cs)
> colnames(cs)
 [1] "Time"  "FSC-H" "FSC-A" "SSC-H" "SSC-A" "B1-A"  "B2-A"  "B3-A"  "B4-A"  "B5-A"  "B6-A"  "B7-A"  "B8-A"  "B9-A"  "B10-A" "B11-A" "B12-A" "B13-A" "B14-A" "R1-A"  "R2-A"  "R3-A"  "R4-A" 
[24] "R5-A"  "R6-A"  "R7-A"  "R8-A" 

Also, maybe try rebuilding flowWorkspace too and if that still doesn't work attach a sessionInfo() just to see if this is a version mismatch issue. There have been lots of updates recently. In the meantime I'll keep trying to reproduce this.

DillonHammill commented 4 years ago

@jacobpwagner, I just read in the problematic files and tried to update the colnames (as above).

I am away from my computer for a couple of hours, I will try re-building flowWorkspace to see if that works.

DillonHammill commented 4 years ago

@jacobpwagner, this works with the latest flowWorkspace. Thanks for your help!