dsh-molbio-tools 0.27.1 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test/smoke.mjs CHANGED
@@ -3442,7 +3442,7 @@ if (savedNcbiEnv.MOLBIO_NCBI_API_KEY !== undefined) process.env.MOLBIO_NCBI_API_
3442
3442
  'molbio_grna_design', 'molbio_qpcr_efficiency', 'molbio_plot', 'molbio_virtual_gel',
3443
3443
  'molbio_sequence_logo', 'molbio_helical_wheel', 'molbio_hydropathy_plot',
3444
3444
  'molbio_fastq_qc', 'molbio_phylogenetic_tree', 'molbio_pcr_simulate', 'molbio_gc_composition',
3445
- 'molbio_protein_charge', 'molbio_dotplot',
3445
+ 'molbio_protein_charge', 'molbio_dotplot', 'molbio_signal_peptide',
3446
3446
  ];
3447
3447
  for (const toolName of pictureTools) {
3448
3448
  const tool = toolByName(toolName);
@@ -3450,7 +3450,7 @@ if (savedNcbiEnv.MOLBIO_NCBI_API_KEY !== undefined) process.env.MOLBIO_NCBI_API_
3450
3450
  assert.ok(Object.hasOwn(tool.output.schema.properties, 'image'), `${toolName} can report the attached image`);
3451
3451
  assert.ok(Object.hasOwn(tool.output.schema.properties, 'image_note'), `${toolName} can explain a missing image`);
3452
3452
  }
3453
- assert.equal(registered.filter((tool) => Object.hasOwn(tool.parameters.properties, 'attach_image')).length, 17, 'exactly the 17 picture tools — the report-only analysis tools are untouched');
3453
+ assert.equal(registered.filter((tool) => Object.hasOwn(tool.parameters.properties, 'attach_image')).length, 18, 'exactly the 18 picture tools — the report-only analysis tools are untouched');
3454
3454
 
3455
3455
  // 9. Rendering text alone still works (the attachment must not break render).
3456
3456
  const logo = await runWith('molbio_sequence_logo', { alignment: ['ACGTACGT', 'ACGTTCGT'], attach_image: true }, routedExec);
@@ -4601,8 +4601,197 @@ if (savedNcbiEnv.MOLBIO_NCBI_API_KEY !== undefined) process.env.MOLBIO_NCBI_API_
4601
4601
  assert.match(text, /dimers: homodimer Tm any/);
4602
4602
  }
4603
4603
 
4604
+ // ── v0.28.0: protein annotation, format interchange, sequencing read sets ───
4605
+
4606
+ {
4607
+ // #13 — PTM motifs, low-complexity regions and composition.
4608
+ const flat = await run('molbio_protein_features', { sequence: 'AAAA' });
4609
+ assert.equal(flat.length, 4);
4610
+ assert.equal(flat.composition.instability_index, 7.5);
4611
+ assert.equal(flat.composition.instability_class, 'stable');
4612
+ assert.equal(flat.composition.aromaticity, 0);
4613
+ assert.deepEqual(flat.ptm_sites, []);
4614
+ assert.deepEqual(flat.low_complexity_regions, [], 'a protein shorter than the window has no low-complexity region');
4615
+
4616
+ const motifs = await run('molbio_protein_features', { sequence: 'AANASWAAWGEASTALKAERRASAAE' });
4617
+ const foundMotifs = motifs.ptm_sites.map((site) => `${site.type}@${site.position}`);
4618
+ for (const expected of [
4619
+ 'N-glycosylation@3',
4620
+ 'C-mannosylation@6',
4621
+ 'SUMOylation@17',
4622
+ 'PKA phosphorylation@22',
4623
+ 'CK2 phosphorylation@23',
4624
+ ]) assert.ok(foundMotifs.includes(expected), `the scan reports ${expected}`);
4625
+ assert.ok(!foundMotifs.some((entry) => entry.startsWith('N-myristoylation')), 'myristoylation is N-terminal only');
4626
+ const myristoyl = await run('molbio_protein_features', { sequence: 'GEASTAAAA' });
4627
+ assert.ok(myristoyl.ptm_sites.some((site) => site.type === 'N-myristoylation' && site.position === 1));
4628
+
4629
+ const lowComplexity = await run('molbio_protein_features', { sequence: 'A'.repeat(20) });
4630
+ assert.deepEqual(lowComplexity.low_complexity_regions.map((region) => [region.start, region.end, region.entropy]), [[1, 20, 0]]);
4631
+ assert.equal(lowComplexity.low_complexity_regions[0].min_window_entropy, 0);
4632
+
4633
+ const capped = await run('molbio_protein_features', { sequence: 'SP'.repeat(5), max_sites: 1 });
4634
+ assert.equal(capped.ptm_sites.length, 1);
4635
+ assert.equal(capped.truncated, true);
4636
+ await assert.rejects(() => run('molbio_protein_features', { sequence: 'AAAA', entropy_threshold: 9 }), /entropy_threshold/);
4637
+ await assert.rejects(() => run('molbio_protein_features', { sequence: 'ATGX' }), /invalid character/);
4638
+
4639
+ // #21 — signal-peptide cleavage and candidate transmembrane segments.
4640
+ const insulin = 'MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALY';
4641
+ const signal = await run('molbio_signal_peptide', { sequence: insulin, output_path: at('signal.svg') });
4642
+ assert.equal(signal.cleavable, true);
4643
+ assert.equal(signal.cleavage_after, 24);
4644
+ assert.equal(signal.best_score, 6.852);
4645
+ assert.equal(signal.signal_peptide, 'MALWMRLLPLLALLALWGPDPAAA');
4646
+ assert.equal(signal.mature_sequence, 'FVNQHLCGSHLVEALY');
4647
+ assert.deepEqual([signal.window_start, signal.window_end], [12, 26]);
4648
+ assert.equal(signal.svg_path, at('signal.svg'));
4649
+ assert.ok(memFs.files.get(signal.svg_path).toString('utf8').includes('<svg'));
4650
+
4651
+ const gfp = await run('molbio_signal_peptide', { sequence: 'MSKGEELFTGVVPILVELDGDVNGHKFSVSGEGEGDATYGKLTLK' });
4652
+ assert.equal(gfp.cleavable, false);
4653
+ assert.equal(gfp.cleavage_after, 0);
4654
+ const tm = await run('molbio_signal_peptide', { sequence: 'M' + 'A'.repeat(30) + 'KKKK' });
4655
+ assert.equal(tm.transmembrane_segments.length, 1);
4656
+ assert.deepEqual([tm.transmembrane_segments[0].start, tm.transmembrane_segments[0].end], [1, 22]);
4657
+ assert.equal(tm.transmembrane_segments[0].mean_hydropathy, 1.81);
4658
+ await assert.rejects(() => run('molbio_signal_peptide', { sequence: 'M'.repeat(10) }), /at least 15/);
4659
+ await assert.rejects(() => run('molbio_signal_peptide', { sequence: insulin, organism: 'plant' }), /organism/);
4660
+ await assert.rejects(() => run('molbio_signal_peptide', { sequence: insulin, threshold: 99 }), /threshold/);
4661
+
4662
+ // #14 — Kolaskar-Tongaonkar propensity on a homopolymer (every value is A(p)=1.064).
4663
+ const antigenic = await run('molbio_antigenicity', { sequence: 'A'.repeat(20) });
4664
+ assert.equal(antigenic.mean_propensity, 1.064);
4665
+ assert.equal(antigenic.threshold, 1);
4666
+ assert.equal(antigenic.regions.length, 1);
4667
+ assert.deepEqual([antigenic.regions[0].start, antigenic.regions[0].end], [4, 17]);
4668
+ assert.equal(antigenic.regions[0].length, 14);
4669
+ assert.equal(antigenic.regions[0].parker_mean, 2.1);
4670
+ assert.equal(antigenic.regions[0].emini_mean, 0.815);
4671
+ assert.equal(antigenic.regions[0].flexibility_mean, 0.984);
4672
+ await assert.rejects(() => run('molbio_antigenicity', { sequence: 'AAAAAAA' }), /at least 8/);
4673
+
4674
+ // #10 — feature export keeps the two coordinate systems apart.
4675
+ const exportInput = {
4676
+ sequence: 'ACGTACGTAC',
4677
+ features: [{ type: 'CDS', start: 2, end: 6, strand: 1, label: 'gene1' }],
4678
+ format: 'gff3',
4679
+ };
4680
+ const gff3 = await run('molbio_feature_export', exportInput);
4681
+ assert.equal(gff3.coordinate_system, '1-based inclusive');
4682
+ assert.match(gff3.content, /^##gff-version 3$/m);
4683
+ assert.match(gff3.content, /\tCDS\t2\t6\t\.\t\+\t\.\tID=CDS_1;Name=gene1/);
4684
+ const bed = await run('molbio_feature_export', { ...exportInput, format: 'bed' });
4685
+ assert.equal(bed.coordinate_system, '0-based half-open');
4686
+ assert.match(bed.content, /^sequence\t1\t6\tgene1\t0\t\+$/m);
4687
+ const csv = await run('molbio_feature_export', { ...exportInput, format: 'csv' });
4688
+ assert.match(csv.content, /^sequence,CDS,2,6,\+,5,gene1,,,$/m);
4689
+ const reverseBed = await run('molbio_feature_export', { sequence: 'ACGTACGTAC', features: [{ start: 2, end: 6, strand: -1, label: 'r' }], format: 'bed' });
4690
+ assert.match(reverseBed.content, /^sequence\t1\t6\tr\t0\t-$/m, 'a parser-style -1 strand becomes - in BED');
4691
+ const multi = await run('molbio_feature_export', {
4692
+ sequence: 'ACGTACGTAC',
4693
+ features: [{ type: 'misc_feature', start: 1, end: 9, label: 'joined', location: 'join(1..3,7..9)', multi_part: true }],
4694
+ format: 'gff3',
4695
+ });
4696
+ assert.ok(multi.notes.some((note) => note.includes('multi-part')));
4697
+ assert.match(multi.content, /location=join\(1\.\.3%2C7\.\.9\)/);
4698
+ const savedFeatures = await run('molbio_feature_export', { ...exportInput, output_path: at('features.gff3') });
4699
+ assert.equal(savedFeatures.saved_to, at('features.gff3'));
4700
+ assert.match(memFs.files.get(savedFeatures.saved_to).toString('utf8'), /##gff-version 3/);
4701
+ await assert.rejects(() => run('molbio_feature_export', { sequence: 'ACGT', features: [{ start: 1, end: 9 }], format: 'gff3' }), /past the sequence length/);
4702
+
4703
+ // #10 — sequence surgery.
4704
+ const rotated = await run('molbio_sequence_edit', { sequence: 'AACCGGTT', operation: 'rotate', position: 3 });
4705
+ assert.equal(rotated.sequences[0], 'CCGGTTAA');
4706
+ const inserted = await run('molbio_sequence_edit', { sequence: 'AAAACCCC', operation: 'insert', position: 0, inserted: 'TT' });
4707
+ assert.equal(inserted.sequences[0], 'TTAAAACCCC');
4708
+ const deleted = await run('molbio_sequence_edit', { sequence: 'AAAACCCC', operation: 'delete', start: 2, end: 4 });
4709
+ assert.equal(deleted.sequences[0], 'ACCCC');
4710
+ const replaced = await run('molbio_sequence_edit', { sequence: 'AAAACCCC', operation: 'replace', start: 2, end: 4, replacement: 'GG' });
4711
+ assert.equal(replaced.sequences[0], 'AGGCCCC');
4712
+ const split = await run('molbio_sequence_edit', { sequence: 'AAAACCCC', operation: 'split', position: 4 });
4713
+ assert.deepEqual(split.sequences, ['AAAA', 'CCCC']);
4714
+ const joined = await run('molbio_sequence_edit', { sequence: 'AAAACC', operation: 'join', join_with: 'CCGGGG', overlap: 2 });
4715
+ assert.equal(joined.sequences[0], 'AAAACCGGGG');
4716
+ const splitFile = await run('molbio_sequence_edit', { sequence: 'AAAACCCC', operation: 'split', position: 4, output_path: at('parts.fa') });
4717
+ assert.match(memFs.files.get(splitFile.saved_to).toString('utf8'), />edited_part1/);
4718
+ await assert.rejects(() => run('molbio_sequence_edit', { sequence: 'AAAACC', operation: 'join', join_with: 'TTGGGG', overlap: 2 }), /does not match/);
4719
+ await assert.rejects(() => run('molbio_sequence_edit', { sequence: 'AAAACCCC', operation: 'delete', start: 3, end: 2 }), /start <= end/);
4720
+
4721
+ // #27 — greedy overlap-layout assembly with both read orientations.
4722
+ let seed = 7;
4723
+ const rand = () => (seed = (seed * 1103515245 + 12345) % 2147483648) / 2147483648;
4724
+ const assemblyRef = Array.from({ length: 400 }, () => 'ACGT'[Math.floor(rand() * 4)]).join('');
4725
+ const assemblyReads = [
4726
+ { name: 'r1', sequence: assemblyRef.slice(0, 220) },
4727
+ { name: 'r2', sequence: assemblyRef.slice(150, 370) },
4728
+ { name: 'r3', sequence: reverseComplementOf(assemblyRef.slice(280, 400)) },
4729
+ ];
4730
+ const assembly = await run('molbio_sanger_assemble', { reads: assemblyReads, min_overlap: 40, trim_quality: 0, output_path: at('contig.fa') });
4731
+ assert.equal(assembly.length, 400);
4732
+ assert.equal(assembly.sequence, assemblyRef);
4733
+ assert.equal(assembly.placed_count, 3);
4734
+ assert.equal(assembly.coverage_mean, 1.4);
4735
+ assert.equal(assembly.coverage_min, 1);
4736
+ assert.equal(assembly.conflicts, 0);
4737
+ assert.deepEqual(assembly.reads.map((read) => [read.name, read.orientation, read.start, read.end]), [
4738
+ ['r1', 'forward', 1, 220], ['r2', 'forward', 151, 370], ['r3', 'reverse', 281, 400],
4739
+ ]);
4740
+ assert.equal(assembly.saved_to, at('contig.fa'));
4741
+ assert.match(memFs.files.get(assembly.saved_to).toString('utf8'), />contig/);
4742
+ const withJunk = await run('molbio_sanger_assemble', { reads: [...assemblyReads, { name: 'junk', sequence: 'N'.repeat(60) }], min_overlap: 40, trim_quality: 0 });
4743
+ assert.equal(withJunk.placed_count, 3);
4744
+ assert.deepEqual(withJunk.unplaced.map((read) => read.name), ['junk']);
4745
+ await assert.rejects(() => run('molbio_sanger_assemble', { reads: [] }), /provide paths/);
4746
+
4747
+ // #31 — allele clustering and the CDS effect call.
4748
+ const editRef = 'ATG' + 'GCT'.repeat(30) + 'TAA';
4749
+ const editReads = [
4750
+ { name: 'wt1', sequence: editRef },
4751
+ { name: 'wt2', sequence: editRef },
4752
+ { name: 'del', sequence: editRef.slice(0, 3) + editRef.slice(6) },
4753
+ { name: 'sub', sequence: editRef.slice(0, 3) + 'A' + editRef.slice(4) },
4754
+ { name: 'junk', sequence: 'C'.repeat(60) },
4755
+ ];
4756
+ const outcome = await run('molbio_editing_outcome', {
4757
+ reads: editReads, reference: editRef, circular: false, cds_start: 1, cds_end: editRef.length,
4758
+ });
4759
+ assert.equal(outcome.total_reads, 5);
4760
+ assert.equal(outcome.aligned_reads, 4);
4761
+ assert.equal(outcome.unaligned_reads, 1);
4762
+ assert.equal(outcome.alleles.length, 3);
4763
+ const wildType = outcome.alleles.find((allele) => allele.signature === 'wild_type');
4764
+ assert.equal(wildType.frequency, 0.5);
4765
+ assert.equal(wildType.effect, 'wild_type');
4766
+ const deletion = outcome.alleles.find((allele) => allele.effect === 'in_frame_indel');
4767
+ assert.equal(deletion.frequency, 0.25);
4768
+ assert.deepEqual([deletion.edited_from, deletion.edited_to], [3, 6]);
4769
+ const substitution = outcome.alleles.find((allele) => allele.signature === 'sub:4:G>A');
4770
+ assert.equal(substitution.effect, 'missense');
4771
+ assert.equal(substitution.protein_change, 'A2T');
4772
+ assert.equal(substitution.frequency, 0.25);
4773
+ assert.ok(outcome.notes.some((note) => note.includes('not TIDE')));
4774
+ const frameOutcome = await run('molbio_editing_outcome', {
4775
+ reads: [{ name: 'wt', sequence: editRef }, { name: 'fs', sequence: editRef.slice(0, 3) + editRef.slice(4) }],
4776
+ reference: editRef, circular: false, cds_start: 1, cds_end: editRef.length,
4777
+ });
4778
+ assert.equal(frameOutcome.alleles.find((allele) => allele.effect === 'frameshift').frequency, 0.5);
4779
+ const silentOutcome = await run('molbio_editing_outcome', {
4780
+ reads: [{ name: 'wt', sequence: editRef }, { name: 'silent', sequence: editRef.slice(0, 5) + 'C' + editRef.slice(6) }],
4781
+ reference: editRef, circular: false, cds_start: 1, cds_end: editRef.length,
4782
+ });
4783
+ assert.equal(silentOutcome.alleles.find((allele) => allele.effect === 'silent').frequency, 0.5);
4784
+ const noWildType = await run('molbio_editing_outcome', {
4785
+ reads: [{ name: 'del', sequence: editRef.slice(0, 3) + editRef.slice(6) }],
4786
+ reference: editRef, circular: false, cds_start: 1, cds_end: editRef.length,
4787
+ });
4788
+ assert.ok(noWildType.notes.some((note) => note.includes('no read matches the reference exactly')), 'a read set with no wild type is diagnosed');
4789
+ await assert.rejects(() => run('molbio_editing_outcome', { reads: editReads, reference: editRef, cds_start: 1 }), /both cds_start and cds_end/);
4790
+ await assert.rejects(() => run('molbio_editing_outcome', { reads: editReads, reference: editRef, min_frequency: 2 }), /min_frequency/);
4791
+ }
4604
4792
  // ── plugin surface ──────────────────────────────────────────────────────────
4605
4793
 
4794
+ assert.equal(registered.length, 72, 'the registry carries the 65 shipped tools plus the 7 v0.28.0 tools');
4606
4795
  assert.equal(plugin.name, 'dsh-molbio-tools');
4607
4796
  assert.deepEqual(plugin.inject, ['tools', 'systemPrompt']);
4608
4797
 
package/test/svgpng.mjs CHANGED
@@ -33,6 +33,7 @@ import { renderPlasmidMap } from '../plasmid.mjs';
33
33
  import { linearFit, renderBarChart, renderGel, renderScatterChart } from '../plot.mjs';
34
34
  import { columnComposition, renderSequenceLogo } from '../logo.mjs';
35
35
  import { helicalWheel, hydropathyProfile, renderHelicalWheel, renderHydropathyPlot } from '../protein-structure.mjs';
36
+ import { renderSignalPeptideProfile, signalPeptideAnalysis } from '../protein-annotate.mjs';
36
37
  import { fastqQcReport, renderFastqQcReport } from '../fastq-qc.mjs';
37
38
  import { renderTreeSvg } from '../phylo.mjs';
38
39
  import { pcrGel } from '../pcr.mjs';
@@ -708,6 +709,7 @@ function sampleDocuments() {
708
709
  ['sequence logo', renderSequenceLogo(columnComposition(['ACGTACGTAC', 'ACGTTCGTAC', 'ACGTACGTGC', 'ACGAACGTAC', 'ACGTACGTAC']), { title: 'Conserved motif', score_type: 'bits' })],
709
710
  ['helical wheel', renderHelicalWheel(wheel, { title: 'Amphipathic helix' })],
710
711
  ['hydropathy plot', renderHydropathyPlot(hydropathy, { title: 'Kyte-Doolittle hydropathy' })],
712
+ ['signal peptide profile', renderSignalPeptideProfile(signalPeptideAnalysis('MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALY'), { title: 'Signal peptide score' })],
711
713
  ['bar chart', renderBarChart({ title: 'Relative expression', x_label: 'condition', y_label: 'fold change', labels: ['control', 'treated', 'rescue'], values: [1, 8.4, 2.1], errors: [0.2, 1.1, 0.4] })],
712
714
  ['scatter chart', renderScatterChart({ title: 'Standard curve', x_label: 'log10 quantity', y_label: 'Ct', x: [0, 1, 2, 3, 4], y: [32.1, 28.9, 25.2, 21.6, 18.1], fit: linearFit([0, 1, 2, 3, 4], [32.1, 28.9, 25.2, 21.6, 18.1]) })],
713
715
  // v19 pictures: the six-panel FASTQ report, the phylogenetic tree (all