# %% from collections import defaultdict import altair as alt import matplotlib.pyplot as plt import pandas as pd from cmap import Colormap import polars as pl #%% df = pl.read_csv("example_data_bk.csv") df.columns df_crop = df[:, :3] df_crop df_crop.write_csv("example_data.csv") #%% # %% kwargs = {"comment": "#", "header": [0, 1], "index_col": 0} df = pd.read_csv("fit_result_batch.csv", **kwargs) # %% df # %% df_wt = df["SecB WT apo"].reset_index() df_dimer = df["SecB his dimer apo"].reset_index() AA_categories = { "pos": ["R", "H", "K"], "neg": ["D", "E"], "aromatic": ["F", "W", "Y"], "polar": ["S", "T", "N", "Q"], "nonpolar": ["A", "V", "I", "L", "M"], "other": ["G", "C", "P"], } cat_list = list(AA_categories) AA_lut = {aa: category for category in AA_categories for aa in AA_categories[category]} AA_lut aa_cat_numbers = [cat_list.index(AA_lut[aa]) for aa in df_wt["sequence"]] df_wt["aa_cat"] = aa_cat_numbers # %% cmap = Colormap("colorbrewer:Accent_6") sol = defaultdict(list) colors = cmap(df_wt["aa_cat"]) nums = range(6) colors = cmap(nums) for n, c in zip(nums, colors): print(n, c) # %% len(cmap.color_stops) colors = cmap.to_altair(N=cmap.num_colors) domain = range(6) altair_scale = alt.Scale(domain=domain, range=colors, clamp=True) # %% alt.Chart(df_wt).mark_point().encode( x="r_number", y="aa_cat", color=alt.Color("aa_cat:N", scale=altair_scale), ) # %% import pandas as pd df = pd.DataFrame({"a": [1, 2, 3, 4], "b": [7, 6, 5, 4], "c": ["a", "b", "b", "c"]}) chart = alt.Chart(df).mark_point().encode(alt.X("a"), alt.Y("b"), alt.Color("c:N")) chart # %% # %% ddG = df_wt["deltaG"] - df_dimer["deltaG"] ddG # %% fig, ax = plt.subplots() ax.scatter(df_wt["r_number"], df_wt["deltaG"]) # %% fig, ax = plt.subplots() ax.scatter(df_wt["r_number"], ddG) # %% df_wt.columns # %% output = pd.DataFrame( { "r_number": df_wt["r_number"], "SecB tetramer ΔG": df_wt["deltaG"], "dimer ΔΔG": ddG, "aa_category": df_wt["aa_cat"], } ) output = output.set_index("r_number") output # %% import numpy as np N = 150 fuzzy_sin = 0.5 * (1 + np.sin(np.arange(N) / 10.0)) + np.random.normal( loc=0, scale=0.1, size=N ) df = pd.DataFrame({"fuzzy_sin": fuzzy_sin}) df # add series to output dataframe a a column output["fuzzy_sin"] = series output # %% output.to_csv("SecB_data.csv") # %% dir(cmap) cmap.category # %% tol_cmap = Colormap("tol:rainbow_discrete_7") tol_cmap.category tol_cmap.num_colors tol_cmap.interpolation # %% tol_cmap = Colormap("vispy:hsl") tol_cmap.category tol_cmap.num_colors tol_cmap.interpolation # %% tol_cmap = Colormap("yorick:stern") tol_cmap.category tol_cmap.num_colors tol_cmap.interpolation # %% tol_cmap = Colormap("tol:rainbow_whbr") tol_cmap.category tol_cmap.num_colors tol_cmap.interpolation # %% tol_cmap = Colormap("glasbey:glasbey") tol_cmap.category tol_cmap.num_colors # tol_cmap.interpolation # %%