### Install BioMakie.jl Source: https://context7.com/biojulia/biomakie.jl/llms.txt Install the BioMakie package from the Julia package manager. ```julia add BioMakie ``` -------------------------------- ### Full Example: Plotting Protein Structure and OpenAI Integration Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/dbinfo.md This comprehensive example integrates protein structure plotting with OpenAI API for dynamic text generation. Ensure your OpenAI API key is set in the environment variable 'APIKEY'. ```julia using BioMakie using BioStructures using GLMakie using OrderedCollections using JSON3 using OpenAI using TextWrap pdb = retrievepdb("2vb1") pdata = plottingdata(pdb) dat = getuniprotdata("P00698"; include_refs = true) txtbuffer = IOBuffer() uniprottxt = begin BioMakie.showsummary(txtbuffer, dat); String(take!(txtbuffer)) end fig = Figure(size = (900, 700)) layout = fig[1,1] = GridLayout(10, 9) plotstruc!(layout[1:10,1:5], pdata; size = (600, 700)) ENV["APIKEY"] = "{Your API key}" # Need to set your API key here! model = "gpt-3.5-turbo" txt = Observable("") tbox = Textbox(layout[4,6:9]; placeholder = "Ask GPT about this protein...", width = 350) on(tbox.stored_string) do t r = create_chat( ENV["APIKEY"], model, [Dict("role" => "user", "content"=> t)] ) txt[] = wrap(r.response[:choices][begin][:message][:content]; width = 50) end ax = Axis(layout[1:3,6:9]) GLMakie.text!(ax, uniprottxt, fontsize = 16, align = (:left, :top)) xlims!(ax, (0, 1)) ylims!(ax, (-0.5, 0)) hidespines!(ax) hideydecorations!(ax) hidexdecorations!(ax) ax = Axis(layout[5:10,6:9]) GLMakie.text!(ax, txt, fontsize = 16, align = (:left, :top)) xlims!(ax, (0, 1)) ylims!(ax, (-0.5, 0)) hidespines!(ax) hideydecorations!(ax) hidexdecorations!(ax) ``` -------------------------------- ### Full MSA Plotting and Selection Example Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/msaselection.md This comprehensive example integrates MSA plotting with interactive residue selection and dynamic frequency plotting. It requires downloading Pfam data and setting up observables for real-time updates. ```julia using BioMakie using MIToS.MSA, MIToS.Pfam using GLMakie using Lazy downloadpfam("pf00062") msa1 = read_file("pf00062.stockholm.gz",Stockholm) msa2 = Observable(msa1) plotdata = plottingdata(msa2) fig = Figure(size = (1400,400)) msa = plotmsa!(fig, plotdata) coldata = lift(plotdata[:selected]) do sel try plotdata[:matrix][][:,parse(Int,sel)] catch ["-" for i in 1:size(plotdata[:matrix][])[1]] end end allaas = [ "R", "M", "N", "E", "F", "I", "D", "L", "A", "Q", "G", "C", "W", "Y", "K", "P", "T", "S", "V", "H", "X", "-"] sortaas = sortperm(allaas) new_aalabels = allaas[sortaas] hydrophobicities = [BioMakie.kideradict[new_aalabels[i]][2] for i in 1:length(new_aalabels)] countmap1 = @lift frequencies($coldata) |> sort aas = @lift collect(keys($countmap1)) freqs = lift(aas) do a collect(values(countmap1[])) end missingaas = @lift setdiff(allaas,$aas) |> sort missingfreqs = @lift zeros(length($missingaas)) perm1 = @lift sortperm([$aas; $missingaas]) aafreqs = @lift ([freqs[];$missingfreqs])[$perm1] aafreqspercent = @lift $aafreqs ./ sum($aafreqs) .* 100 new_aafreqs = @lift $aafreqspercent[sortaas] ax = Axis(fig[1,4], xticklabelsize = 16, yticks = (0:10:100), yticklabelsize = 20, title = "Amino Acid Percentages", titlesize = 18, xticks = (1:22,new_aalabels) ) bp = barplot!(ax, 1:22, aafreqspercent; color = hydrophobicities, strokewidth = 1, xtickrange=1:22, xticklabels=new_aalabels ) ylims!(ax, (0, 100)) xlims!(ax, (0, 23)) ``` -------------------------------- ### Full Protein Mutation Workflow with ProtoSyn Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/mutation.md This comprehensive example shows the entire process of loading a protein structure, preparing it for mutation, setting up the mutation interface, and applying mutations and rotamer changes. It includes UI elements for selection and mutation. ```julia using BioMakie using GLMakie using BioStructures BioMakie.getprotosyn() include("../protosyn.jl") struc = retrievepdb("2vb1") chn = collectresidues(struc[1]["A"], standardselector) writepdb("2vb1x.pdb", chn) rot_lib = ProtoSyn.Peptides.load_dunbrack() res_lib = ProtoSyn.load_grammar_from_file(ProtoSyn.resource_dir*"/Peptides/grammars.yml", "default") pose = ProtoSyn.Peptides.load("2vb1x.pdb"; bonds_by_distance=true) |> Observable ProtoSyn.Peptides.cap!(pose[]) ProtoSyn.Peptides.assign_default_atom_names!(pose[]) ProtoSyn.sort_atoms_by_graph!(pose[]) ProtoSyn.Peptides.Calculators.Electrostatics.assign_default_charges!(pose[], res_lib) pdata = plottingdata(pose) fig = Figure(size = (985,700)) layout = fig[1,1] = GridLayout(11,7) selected = @lift pdata[:resids][][$(pdata[:selected])] |> unique selection_text = lift(selected) do sel if length(sel) == 0 return "" else return "$(string(pose[].graph[1][sel[1]])) end end _plotstruc!(layout[1:10,1:5], pdata; size = (600,700)) title = Label(layout[1,6:7]; text = "Mutate Residue", fontsize = 30) selection_label = Label(layout[2,6:7]; text = "Selection:", fontsize = 20) vselection = Label(layout[3,6:7]; text = selection_text, fontsize = 16) clear_button = Button(layout[4,6:7]; label = "Clear selection", buttoncolor = :pink, fontsize = 18, width = 140, height = 50) mutation_label = Label(layout[5,6:7]; text = "Mutate selection to:", fontsize = 20) mutate_menu = Menu(layout[6,6:7]; options = BioMakie.res3letters[1:20], cell_color_active = to_color(:lightblue), cell_color_hover = to_color(:lightgreen), selection_cell_color_inactive = to_color(:lightblue) ) mutate_button = Button(layout[7,6:7]; label = "Mutate!", buttoncolor = :lightgreen, fontsize = 18, width = 80, height = 50 ) rotamer = Observable(1) rotamer_label = Label(layout[8:9,6]; text = "Change rotamer:", fontsize = 20) rotamer_button1 = Button(layout[8,7]; label = "ꜛ", buttoncolor = :lightgreen, fontsize = 40, tellwidth = false, width = 70, height = 40 ) rotamer_button2 = Button(layout[9,7]; label = "ꜜ", buttoncolor = :lightgreen, fontsize = 40, tellwidth = false, width = 70, height = 40 ) on(clear_button.clicks) do s pdata[:selected][] = Vector{Bool}(undef,length(pdata[:selected][])) .= false end on(mutate_button.clicks) do s selection_text[] = "$(string(pose[].graph[1][selected[][1]])) mutletter = BioMakie.resletterdict[mutate_menu.selection[]] ProtoSyn.Peptides.mutate!(pose[], pose[].graph[1][selected[][1]], res_lib, [mutletter]) fixpose!(pose) end on(rotamer_button1.clicks) do s if length(selected[]) == 0 println("No selection") else phi = ProtoSyn.getdihedral(pose[].state, ProtoSyn.Peptides.phi(pose[].graph[1][selected[][1]])) psi = ProtoSyn.getdihedral(pose[].state, ProtoSyn.Peptides.psi(pose[].graph[1][selected[][1]])) stack = rot_lib["$(pose[].graph[1][selected[][1]].name)"][phi, psi] nrotamers = length(stack.rotamers) if rotamer[] < nrotamers rotamer[] = rotamer[] + 1 end ProtoSyn.Peptides.apply!(pose[].state, stack[rotamer[]], pose[].graph[1][selected[][1]]) fixpose!(pose) end end on(rotamer_button2.clicks) do s if length(selected[]) == 0 println("No selection") else phi = ProtoSyn.getdihedral(pose[].state, ProtoSyn.Peptides.phi(pose[].graph[1][selected[][1]])) psi = ProtoSyn.getdihedral(pose[].state, ProtoSyn.Peptides.psi(pose[].graph[1][selected[][1]])) stack = rot_lib["$(pose[].graph[1][selected[][1]].name)"][phi, psi] nrotamers = length(stack.rotamers) if rotamer[] > nrotamers rotamer[] = rotamer[] - 1 end ProtoSyn.Peptides.apply!(pose[].state, stack[rotamer[]], pose[].graph[1][selected[][1]]) fixpose!(pose) end end ``` -------------------------------- ### Get and Plot Structure Data Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/mutation.md Generates plotting data from a ProtoSyn pose and visualizes the structure using Makie. This is useful for initial visualization and inspection. ```julia pdata = plottingdata(pose) fig = Figure() _plotstruc!(fig, pdata) ``` -------------------------------- ### Full Alpha Shape Visualization Setup Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/alphashape.md This comprehensive snippet sets up the visualization of a protein's alpha shape. It includes fetching structure data, defining sliders for alpha and atom radius, calculating sphere points and the alpha shape, computing surface area, and rendering the mesh and points using GLMakie. ```julia using BioMakie using GLMakie using GLMakie: Slider using SplitApplyCombine using GeometryBasics using Meshes using BioStructures using PyCall using Conda scipy = pyimport_conda("scipy", "scipy") np = pyimport_conda("numpy", "numpy") collections = pyimport_conda("collections", "collections") struc = retrievepdb("2vb1") chn = struc[1]["A"] |> Observable atms = collectatoms(struc, standardselector) |> Observable cords = @lift coordarray($atms)' |> collect fig = Figure(size = (800,600)) layout = fig[1,1] = GridLayout(10, 9) strucname = struc.name[1:4] sc_scene = layout[1:10,1:6] = LScene(fig; show_axis = false) structxt = layout[1,7:8] = Label(fig, text = "Structure ID: $(strucname)", fontsize = 35) alpha1 = layout[5,7:9] = Slider(fig, range = 1.5:0.5:9.0, startvalue = 2.5) alphatxt1 = lift(alpha1.value) do s1; string("alpha = ", round(s1, sigdigits = 2)); end alphatext = layout[4,7:9] = Label(fig, text = alphatxt1, fontsize = 22) alphaval = alpha1.value radii1 = layout[7,7:9] = Slider(fig, range = 1.5:0.5:9.0, startvalue = 2.5) radiixt1 = lift(radii1.value) do s1; string("atom radius = ", round(s1, sigdigits = 2)); end radiitext = layout[6,7:9] = Label(fig, text = radiixt1, fontsize = 22) radiival = radii1.value; spnts = @lift getspherepoints($cords,$radiival) proteinshape = @lift let pnts = $spnts; getalphashape(pnts,$alphaval); end alphaverts = @lift $spnts[$(proteinshape)[1],:] alphaedges = @lift $spnts[$(proteinshape)[2],:] |> linesegs function surfacearea(coordinates, connectivity) totalarea = 0.0 for i = 1:size(connectivity,1) totalarea += measure(Ngon(Meshes.Point{3,Int64}.(coordinates[connectivity[i,1],:], coordinates[connectivity[i,2],:], coordinates[connectivity[i,3],:])...)) end return totalarea end surfarea = @lift surfacearea($spnts, $(proteinshape)[3]) surfatext = layout[2,7:9] = Label(fig, text = lift(X->string("surface area = ", round(Int64, X), " Ų"), surfarea), fontsize = 22) linesegments!(sc_scene, alphaedges, color = :gray, transparency = true) meshscatter!(sc_scene, cords, markersize = 0.3, color = :blue) meshscatter!(sc_scene, alphaverts, markersize = 0.3, color = :green) ``` -------------------------------- ### Plot Multiple Sequence Alignment (FASTX FASTA) Source: https://context7.com/biojulia/biomakie.jl/llms.txt Create a standalone interactive MSA heatmap using FASTX.jl in FASTA format. This example demonstrates setting a custom colorscheme and sheet size for the alignment visualization. ```julia using FASTX reader = open(FASTX.FASTA.Reader, "PF00062_full.fasta") msa_fastx = [reader...] |> Observable close(reader) fig2 = plotmsa(msa_fastx; colorscheme = :tableau_blue_green, sheetsize = [60, 30]) ``` -------------------------------- ### Plot Multiple Sequence Alignment (FastaIO) Source: https://context7.com/biojulia/biomakie.jl/llms.txt Create a standalone interactive MSA heatmap using FastaIO.jl. This example uses the tuple format output from `readfasta` and customizes the figure size and marker color. ```julia using FastaIO msa_fio = readfasta("sequences.fasta") # Vector{Tuple{String,String}} fig3 = plotmsa(msa_fio; figsize = (1200, 400), markercolor = :white) ``` -------------------------------- ### Load and Save PDB Structure Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/mutation.md Loads a PDB structure using BioStructures, extracts a specific chain, saves it, and then loads it into ProtoSyn for further processing. Ensure BioStructures and ProtoSyn are installed. ```julia using BioStructures struc = retrievepdb("2vb1") chn = collectresidues(struc[1]["A"], standardselector) writepdb("2vb1x.pdb", chn) pose = ProtoSyn.Peptides.load("2vb1x.pdb"; bonds_by_distance=true) |> Observable ``` -------------------------------- ### Plot Protein Structure (MIToS) Source: https://context7.com/biojulia/biomakie.jl/llms.txt Create a standalone 3D protein structure visualization using MIToS.jl. This example shows plotting a structure read from a PDB file with covalent bond types and disabling water molecules. ```julia using MIToS.PDB pdbfile = MIToS.PDB.downloadpdb("2vb1", format = PDBFile) resz = MIToS.PDB.read_file(pdbfile, PDBFile) |> Observable fig5 = plotstruc(resz; bondtype = :covalent, water = false) ``` -------------------------------- ### Import Python libraries via PyCall Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/alphashape.md Imports SciPy, NumPy, and collections from Python using PyCall. Ensure these are installed in your Conda/Python environment. ```julia using PyCall using Conda scipy = pyimport("scipy") np = pyimport("numpy") collections = pyimport("collections") ``` -------------------------------- ### Load BioMakie and ProtoSyn Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/mutation.md This snippet shows how to load the BioMakie and GLMakie packages and includes the ProtoSyn source code using a workaround. This is necessary for using ProtoSyn's mutation functionalities. ```julia using BioMakie using GLMakie BioMakie.getprotosyn() include("../protosyn.jl") ``` -------------------------------- ### Set up the figure and plot structure Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/dbinfo.md Initializes a GLMakie figure and plots the protein structure onto a specified layout grid. ```julia fig = Figure(size = (900, 700)) layout = fig[1,1] = GridLayout(10, 9) fig = plotstruc!(layout[1:10,1:5], pdata; size = (600, 700)) ``` -------------------------------- ### Load Structure and Set Up Figure Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/alphashape.md Loads a PDB structure using BioStructures.jl, extracts atomic coordinates, and sets up the main figure and layout for visualization. ```julia struc = retrievepdb("2vb1") chn = struc[1]["A"] |> Observable atms = collectatoms(struc, standardselector) |> Observable cords = @lift coordarray($atms)' |> collect fig = Figure(size = (800,600)) layout = fig[1,1] = GridLayout(10, 9) ``` -------------------------------- ### Download and prepare MSA data Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/msaselection.md Downloads a Pfam MSA and prepares it for plotting using MIToS. ```julia downloadpfam("pf00062") msa1 = read_file("pf00062.stockholm.gz",Stockholm) msa2 = Observable(msa1) plotdata = plottingdata(msa2) ``` -------------------------------- ### Import necessary packages Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/dbinfo.md Imports the required libraries for BioMakie, BioStructures, GLMakie, and data handling. ```julia using BioMakie using BioStructures using GLMakie using OrderedCollections using JSON3 using OpenAI using TextWrap ``` -------------------------------- ### Configure OpenAI API and Textbox Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/dbinfo.md Sets the OpenAI API key, defines the model, and creates an interactive textbox. The `on` function updates an Observable with GPT responses when text is submitted. ```julia ENV["APIKEY"] = "{Your API key}" model = "gpt-3.5-turbo" txt = Observable("") tbox = Textbox(layout[4,6:9]; placeholder = "Ask GPT about this protein...", width = 350) on(tbox.stored_string) do t r = create_chat( ENV["APIKEY"], model, [Dict("role" => "user", "content"=> t)] ) txt[] = wrap(r.response[:choices][begin][:message][:content]; width = 50) end ``` -------------------------------- ### Import necessary Julia packages Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/alphashape.md Imports required Julia packages for BioMakie, GLMakie, SplitApplyCombine, GeometryBasics, and BioStructures. ```julia using BioMakie using GLMakie using GLMakie: Slider using SplitApplyCombine using GeometryBasics using BioStructures ``` -------------------------------- ### Retrieve and prepare protein data Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/dbinfo.md Fetches PDB data and prepares it for plotting. Also retrieves UniProt data and captures its summary. ```julia pdb = retrievepdb("2vb1") pdata = plottingdata(pdb) ``` ```julia dat = getuniprotdata("P00698"; include_refs = true) txtbuffer = IOBuffer() uniprottxt = begin BioMakie.showsummary(txtbuffer, dat); String(take!(txtbuffer)) end ``` -------------------------------- ### Import necessary packages Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/msaselection.md Imports the required libraries for MSA plotting and data manipulation. ```julia using BioMakie using MIToS.MSA, MIToS.Pfam using GLMakie using Lazy ``` -------------------------------- ### Load Rotamer Library and Apply Specific Rotamer Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/mutation.md Loads the Dunbrack rotamer library, calculates dihedral angles (phi and psi) for a residue, selects a specific rotamer from the library based on these angles, and applies it to the structure using `apply!`, followed by `fixpose!` to update the structure. This allows fine-tuning of side chain orientations. ```julia rot_lib = ProtoSyn.Peptides.load_dunbrack() phi = ProtoSyn.getdihedral(pose[].state, ProtoSyn.Peptides.phi(pose[].graph[1][128])) psi = ProtoSyn.getdihedral(pose[].state, ProtoSyn.Peptides.psi(pose[].graph[1][128])) stack = rot_lib["TYR"][phi, psi] ProtoSyn.Peptides.apply!(pose[].state, stack[3], pose[].graph[1][128]) fixpose!(pose) ``` -------------------------------- ### Create observables for dynamic data synchronization Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/msaselection.md Sets up observables to link the selected residue's data to the frequency plot, ensuring real-time updates. ```julia countmap1 = @lift frequencies($coldata) |> sort aas = @lift collect(keys($countmap1)) freqs = lift(aas) do a collect(values(countmap1[])) end missingaas = @lift setdiff(allaas,$aas) |> sort missingfreqs = @lift zeros(length($missingaas)) perm1 = @lift sortperm([$aas; $missingaas]) aafreqs = @lift ([freqs[];$missingfreqs])[$perm1] aafreqspercent = @lift $aafreqs ./ sum($aafreqs) .* 100 new_aafreqs = @lift $aafreqspercent[sortaas] ``` -------------------------------- ### Add Text and Interactive Elements Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/alphashape.md Configures the visualization scene, adds labels for structure ID and alpha values, and sets up sliders for interactive control of alpha and atom radius. ```julia strucname = struc.name[1:4] sc_scene = layout[1:10,1:6] = LScene(fig; show_axis = false) structxt = layout[1,7:8] = Label(fig, text = "Structure ID: $(strucname)", fontsize = 35) alpha1 = layout[5,7:9] = Slider(fig, range = 1.5:0.5:9.0, startvalue = 2.5) alphatxt1 = lift(alpha1.value) do s1; string("alpha = ", round(s1, sigdigits = 2)); end alphatext = layout[4,7:9] = Label(fig, text = alphatxt1, fontsize = 22) alphaval = alpha1.value radii1 = layout[7,7:9] = Slider(fig, range = 1.5:0.5:9.0, startvalue = 2.5) radiixt1 = lift(radii1.value) do s1; string("atom radius = ", round(s1, sigdigits = 2)); end radiitext = layout[6,7:9] = Label(fig, text = radiixt1, fontsize = 22) radiival = radii1.value; nothing #hide ``` -------------------------------- ### `getbonds` Source: https://context7.com/biojulia/biomakie.jl/llms.txt Computes inter-atomic bond matrices. Returns a BitMatrix where entry [i,j] == 1 if atoms i and j are bonded. Supports three algorithms: :knowledgebased, :distance, and :covalent. ```APIDOC ## `getbonds` — Compute inter-atomic bond matrices Returns a `BitMatrix` where entry `[i,j] == 1` if atoms `i` and `j` are bonded. Supports three algorithms: `:knowledgebased` (residue lookup tables), `:distance` (fixed cutoff), and `:covalent` (sum-of-covalent-radii). ```julia using BioMakie, BioStructures struc = retrievepdb("2vb1") chain = struc["A"] # Knowledge-based bonds (default, most accurate for standard residues) bmat_kb = getbonds(chain; algo = :knowledgebased, H = false, disulfides = true) # Distance-based bonds bmat_dist = getbonds(chain; algo = :distance, cutoff = 1.9) # Covalent-radius bonds bmat_cov = getbonds(chain; algo = :covalent, extradistance = 0.14, H = true) # MIToS residues using MIToS.PDB pdbfile = MIToS.PDB.downloadpdb("2vb1", format = PDBFile) resz = select_residues(MIToS.PDB.read_file(pdbfile, PDBFile), model="1", chain="A", group="ATOM") bmat_mitos = getbonds(resz; algo = :knowledgebased) # => BitMatrix of size (n_atoms × n_atoms) ``` ``` -------------------------------- ### Generate distance and contact maps using BioStructures Source: https://context7.com/biojulia/biomakie.jl/llms.txt Use `heatmap` and `heatmap!` to visualize distance and contact maps from MIToS or BioStructures objects. Requires `BioMakie`, `GLMakie`, and `MIToS`. ```julia using BioMakie, GLMakie, MIToS.PDB, BioStructures # --- MIToS distance / contact map --- pdbfile = MIToS.PDB.downloadpdb("1IVO", format = PDBFile) resz = select_residues(read_file(pdbfile, PDBFile), model="1", chain="A", group="ATOM") dmap = MIToS.PDB.distance(resz, criteria = "All") cmap = contact(resz, 8.0, criteria = "CB") fig1 = heatmap(dmap; colormap = :viridis) # standalone figure fig2 = Figure() heatmap!(fig2, cmap; colormap = :ice) # into existing figure # --- BioStructures DistanceMap / ContactMap --- struc = retrievepdb("1IVO") cbetas_A = collectatoms(struc[1]["A"], cbetaselector) cbetas_B = collectatoms(struc[1]["B"], cbetaselector) dmap_bs = DistanceMap(cbetas_A, cbetas_B) cmap_bs = ContactMap(cbetas_A, cbetas_B) heatmap(dmap_bs; colormap = :plasma) heatmap(cmap_bs; xlabel = "Chain B", ylabel = "Chain A") ``` -------------------------------- ### Create the main MSA plot figure Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/msaselection.md Initializes a GLMakie figure and plots the MSA data. ```julia fig = Figure(size = (1400,400)) msa = plotmsa!(fig, plotdata) ``` -------------------------------- ### BioMakie Color Schemes for Atoms and Residues Source: https://context7.com/biojulia/biomakie.jl/llms.txt Accesses built-in color dictionaries for element-based and residue-based atom coloring in BioMakie visualizations. These schemes can be retrieved individually or all at once. ```julia using BioMakie # Element-based elecolors cpkcolors aquacolors # Residue-based (keyed by one-letter amino acid code) shapelycolors leskcolors maecolors cinemacolors # Retrieve all at once all_schemes = getbiocolors() ``` -------------------------------- ### `distancebonds` / `covalentbonds` / `sidechainbonds` / `backbonebonds` Source: https://context7.com/biojulia/biomakie.jl/llms.txt Specialized low-level bond-detection functions for specific use cases: pure-distance cutoff, sum-of-covalent-radii, side-chain-only, and backbone-only bond matrices. ```APIDOC ## `distancebonds` / `covalentbonds` / `sidechainbonds` / `backbonebonds` — Specialized bond functions Low-level bond-detection functions for specific use cases: pure-distance cutoff, sum-of-covalent-radii, side-chain-only, and backbone-only bond matrices. ```julia using BioMakie, BioStructures struc = retrievepdb("2vb1") chain = struc["A"] atms = defaultatom.(collectatoms(chain)) ``` ``` -------------------------------- ### Generate Cylinder Meshes for Bonds Source: https://context7.com/biojulia/biomakie.jl/llms.txt Converts a bond matrix and atom coordinates into a vector of GeometryBasics.Cylinder objects for rendering. Supports auto-computation of bonds and manual rendering of single bonds. ```julia using BioMakie, BioStructures, GLMakie struc = retrievepdb("2vb1") chain = struc["A"] # Auto-compute bonds and return cylinders shapes = bondshapes(chain; algo = :knowledgebased, bondwidth = 0.15) # => Vector{Cylinder{Float32}} # Render manually fig = Figure() lscene = LScene(fig[1,1]; show_axis = false) meshes = normal_mesh.(shapes) mesh!(lscene, meshes, color = RGBA(0.5, 0.5, 0.5, 0.8)) # Single bond between two atoms atms = defaultatom.(collectatoms(chain)) cyl = bondshape([atms[1], atms[2]]; bondwidth = 0.2) ``` -------------------------------- ### Retrieve and parse UniProt data Source: https://context7.com/biojulia/biomakie.jl/llms.txt Use `getuniprotdata` to download and parse UniProt entries, or `readuniprotdata` to parse existing JSON files. Requires `BioMakie`. ```julia using BioMakie # Download by accession and parse in one step pdata = getuniprotdata("P00533") # EGFR_HUMAN # => UniProtData struct; prints: "*** Downloaded P00533 to file: P00533.json ***" # Inspect summary show(pdata) # --- Uniprot Data --- # Accession: P00533 # ID: EGFR_HUMAN # Name: Epidermal growth factor receptor # EC Number: 2.7.10.1 # Gene: EGFR # Access fields pdata.sequence # full amino-acid sequence string pdata.domains_and_sites # Vector of OrderedDicts with :type, :description, :begin, :end pdata.mutagenesis # known mutagenesis sites pdata.func # functional annotation comments # Parse a previously downloaded JSON file (include all DB cross-refs) pdata2 = readuniprotdata("P00533.json"; include_refs = true) length(pdata2.dbrefs) # number of cross-reference entries (PDB, EMBL, etc.) ``` -------------------------------- ### Create and configure the amino acid frequency plot Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/msaselection.md Generates a bar plot for amino acid percentages, adjusting axis labels, ticks, and colors based on hydrophobicity. ```julia ax = Axis(fig[1,4], xticklabelsize = 16, yticks = (0:10:100), yticklabelsize = 20, title = "Amino Acid Percentages", titlesize = 18, xticks = (1:22,new_aalabels) ) bp = barplot!(ax, 1:22, aafreqspercent; color = hydrophobicities, strokewidth = 1, xtickrange=1:22, xticklabels=new_aalabels ) ylims!(ax, (0, 100)) xlims!(ax, (0, 23)) ``` -------------------------------- ### Plot Protein Structure (BioStructures) Source: https://context7.com/biojulia/biomakie.jl/llms.txt Create a standalone 3D protein structure visualization using BioStructures.jl. Supports different representations like ball-and-stick, space-filling, and covalent-radius. Structures can be provided directly or as Observables. ```julia using BioMakie, GLMakie, BioStructures # --- BioStructures path --- struc = retrievepdb("2vb1", dir = "data/") |> Observable # Ball-and-stick representation with aqua color scheme fig1 = plotstruc(struc; plottype = :ballandstick, atomcolors = aquacolors) # Space-filling (van der Waals) representation fig2 = plotstruc(struc; plottype = :spacefilling, figsize = (800, 800)) # Covalent-radius representation using custom color overrides fig3 = plotstruc(struc; plottype = :covalent, atomcolors = Dict("C" => :teal, "N" => :blue)) # Single chain only chain_A = retrievepdb("2hhb", dir = "data/")["A"] |> Observable fig4 = plotstruc(chain_A; plottype = :ballandstick, markerscale = 1.2) ``` -------------------------------- ### Prepare column data for frequency plot Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/msaselection.md Extracts column data from the selected residue in the MSA and calculates hydrophobicity values for coloring. ```julia coldata = lift(plotdata[:selected]) do sel try plotdata[:matrix][][:,parse(Int,sel)] catch ["-" for i in 1:size(plotdata[:matrix][])[1]] end end allaas = [ "R", "M", "N", "E", "F", "I", "D", "L", "A", "Q", "G", "C", "W", "Y", "K", "P", "T", "S", "V", "H", "X", "-"] sortaas = sortperm(allaas) new_aalabels = allaas[sortaas] hydrophobicities = [BioMakie.kideradict[new_aalabels[i]][2] for i in 1:length(new_aalabels)] ``` -------------------------------- ### `atomradii` / `atomsizes` Source: https://context7.com/biojulia/biomakie.jl/llms.txt Returns element-based radius vectors for rendering spheres; supports covalent, van der Waals, and ball-and-stick presets. ```APIDOC ## `atomradii` / `atomsizes` — Per-atom radius vectors Returns element-based radius vectors for rendering spheres; supports covalent, van der Waals, and ball-and-stick presets. ```julia using BioMakie, BioStructures struc = retrievepdb("2vb1") atms = defaultatom.(collectatoms(struc)) radii_bas = atomradii(atms; radiustype = :ballandstick) # covalent * ~0.7 radii_vdw = atomradii(atms; radiustype = :vanderwaals) # full VDW radii radii_cov = atomradii(atms; radiustype = :covalent) # covalent radii # atomsizes is a convenience wrapper that resolves atoms from a structure first sizes = atomsizes(struc; radiustype = :spacefilling) # => Vector{Float32}, one entry per non-disordered atom ``` ``` -------------------------------- ### heatmap / heatmap! — Distance and contact map plots Source: https://context7.com/biojulia/biomakie.jl/llms.txt Overloads of Makie's `heatmap` to render MIToS `PairwiseListMatrix` distance/contact maps and BioStructures `DistanceMap`/`ContactMap` objects with interactive data inspection. ```APIDOC ## heatmap / heatmap! ### Description Overloads of Makie's `heatmap` to render MIToS `PairwiseListMatrix` distance/contact maps and BioStructures `DistanceMap`/`ContactMap` objects with interactive data inspection. ### Usage ```julia using BioMakie, GLMakie, MIToS.PDB, BioStructures # --- MIToS distance / contact map --- dmap = MIToS.PDB.distance(resz, criteria = "All") cmap = contact(resz, 8.0, criteria = "CB") fig1 = heatmap(dmap; colormap = :viridis) # standalone figure fig2 = Figure() heatmap!(fig2, cmap; colormap = :ice) # into existing figure # --- BioStructures DistanceMap / ContactMap --- dmap_bs = DistanceMap(cbetas_A, cbetas_B) cmap_bs = ContactMap(cbetas_A, cbetas_B) heatmap(dmap_bs; colormap = :plasma) heatmap(cmap_bs; xlabel = "Chain B", ylabel = "Chain A") ``` ``` -------------------------------- ### Generate Sphere Points and Line Segments Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/alphashape.md Provides functions to generate points on the surface of spheres and to create line segments from a set of 3D coordinates. These are useful for geometric visualizations. ```julia function getspherepoints(cords::Matrix, radius::Real) pnts = [GeometryBasics.Point{3,Float64}(cords[i,:]) for i in 1:size(cords,1)] |> Observable spheres = GeometryBasics.Point{3,Float64}[] lift(pnts) do p for i in 1:size(p,1) sp = GeometryBasics.decompose(GeometryBasics.Point{3,Float64},GeometryBasics.Sphere(p[i],radius),4) |> unique for ii in 1:size(sp,1) push!(spheres,sp[ii]) end end end return [[spheres[i].data...] for i in 1:size(spheres,1)] |> combinedims |> transpose |> collect end function linesegs(arr::AbstractArray{T,3}) where T<:AbstractFloat new_arr::AbstractArray{Point3f} = [] for i in 1:size(arr,1) push!(new_arr, Makie.Point3f(arr[i,1,:])) push!(new_arr, Makie.Point3f(arr[i,2,:])) end return new_arr |> combinedims |> transpose |> collect end ``` -------------------------------- ### Display protein information and GPT response Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/dbinfo.md Renders the UniProt summary and the dynamic GPT-generated text onto separate axes within the figure. Axis decorations are hidden for a cleaner display. ```julia ax = Axis(layout[1:3,6:9]) GLMakie.text!(ax, uniprottxt, fontsize = 16, align = (:left, :top)) xlims!(ax, (0, 1)) ylims!(ax, (-0.5, 0)) hidespines!(ax) hideydecorations!(ax) hidexdecorations!(ax) ax = Axis(layout[5:10,6:9]) GLMakie.text!(ax, txt, fontsize = 16, align = (:left, :top)) xlims!(ax, (0, 1)) ylims!(ax, (-0.5, 0)) hidespines!(ax) hideydecorations!(ax) hidexdecorations!(ax) ``` -------------------------------- ### Specialized Bond Detection Functions Source: https://context7.com/biojulia/biomakie.jl/llms.txt Low-level functions for detecting bonds based on specific criteria: pure distance cutoff, sum-of-covalent-radii, side-chain-only, and backbone-only. ```julia using BioMakie, BioStructures struc = retrievepdb("2vb1") chain = struc["A"] atms = defaultatom.(collectatoms(chain)) ``` -------------------------------- ### Plot Multiple Sequence Alignments with BioMakie.jl Source: https://github.com/biojulia/biomakie.jl/blob/master/docs/src/index.md Visualize multiple sequence alignments using plotmsa. Supports reading from FASTA files or using MIToS.jl for Stockholm format. Customize with color schemes. ```julia using FASTX reader = open(FASTX.FASTA.Reader, "PF00062_full.fasta") msa = [reader...] |> Observable close(reader) ## or using MIToS.MSA msa = read_file("pf00062.stockholm.gz", Stockholm) fig = plotmsa(msa; colorscheme = :tableau_blue_green) ``` -------------------------------- ### Mutate Figure with Protein Structure (BioStructures) Source: https://context7.com/biojulia/biomakie.jl/llms.txt Mutate an existing Makie Figure with a protein structure using BioStructures.jl. This allows for multi-panel layouts, combining structure plots with other visualizations like MSAs. ```julia using BioMakie, GLMakie, BioStructures struc = retrievepdb("2vb1") |> Observable fig = Figure(size = (1200, 600)) # Ballandstick in panel (1,1) plotstruc!(fig, struc; plottype = :ballandstick, gridposition = (1, 1), atomcolors = elecolors, markerscale = 0.9) # Space-filling in panel (1,2) plotstruc!(fig, struc; plottype = :spacefilling, gridposition = (1, 2), atomcolors = aquacolors) display(fig) ``` -------------------------------- ### Visualize Protein Structure with BioMakie Source: https://context7.com/biojulia/biomakie.jl/llms.txt Plots a protein structure using GLMakie, allowing customization of atom colors and plot type. Requires BioStructures for retrieving PDB data and GLMakie for plotting. ```julia using GLMakie, BioStructures struc = retrievepdb("2vb1") |> Observable fig = plotstruc(struc; atomcolors = shapelycolors, plottype = :spacefilling) ``` -------------------------------- ### `atomcolors` / `rescolors` Source: https://context7.com/biojulia/biomakie.jl/llms.txt Returns a Vector of colors for a set of atoms or residues, given a color-scheme dictionary. Accepts BioStructures and MIToS types as well as their Observable wrappers. ```APIDOC ## `atomcolors` / `rescolors` — Atom and residue color vectors Returns a `Vector` of colors for a set of atoms or residues, given a color-scheme dictionary. Accepts BioStructures and MIToS types as well as their `Observable` wrappers. ```julia using BioMakie, BioStructures struc = retrievepdb("2vb1") atms = defaultatom.(collectatoms(struc)) # Element-based coloring (CPK) ecols = atomcolors(struc; colors = elecolors) # => Vector of colors: C→:gray, N→:blue, O→:red, S→:yellow … # Aqua palette acols = atomcolors(struc; colors = aquacolors) # Residue-type coloring (MAE scheme) rcols = rescolors(struc; colors = maecolors) # => colors keyed by one-letter residue codes: A→:lightgreen, R→:orange … # All built-in schemes at once all_schemes = getbiocolors() # Returns OrderedDict with keys: # :elecolors, :cpkcolors, :aquacolors, # :shapelycolors, :leskcolors, :maecolors, :cinemacolors ``` ``` -------------------------------- ### `bondshapes` / `bondshape` Source: https://context7.com/biojulia/biomakie.jl/llms.txt Converts a bond matrix and atom coordinates into a vector of GeometryBasics.Cylinder objects ready to be passed to `mesh!` for rendering. ```APIDOC ## `bondshapes` / `bondshape` — Cylinder mesh geometries for bonds Converts a bond matrix and atom coordinates into a vector of `GeometryBasics.Cylinder` objects ready to be passed to `mesh!` for rendering. ```julia using BioMakie, BioStructures, GLMakie struc = retrievepdb("2vb1") chain = struc["A"] # Auto-compute bonds and return cylinders shapes = bondshapes(chain; algo = :knowledgebased, bondwidth = 0.15) # => Vector{Cylinder{Float32}} # Render manually fig = Figure() lscene = LScene(fig[1,1]; show_axis = false) meshes = normal_mesh.(shapes) mesh!(lscene, meshes, color = RGBA(0.5, 0.5, 0.5, 0.8)) # Single bond between two atoms atms = defaultatom.(collectatoms(chain)) cyl = bondshape([atms[1], atms[2]]; bondwidth = 0.2) ``` ``` -------------------------------- ### Plot Multiple Sequence Alignment (MIToS Stockholm) Source: https://context7.com/biojulia/biomakie.jl/llms.txt Create a standalone interactive multiple sequence alignment (MSA) heatmap using MIToS.jl in Stockholm format. Features per-position amino acid characters overlaid as scatter markers and supports scrolling through large alignments. ```julia using BioMakie, GLMakie # --- MIToS Stockholm format --- using MIToS.MSA, MIToS.Pfam MIToS.Pfam.downloadpfam("PF00062") msa = MIToS.MSA.read_file("PF00062.stockholm.gz", Stockholm, generatemapping = true, useidcoordinates = true) fig1 = plotmsa(msa; colorscheme = :buda, markersize = 11) ```