restriction-analysis/restriction-mapping/SKILL.md
Create restriction maps showing enzyme cut positions on DNA sequences using Biopython Bio.Restriction. Visualize cut sites, calculate distances between sites, and generate text or graphical maps. Use when creating or analyzing restriction maps.
npx skillsauth add GPTomics/bioSkills bio-restriction-mappingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Reference examples tested with: BioPython 1.83+
Before using code patterns, verify installed versions match. If versions differ:
pip show <package> then help(module.function) to check signaturesIf code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
"Create a restriction map of my sequence" -> Visualize cut site positions for multiple enzymes along a DNA sequence with inter-site distances.
Bio.Restriction.Analysis for positions, matplotlib for graphical mapsfrom Bio import SeqIO
from Bio.Restriction import EcoRI, BamHI, HindIII, RestrictionBatch, Analysis
record = SeqIO.read('sequence.fasta', 'fasta')
seq = record.seq
batch = RestrictionBatch([EcoRI, BamHI, HindIII])
analysis = Analysis(batch, seq)
# Print formatted map
analysis.print_as('map')
# Map format (visual)
analysis.print_as('map')
# Linear format (list)
analysis.print_as('linear')
# Tabular format
analysis.print_as('tabulate')
# Get as string instead of printing
map_str = analysis.format_as('map')
linear_str = analysis.format_as('linear')
from Bio.Restriction import EcoRI, BamHI
ecori_sites = EcoRI.search(seq)
bamhi_sites = BamHI.search(seq)
# All cut positions sorted
all_sites = sorted(ecori_sites + bamhi_sites)
# Calculate distances between consecutive sites
distances = []
for i in range(len(all_sites) - 1):
dist = all_sites[i + 1] - all_sites[i]
distances.append((all_sites[i], all_sites[i + 1], dist))
print(f'{all_sites[i]} -> {all_sites[i + 1]}: {dist} bp')
from Bio import SeqIO
from Bio.Restriction import RestrictionBatch, Analysis
from Bio.Restriction import EcoRI, BamHI, HindIII, XhoI, NotI
record = SeqIO.read('plasmid.fasta', 'fasta')
seq = record.seq
seq_len = len(seq)
enzymes = RestrictionBatch([EcoRI, BamHI, HindIII, XhoI, NotI])
analysis = Analysis(enzymes, seq, linear=False)
print(f'Restriction Map: {record.id}')
print(f'Length: {seq_len} bp (circular)')
print('=' * 50)
results = analysis.full()
all_cuts = []
for enzyme, sites in results.items():
for site in sites:
all_cuts.append((site, str(enzyme)))
all_cuts.sort(key=lambda x: x[0])
print('\nCut sites (5\' -> 3\'):')
for pos, enz in all_cuts:
pct = (pos / seq_len) * 100
print(f' {pos:6d} bp ({pct:5.1f}%) - {enz}')
def draw_restriction_map(seq, results, width=80):
'''Draw a simple text restriction map'''
seq_len = len(seq)
scale = width / seq_len
# Header
print(f'0{" " * (width - 6)}{seq_len}')
print('|' + '-' * (width - 2) + '|')
# Plot each enzyme
for enzyme, sites in results.items():
if not sites:
continue
line = [' '] * width
for site in sites:
pos = int(site * scale)
if pos >= width:
pos = width - 1
line[pos] = '|'
print(''.join(line) + f' {enzyme}')
print('|' + '-' * (width - 2) + '|')
# Usage
batch = RestrictionBatch([EcoRI, BamHI, HindIII])
analysis = Analysis(batch, seq)
results = analysis.full()
draw_restriction_map(seq, results)
from Bio import SeqIO
from Bio.Restriction import RestrictionBatch, Analysis, EcoRI, BamHI
record = SeqIO.read('plasmid.gb', 'genbank')
seq = record.seq
enzymes = RestrictionBatch([EcoRI, BamHI])
analysis = Analysis(enzymes, seq, linear=False)
results = analysis.full()
print('Restriction Sites and Overlapping Features:')
print('=' * 60)
for enzyme, sites in results.items():
for site in sites:
print(f'\n{enzyme} at position {site}:')
for feature in record.features:
start = int(feature.location.start)
end = int(feature.location.end)
if start <= site <= end:
feat_type = feature.type
label = feature.qualifiers.get('label', feature.qualifiers.get('gene', ['unknown']))[0]
print(f' Within {feat_type}: {label} ({start}-{end})')
def export_restriction_map(seq, results, output_file, seq_name='sequence'):
'''Export restriction map to text file'''
with open(output_file, 'w') as f:
f.write(f'Restriction Map: {seq_name}\n')
f.write(f'Length: {len(seq)} bp\n')
f.write('=' * 50 + '\n\n')
all_cuts = []
for enzyme, sites in results.items():
for site in sites:
all_cuts.append((site, str(enzyme)))
all_cuts.sort()
f.write('Site\tPosition\tFrom_Start\n')
for pos, enz in all_cuts:
f.write(f'{enz}\t{pos}\t{pos}\n')
f.write('\n\nFragment sizes between sites:\n')
if all_cuts:
positions = sorted([c[0] for c in all_cuts])
for i in range(len(positions) - 1):
size = positions[i + 1] - positions[i]
f.write(f'{positions[i]} -> {positions[i + 1]}: {size} bp\n')
# Usage
export_restriction_map(seq, results, 'restriction_map.txt', record.id)
def circular_distances(sites, seq_len):
'''Calculate fragment sizes for circular DNA'''
if not sites:
return []
sites = sorted(sites)
fragments = []
# Between consecutive sites
for i in range(len(sites) - 1):
fragments.append(sites[i + 1] - sites[i])
# Wrap-around fragment
wrap = (seq_len - sites[-1]) + sites[0]
fragments.append(wrap)
return fragments
# Usage
ecori_sites = EcoRI.search(seq, linear=False)
fragments = circular_distances(ecori_sites, len(seq))
print(f'EcoRI fragments (circular): {fragments}')
tools
--- name: bio-phasing-imputation-foundations description: Frames the phasing/imputation pipeline before any tool runs: phasing and imputation are one Li-Stephens copying HMM (recombination is the transition, mutation the emission, the genetic map and Ne set the rates), imputation's honest output is a dosage with a self-estimated quality (INFO/R2/DR2) not a hard genotype, and the stages are ordered and each fails silently (QC, align build and strand to the panel, phase, impute per chromosome, fil
tools
Chooses the enrichment generation before any tool runs, mapping the input shape to a method class - a pre-selected gene list plus a background to over-representation analysis (ORA, hypergeometric), a ranked statistic for all genes to gene set enrichment (GSEA), a signed signaling topology to pathway-topology (SPIA) - then making the null explicit (competitive vs self-contained, gene vs subject sampling) and running a trustworthiness checklist (testable-gene universe, FDR, redundancy collapse, leading-edge check, version reporting). Covers why every clusterProfiler GSEA is the inter-gene-correlation-uncorrected competitive null, why the background not the gene list decides ORA significance, and why no method is universally best. Use when deciding ORA vs GSEA vs topology, which gene-set DB, whether a result is trustworthy, or which null a tool computes. For ORA see go-enrichment, GSEA see gsea, databases kegg-pathways/reactome-pathways/wikipathways; the ranking comes from differential-expression/de-results.
testing
End-to-end GWAS workflow from VCF to association results. Covers PLINK QC, population structure correction, and association testing for case-control or quantitative traits. Use when running genome-wide association studies.
development
Orchestrates the full path from differential expression results to redundancy-collapsed functional enrichment: choose ORA vs GSEA, convert gene IDs per method, run enrichGO/enrichKEGG/enrichPathway/enrichWP or gseGO/gseKEGG (clusterProfiler, ReactomePA, rWikiPathways), and visualize. Routes the ORA-vs-GSEA generation fork and the null/universe/reproducibility theory to pathway-analysis/enrichment-foundations. Use when a DESeq2/edgeR/limma result must become enriched GO terms, KEGG/Reactome/WikiPathways pathways, or a GSEA leading edge; when deciding whether a ranking exists for all genes (GSEA, named decreasing vector) or only a pre-selected list (ORA plus a defensible background universe); or when assembling DE-to-pathway end to end. The DE list and ranking statistic come from differential-expression/de-results; per-method nuance lives in the pathway-analysis skills.