Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export to "flareplot" #122

Open
cbouy opened this issue Apr 21, 2023 · 0 comments
Open

Export to "flareplot" #122

cbouy opened this issue Apr 21, 2023 · 0 comments
Labels
visualization Visualization

Comments

@cbouy
Copy link
Member

cbouy commented Apr 21, 2023

See GPCRviz/flareplot

Add a to_flareplot option to Fingerprint.

Script used for RDKit UGM poster to visualize difference in interactions between active and inactive PDB structures:

import json

jdict = {
    "edges": [],
    "trees": [{
        "treeLabel": "TMs",
        "treeProperties": []
    }],
    "tracks": [{
        "trackLabel": "TMs",
        "trackProperties": []
    }],
    "defaults": {
        "width": 2,
        "edgeOpacity": .85
    }
}
TM_COLORS = {
    "TM1": "#ccebc5",
    "TM2": "#e8ce85", #"#ffffb3",
    "TM3": "#bebada",
    "TM4": "#fb8072",
    "TM5": "#80b1d3",
    "TM6": "#bc80bd",
    "TM7": "#b3de69",
    "H8": "#fccde5",
}
EDGE_COLORS = {
    1: "#66c2a5",
    -1: "#fc8d62",
    0: "#a9a9a9"
}

def get_name(res):
    resid = plf.ResidueId.from_string(res)
    aa = mda.lib.util.inverse_aa_codes[resid.name]
    return f"{aa}{resid.number}"

# add nodes
residues = sorted(set([
    plf.ResidueId.from_string(r)
    for i in data.index.values
    for r in i
]))

for resid in residues:
    res = str(resid)
    resid = plf.ResidueId.from_string(res)
    info = get_opsd_info(resid.number)
    domain = info["Label"]
    color = TM_COLORS.get(domain, False)
    if color is False:
        continue
    name = get_name(res)
    jdict["trees"][0]["treeProperties"].append({
        "path": f"{domain}.{name}", "key": f"{resid.number}"
    })
    jdict["tracks"][0]["trackProperties"].append({
        "nodeName": name, "color": color, "size": .5
    })

done = set()
for (lres, pres), value in data.iteritems():
    color = EDGE_COLORS[value]
    key = frozenset([lres, pres])
    if key in done:
        continue
    done.add(key)
    jdict["edges"].append(
        {"name1": get_name(lres), "name2": get_name(pres), "frames": [0], "color": color}
    )

with open("flareplot.json", "w") as fh:
    json.dump(jdict, fh, indent=2)
@cbouy cbouy added the visualization Visualization label Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
visualization Visualization
Projects
None yet
Development

No branches or pull requests

1 participant