Before using code patterns, verify installed versions match. If versions differ:
Python: pip show <package> then help(module.function) to check signatures
R: packageVersion('<pkg>') then ?function_name to verify parameters
CLI: <tool> --version then <tool> --help to confirm flags
If code throws ImportError, AttributeError, or TypeError, introspect the installed
package and adapt the example to match the actual API rather than retrying.
Repertoire Visualization
"Visualize my immune repertoire data" → Create publication-quality figures for TCR/BCR repertoires including circos plots, V(D)J gene usage heatmaps, diversity plots, and clonal tracking across samples.
CLI: vdjtools PlotFancyVJUsage for circos-style V-J plots
Python: matplotlib/seaborn for custom repertoire visualizations
def plot_spectratype(clone_df, group_col=None):
'''Plot CDR3 length distribution'''
fig, ax = plt.subplots(figsize=(10, 6))
clone_df['cdr3_length'] = clone_df['cdr3_nt'].str.len()
if group_col:
for group, data in clone_df.groupby(group_col):
ax.hist(data['cdr3_length'], bins=range(20, 80, 3),
alpha=0.5, label=group, density=True)
ax.legend()
else:
ax.hist(clone_df['cdr3_length'], bins=range(20, 80, 3))
ax.set_xlabel('CDR3 Length (nt)')
ax.set_ylabel('Density')
ax.set_title('CDR3 Length Distribution (Spectratype)')
plt.savefig('spectratype.pdf')
Clonotype Network
import networkx as nx
def plot_clone_network(clone_df, similarity_threshold=0.8):
'''Create network of similar clonotypes'''
from Levenshtein import ratio
G = nx.Graph()
clones = clone_df['cdr3_aa'].unique()
# Add nodes
for clone in clones:
freq = clone_df[clone_df['cdr3_aa'] == clone]['frequency'].sum()
G.add_node(clone, size=freq)
# Add edges for similar clones
for i, c1 in enumerate(clones):
for c2 in clones[i+1:]:
sim = ratio(c1, c2)
if sim >= similarity_threshold:
G.add_edge(c1, c2, weight=sim)
# Draw network
fig, ax = plt.subplots(figsize=(12, 12))
pos = nx.spring_layout(G)
sizes = [G.nodes[n]['size'] * 1000 for n in G.nodes()]
nx.draw(G, pos, node_size=sizes, with_labels=False, ax=ax)
plt.savefig('clone_network.pdf')
Related Skills
vdjtools-analysis - Generate input data
mixcr-analysis - Generate clonotype tables
data-visualization/ggplot2-fundamentals - General plotting concepts