Skip to content

Commit

Permalink
✨ handle catigorical data
Browse files Browse the repository at this point in the history
  • Loading branch information
Wytamma committed Jul 7, 2023
1 parent 218ab0c commit 6a20f4f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
15 changes: 10 additions & 5 deletions backend/beastiary/api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,16 @@ def lines_to_SampleCreate(
data = {}
line = line.strip() # strip \n
for header, value in zip(headers, line.split(delimiter)):
value = float(value)
if value.is_integer():
value = int(value)
elif math.isnan(value) or math.isinf(value):
value = None
try:
value = float(value)
if value.is_integer():
value = int(value)
elif math.isnan(value) or math.isinf(value):
value = None
except ValueError:
# value is not a number
# treat as categorical
logger.debug(f"Value is not a number: {value}")
data[header] = value
sample_in = {}
sample_in["data"] = data
Expand Down
10 changes: 10 additions & 0 deletions backend/tests/data/jumping.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Sample posterior likelihood prior treeLikelihood.updated_aln76 treeHeight.t:updated_aln76 treeLength.t:updated_aln76 Tree.t:updated_aln76.count_type0_to_type1 Tree.t:updated_aln76.count_type1_to_type0 Tree.t:updated_aln76.count_type0 Tree.t:updated_aln76.count_type1 rootTypeLogger.t:updated_aln76 R0.t:updated_aln76.1 R0.t:updated_aln76.2 samplingProportion.t:updated_aln76.1 samplingProportion.t:updated_aln76.2 samplingProportion.t:updated_aln76.3 samplingProportion.t:updated_aln76.4 rateMatrix.t:updated_aln76.1 rateMatrix.t:updated_aln76.2 geo-frequencies.t:updated_aln76.1 geo-frequencies.t:updated_aln76.2 clockRate.c:updated_aln76 gammaShape.s:updated_aln76 kappa.s:updated_aln76 freqParameter.s:updated_aln76.1 freqParameter.s:updated_aln76.2 freqParameter.s:updated_aln76.3 freqParameter.s:updated_aln76.4 Tree.t:updated_aln76.GetTypeChanges
0 -41333.75971284343 -40734.51379958226 -599.2459132611716 -40734.51379958226 6.923434373151229 33.0132421625962 17 16 82 17 1 2.0 2.0 0.0 0.01 0.0 0.01 0.1 0.1 0.5 0.5 9.0E-4 1.0 2.0 0.25 0.25 0.25 0.25 0 9_5 0
1000 -38551.95529369084 -38321.410769514296 -230.54452417654153 -38321.410769514296 3.4813017751360102 77.39835273735575 18 11 75 24 0 11.191851819003919 10.751059471143009 0.0 0.01378259446660518 0.0 0.016439561188787387 0.03385265105256901 0.04212268562474381 0.5838715861164372 0.41612841388356286 9.0E-4 1.0 2.0 0.25 0.25 0.25 0.25 0 12_13 0
2000 -37806.5335154905 -37664.794951461845 -141.73856402865133 -37664.794951461845 2.492211350510883 78.2722894485813 20 10 73 26 1 13.318544178753282 10.793720878442507 0.0 0.019047014222626658 0.0 0.010216644370878259 0.06244368855427064 0.05744194329618179 0.598532732581924 0.40146726741807615 9.0E-4 1.0 2.0 0.25 0.25 0.25 0.25 0 19_19 0
3000 -37265.55710548536 -37184.04763492051 -81.50947056484355 -37184.04763492051 1.7510212385218977 69.70215200583725 18 15 79 20 0 13.959095875169004 11.346246040509724 0.0 0.03149553800147499 0.0 0.011567381328671822 0.09153519223651532 0.06054242114193841 0.5405112559126798 0.45948874408732027 9.0E-4 1.0 2.0 0.25 0.25 0.25 0.25 0 24_24 0
4000 -37039.0562530545 -37001.856592234064 -37.19966082043219 -37001.856592234064 1.6669757298439463 67.96313753575224 14 13 81 18 0 13.638246099325276 13.526934021394027 0.0 0.046071824649735464 0.0 0.013180438335592064 0.10992616577549225 0.08135437126155767 0.6769289777618196 0.3230710222381804 9.0E-4 1.0 2.0 0.25 0.25 0.25 0.25 0 11_8 0
5000 -36771.89749383548 -36746.022367087964 -25.87512674751925 -36746.022367087964 1.7074971161817503 67.68712120684698 11 11 82 17 0 14.363300326843035 13.415749919134266 0.0 0.05019017122119998 0.0 0.012550661083166645 0.1201975222797158 0.13898266943209373 0.6596700760439751 0.34032992395602485 9.0E-4 1.0 2.0 0.25 0.25 0.25 0.25 0 23_23 0
6000 -36355.66204452353 -36346.81551356546 -8.846530958072025 -36346.81551356546 1.5552549629143344 63.94436092655659 7 11 86 13 0 13.985881832110238 13.664954103109945 0.0 0.05619953122768195 0.0 0.015354996647925855 0.17390817012964535 0.13011493133467242 0.7476152154517764 0.25238478454822344 9.0E-4 0.5113428395081505 2.0 0.25 0.25 0.25 0.25 0 22_22 0
7000 -36153.369535529986 -36144.50033045471 -8.869205075272143 -36144.50033045471 1.5538483105584278 65.30835217491838 11 12 83 16 0 13.042243780723615 12.8237952245519 0.0 0.08170188816747899 0.0 0.01512007350339032 0.2624161026093499 0.20843693863223514 0.6728927812064905 0.3271072187935094 9.0E-4 0.5113428395081505 2.0 0.25 0.25 0.25 0.25 0 22_23 0
8000 -35849.46683438652 -35848.3779549682 -1.0888794183205581 -35848.3779549682 1.5066140842781008 62.72899793790548 10 15 87 12 0 13.506280804534299 12.716960120895367 0.0 0.08866723719051095 0.0 0.0203000218136345 0.21993066718530616 0.2954599228150545 0.6728927812064905 0.3271072187935094 9.0E-4 0.24308998662756756 2.0 0.25 0.25 0.25 0.25 0 11_10 0

0 comments on commit 6a20f4f

Please sign in to comment.