NBISweden / encam

Encyclopedia of Cancer Microenvironment
http://encima.one
2 stars 2 forks source link

survival endpoint can return Infinity in JSON (not valid JSON) #77

Closed danr closed 4 years ago

danr commented 4 years ago

Fun quirk of JSON: the Javascript-valid double values Infinity and NaN are not expressible as JSON... And here's an invocation that returns Infinity:

curl 'http://localhost:8080/api/survival'  -H 'Content-type: application/json' --data-binary '{"clinical_stage":["I","II","III","IV"],"pT_stage":["T1","T2","T3","T4"],"pN_stage":["N1","N2"],"pM_stage":["M1"],"Diff_grade":["low","missing"],"Neuralinv":["No","Yes","missing"],"Vascinv":["No","Yes","missing"],"PreOp_treatment_yesno":["Yes"],"PostOp_type_treatment":["no"],"Anatomical_location":{"COAD":["Appendix","Ascendens","Caecum","Descendens","Flexura hepatica","Flexura lienalis","Rectum","Sigmoideum","Transversum"],"READ":["Appendix","Rectum"]},"Morphological_type":{"COAD":["mucinon-mucinousus","non-mucinous","missing"],"READ":["mucinon-mucinousus","non-mucinous","missing"]},"MSI_ARTUR":{"COAD":["MSI","MSS"],"READ":["MSI","MSS"]},"cells":["CD4"],"tumors":["BRCA"],"cell":"CD4","cell_full":"CD4_TUMOR","group_sizes":[1,2],"num_groups":2}'   --compressed

returns

  "cox_regression": {
    "coef": 18423250.158871397,
    "lower": 0,
    "p": 0.9961913233971302,
    "upper": Infinity
  },
  "log_rank": {
    "p_logrank": 0.22525290636064954,
    "test_statistic_logrank": 1.4705882352941184
  },
  "points": [
    {
      "fit": 1,
      "group": 1,
      "lower": 1,
      "time": 0,
      "upper": 1
    },
    {
      "fit": 0,
      "group": 1,
      "lower": 0,
      "time": 126,
      "upper": 0
    },
    {
      "fit": 1,
      "group": 2,
      "lower": 1,
      "time": 0,
      "upper": 1
    },
    {
      "fit": 0.5,
      "group": 2,
      "lower": 0.005983087639145737,
      "time": 13,
      "upper": 0.9104100848367374
    },
    {
      "fit": 0,
      "group": 2,
      "lower": 0,
      "time": 47,
      "upper": 0
    }
  ]
}

Possible fix: replace Infinity with max double 1.7976931348623157e+308

danr commented 4 years ago

Ok thinking about it just a few seconds more, it's a bit silly to set a probability to max double :P Perhaps better to set it to 1.0.

dbampalikis commented 4 years ago

Yes, I think that makes more sense to use 1.0 and 0 for Infinity and -Infinity respectively. I am thinking of implementing it only for the cox regression for now. Sounds good?

danr commented 4 years ago

Sounds good!