Landscape projection

This does surface interpolation to generate a VR landscape
# This ensures Plotly output works in multiple places:
# plotly_mimetype: VS Code notebook UI
# notebook: "Jupyter: Export to HTML" command in VS Code
# See https://plotly.com/python/renderers/#multiple-renderers
pio.renderers.default = "plotly_mimetype+notebook"
base_dir = os.path.dirname(sys.path[0])
data_dir = f"{base_dir}/data/output"
with open(f"{data_dir}/param_dict.json", "r") as param_json:
    param_dict = json.load(param_json)
param_dict
{'input_csv': 'md_QinCardoso23.csv',
 'dim_names': ['phate1', 'phate2'],
 'potency': 'CCAT',
 'dynamic': 'inverse_vvl',
 'cluster': 'curatedCLUST',
 'cluster_colours': {'TA 1': '#FF99CC',
  'Goblet / DCS': '#CC9900',
  'Late Enterocyte': '#006600',
  'proCSC': '#000099',
  'Early Enterocyte': '#00FF99',
  'revCSC': '#CC0000',
  'ER Stress': '#CC00FF',
  'CSC': '#6666FF',
  'TA 2': '#FF6666'},
 'condition': 'condition',
 'scores_csv': 'vr_QinCardoso23.csv'}
score_data = pd.read_csv(f"{data_dir}/{param_dict['scores_csv']}")
score_data
phate1 phate2 CCAT velocity_length A K P WENR mac fib ... OWNsig_stemS_UCell condition inverse_vvl dist deg dist_scaled inv_deg_scaled potency_med dynamic_med VR
0 -0.003110 -0.003080 0.339365 186.242097 0 0 0 0 0 0 ... 0.221648 WT 0.147660 0.006520 8 0.095761 0.312500 0.418507 0.062690 0.377256
1 0.024983 0.029213 0.217284 152.058837 0 0 0 0 0 0 ... 0.122389 WT 0.231605 0.017569 6 0.059681 0.666667 0.249275 0.113152 0.225022
2 0.037142 0.007396 0.102314 164.789267 0 0 0 0 0 0 ... 0.155778 WT 0.196273 0.019348 6 0.226228 0.714286 0.220369 0.189912 0.202629
3 -0.021990 0.000884 0.592517 221.681973 0 0 0 0 0 0 ... 0.085037 WT 0.087964 0.008693 5 0.095699 1.000000 0.680724 0.069009 0.613312
4 0.041909 0.035762 0.207627 208.885837 0 0 0 0 0 0 ... 0.058852 WT 0.107182 0.047344 5 0.920014 1.000000 0.220369 0.189912 0.215805
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
5896 -0.003300 -0.006133 0.598417 197.806256 0 0 0 1 0 0 ... 0.337778 WENR 0.125830 0.005085 5 0.009114 1.000000 0.690199 0.098587 0.621269
5897 -0.028562 0.010894 0.842009 145.233683 0 0 0 1 0 0 ... 0.256611 WENR 0.253098 0.008261 5 0.080657 1.000000 0.779294 0.210717 0.703064
5898 -0.002911 -0.009425 0.689346 188.500721 0 0 0 1 0 0 ... 0.283296 WENR 0.143186 0.007716 5 0.129462 1.000000 0.724684 0.164599 0.654346
5899 -0.024535 0.002836 0.838003 114.664223 0 0 0 1 0 0 ... 0.203278 WENR 0.380759 0.007152 6 0.042140 0.694444 0.779294 0.210717 0.702252
5900 -0.013252 0.004670 0.815766 191.966684 0 0 0 1 0 0 ... 0.388148 WENR 0.136525 0.015421 7 0.749223 0.510204 0.696763 0.105690 0.635005

5901 rows × 22 columns


source

generate_grid

 generate_grid (dataframe, param_dict, auto=True, nticks=48, d1min=None,
                d1max=None, d1tick=None, d2min=None, d2max=None,
                d2tick=None)
param_dict = generate_grid(score_data, param_dict, auto=True)
Automated grid computation
Added grids to parameter dictionary

Eventually, setting condition to None in param_dict will signify that vr scores are computed on the whole dataset.

For now though, we assume that they are always computed on a per sample/condition basis, and thus several landscapes need to be generated.


source

interpolate_landscape

 interpolate_landscape (dataframe, param_dict, trim=True)
param_dict
{'input_csv': 'md_QinCardoso23.csv',
 'dim_names': ['phate1', 'phate2'],
 'potency': 'CCAT',
 'dynamic': 'inverse_vvl',
 'cluster': 'curatedCLUST',
 'cluster_colours': {'TA 1': '#FF99CC',
  'Goblet / DCS': '#CC9900',
  'Late Enterocyte': '#006600',
  'proCSC': '#000099',
  'Early Enterocyte': '#00FF99',
  'revCSC': '#CC0000',
  'ER Stress': '#CC00FF',
  'CSC': '#6666FF',
  'TA 2': '#FF6666'},
 'condition': 'condition',
 'scores_csv': 'vr_QinCardoso23.csv',
 'grids': array([[[-0.03413235, -0.03413235, -0.03413235, ..., -0.03413235,
          -0.03413235, -0.03413235],
         [-0.03262914, -0.03262914, -0.03262914, ..., -0.03262914,
          -0.03262914, -0.03262914],
         [-0.03112593, -0.03112593, -0.03112593, ..., -0.03112593,
          -0.03112593, -0.03112593],
         ...,
         [ 0.04253158,  0.04253158,  0.04253158, ...,  0.04253158,
           0.04253158,  0.04253158],
         [ 0.04403479,  0.04403479,  0.04403479, ...,  0.04403479,
           0.04403479,  0.04403479],
         [ 0.045538  ,  0.045538  ,  0.045538  , ...,  0.045538  ,
           0.045538  ,  0.045538  ]],
 
        [[-0.0224318 , -0.0212241 , -0.02001639, ...,  0.03916118,
           0.04036889,  0.04157659],
         [-0.0224318 , -0.0212241 , -0.02001639, ...,  0.03916118,
           0.04036889,  0.04157659],
         [-0.0224318 , -0.0212241 , -0.02001639, ...,  0.03916118,
           0.04036889,  0.04157659],
         ...,
         [-0.0224318 , -0.0212241 , -0.02001639, ...,  0.03916118,
           0.04036889,  0.04157659],
         [-0.0224318 , -0.0212241 , -0.02001639, ...,  0.03916118,
           0.04036889,  0.04157659],
         [-0.0224318 , -0.0212241 , -0.02001639, ...,  0.03916118,
           0.04036889,  0.04157659]]])}
# Colour and axes scales should be set globally here
vr_max = round(score_data["VR"].max(),2)+0.02
vr_min = round(score_data["VR"].min(),2)-0.02

for i in score_data[param_dict["condition"]].unique():
    print(i)
    land_data = score_data.loc[score_data[param_dict["condition"]]==i]
    print(land_data.shape)

    vr_land = interpolate_landscape(land_data, param_dict)

    fig = go.Figure(
            data=[go.Surface(
                x=param_dict["grids"][0],y=param_dict["grids"][1],z=vr_land
            )])
    fig.update_traces(colorscale=[[0,"blue"],[0.25,"green"],[0.5,"yellow"],[0.75,"#5f3316"],[0.85,"#513b1b"],[1,"white"]],cmax=vr_max, cmin=vr_min)
    fig.add_scatter3d(
        x=land_data[param_dict["dim_names"][0]],
        y=land_data[param_dict["dim_names"][1]], 
        z=((0.1*land_data[param_dict["potency"]]+0.9*land_data["VR"])+0.012),
        mode="markers",
        marker=dict(
            size=4, 
            color=land_data[param_dict["cluster"]].map(param_dict["cluster_colours"]),
            opacity=0.42,
            # line=dict(width=2,
            #     color="darkgrey")
            )
        )
    fig.update_layout(
        title=None,
        template = "simple_white",
        scene = dict(
            xaxis = dict(nticks=5,title=""),
            yaxis = dict(nticks=5, title = ""),
            zaxis = dict(nticks=5, range=[vr_min,vr_max], title="")
            ),
        autosize=True,
        width=1000, height=1000,
        margin=dict(l=0, r=0, b=0, t=0),
        scene_aspectmode="cube",
        scene_camera=dict(
            up=dict(x=0, y=0, z=1),
            center=dict(x=0, y=0, z=0),
            eye=dict(x=1.5, y=1, z=2)
        )
        )
    fig.show()
WT
(1511, 22)
CRC
(1860, 22)
WTfib
(1139, 22)
WENR
(1391, 22)

source

foo

 foo ()
# test_eq(say_hi("Jeremy"), "Hi Jeremy!")