SydneyBioX / spicyR

https://sydneybiox.github.io/spicyR/
8 stars 4 forks source link

New error when running `spicy` #34

Closed nilseling closed 10 months ago

nilseling commented 10 months ago

Hi all,

since the updates from yesterday, I'm encountering a new error when executing spicy:

spicyTest <- spicy(
  all_sce,
  condition = "modality",
  subject = "sample_id",
  spatialCoords = c("Pos_X", "Pos_Y"),
  window = "square",
  cellType = "matched_celltype",
  imageID = "sample_id_global",
  Rs = c(20, 50, 100, 150)
)

results in

There is no cellID. I'll create these

There is no image specific imageCellID. I'll create these

Testing for spatial differences across conditions accounting for multiple images per subject
Error in `[.data.frame`(as.data.frame(imagePheno(cells)), imageID) : 
  undefined columns selected

based on:

> colData(all_sce)
DataFrame with 197657 rows and 7 columns
                    sample_id  patient_id matched_celltype     Pos_X     Pos_Y    modality       sample_id_global
                  <character> <character>      <character> <numeric> <numeric> <character>            <character>
1      IMMUcan_2022_WFLOW_1..    10061074            Tumor 213.40000  0.600000         IMC IMMUcan_2022_WFLOW_1..
2      IMMUcan_2022_WFLOW_1..    10061074       Neutrophil   7.45455  1.045455         IMC IMMUcan_2022_WFLOW_1..
3      IMMUcan_2022_WFLOW_1..    10061074            Tumor 327.79167  0.791667         IMC IMMUcan_2022_WFLOW_1..
4      IMMUcan_2022_WFLOW_1..    10061074            Tumor 383.44828  1.206897         IMC IMMUcan_2022_WFLOW_1..
5      IMMUcan_2022_WFLOW_1..    10061074                T 501.00000  0.625000         IMC IMMUcan_2022_WFLOW_1..
...                       ...         ...              ...       ...       ...         ...                    ...
197653 IMMUcan_Batch2021092..    10082495              BnT   25.3062  119.0880         mIF IMMUcan_Batch2021092..
197654 IMMUcan_Batch2021092..    10082495              BnT  391.9980  337.9122         mIF IMMUcan_Batch2021092..
197655 IMMUcan_Batch2021092..    10082495              BnT  340.3932  464.9394         mIF IMMUcan_Batch2021092..
197656 IMMUcan_Batch2021092..    10082495            Tumor   83.3616  332.4540         mIF IMMUcan_Batch2021092..
197657 IMMUcan_Batch2021092..    10082495            other   10.9164   16.3746         mIF IMMUcan_Batch2021092..

With the release version of spicyR the function does not produce an error, it only occurs with spicyR v1.15.1.

nilseling commented 10 months ago

I'd like to reopen this issue as there has been an additional error when executing the signifPlot function after the change.

Using the same call as above with version 1.15.3 when executing signifPlot(spicyTest) results in

Error in data.frame(cellTypeA = c(NA, NA), cellTypeB = c(NA, NA), size = c(1,  : 
  arguments imply differing number of rows: 2, 0

Unfortunately, I cannot reproduce this with the provided example data. But also this call worked before the recent changes.

nick-robo commented 10 months ago

I think this is caused by the condition column in the SCE (modality) not being a factor.

Could you check if it works if you convert it into a factor?

The first level of the factor is treated as the base group for the creation of the linear models.

nilseling commented 10 months ago

Thanks, that fixed the issue. However, the little half-circles are gone from the plot and depending on the levels of the factor c("IMC", "mIF") or c("mIF", "IMC") I get the following plots:

image

or

image

So just to really know the directionality of the results it would be good to add the circles back.

nilseling commented 10 months ago

Ah, and previously there was an entry spicyTest$dataframe which was quite convenient to figure out which subjects had the strongest change in the L function. This seems to be gone now, right?

nick-robo commented 10 months ago

We have created a function to replace spicyTest$dataframe.

bind(spicyTest)[1:5,1:5]
  imageID     condition subject ductal__ductal acinar__ductal
1     P15 Long-duration    6089       3.982313      -2.539548
2     Q06 Long-duration    6089       4.541734      -5.750083
3     Q20 Long-duration    6089      12.380665       2.605501
4     P36 Long-duration    6089      26.392357       5.224948
5     P34 Long-duration    6089      12.958183      -4.590799

In regard to the circle, we can't seem to replicate the issue. The top entry in the legend should be the left circle.