Skip to content

Commit

Permalink
chore: update package versions and add trimAnnStartEndToFitSeqLength …
Browse files Browse the repository at this point in the history
…utility function with tests, start to add protein editor test
  • Loading branch information
tnrich committed Jan 28, 2025
1 parent 9eb0a4b commit a8fc851
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### 0.2.0

- feat: replace HTMLSelect with TgHTMLSelect to provide better disabled… [`#130`](https://github.com/TeselaGen/tg-oss/pull/130)
- fix: Pass editor name to simplelinearcircularSequenceView component [`#129`](https://github.com/TeselaGen/tg-oss/pull/129)
- Expose files in package to workaround multiple version of react [`#124`](https://github.com/TeselaGen/tg-oss/pull/124)
- fix copy sequence [`#127`](https://github.com/TeselaGen/tg-oss/pull/127)
- Refactor file imports and update version; make initial values not get overridden by default values; add DefaultVal demo component [`#125`](https://github.com/TeselaGen/tg-oss/pull/125)
Expand Down
41 changes: 33 additions & 8 deletions packages/ove/cypress/e2e/proteinEditor.spec.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
describe("proteinEditor", function () {
beforeEach(() => {
cy.visit("/#/Editor?moleculeType=Protein");
// cy.get(`[data-test="moleculeType"]`).select('Protein')
});
it(`annotations shouldn't have a strand field to edit and all annotations be 'forward'`, () => {
cy.visit("/#/Editor?moleculeType=Protein");
cy.contains(".veRowViewPart", "Part 0").rightclick();
cy.contains(".bp3-menu-item", "Edit Part").click();
cy.contains(".bp3-dialog", "Add Note"); //dialog should exist, but strand shouldn't
cy.contains(".bp3-dialog", "Strand").should("not.exist");
});
it(`should have non protein actions hidden from the menu search`, () => {
cy.visit("/#/Editor?moleculeType=Protein");
cy.get("body").type("{meta}/");
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(0);
cy.focused().type("translation{enter}");
cy.contains(".bp3-menu-item", "Translations").should("not.exist");
});
it(`should be able to toggle between protein and dna mode after firing some actions`, () => {
cy.visit("/#/Editor?moleculeType=Protein");
cy.contains(".veLabelText", "Part 0").click();
cy.get(`[data-test="moleculeType"]`).select("DNA");
cy.contains("Length: 5299 bps").should("exist");
});
it(`feature/part add/edit should be AA indexed`, () => {
cy.visit("/#/Editor?moleculeType=Protein");
cy.get(".tg-menu-bar").contains("Edit").click();
cy.contains(".bp3-menu-item", "Create").click();
cy.contains(".bp3-menu-item", "New Feature").click({ force: true });
Expand Down Expand Up @@ -57,6 +57,7 @@ describe("proteinEditor", function () {
cy.get(`.tg-test-end [value="31"]`);
});
it(`should be able to insert AAs correctly via typing in the editor`, () => {
cy.visit("/#/Editor?moleculeType=Protein");
cy.contains("Part - pj5_00001 - Start: 1 End: 1384");
cy.contains(".veRowViewPrimaryProteinSequenceContainer svg g", "M").click({
force: true
Expand Down Expand Up @@ -96,7 +97,25 @@ describe("proteinEditor", function () {

cy.get(`[title="Selecting 2 AAs from 2 to 3"]`).should("exist");
});
it.skip(`selection layer should be updated correctly if inserting at the end of an AA seq`, () => {
// TNWTODO
cy.visit("/#/Editor?shortSeq=true&moleculeType=Protein");
cy.contains(".veRowViewPrimaryProteinSequenceContainer svg g", "V").click({
force: true
});

cy.get(".veRowViewCaret:first").trigger("contextmenu", { force: true });
cy.contains(".bp3-menu-item", "Replace").click();
cy.contains("Press ENTER");
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(0);
cy.get(".sequenceInputBubble input").type("rggta{enter}");
//we don't want to see the insert successful message because no bps were entered
cy.contains("Sequence Inserted Successfully");
cy.contains("Selecting 5 AAs from 14 to 18");
});
it(`should be able to delete correctly when backspace/del pressed`, () => {
cy.visit("/#/Editor?moleculeType=Protein");
cy.contains(".veRowViewPrimaryProteinSequenceContainer svg g", "M").click({
force: true
});
Expand All @@ -105,6 +124,7 @@ describe("proteinEditor", function () {
cy.contains("Length: 1383 AAs");
});
it(`should be able to cut /* todo: and paste */ correctly`, () => {
cy.visit("/#/Editor?moleculeType=Protein");
cy.get(".veRowViewPartsContainer")
.contains("Part 0")
.first()
Expand Down Expand Up @@ -134,7 +154,8 @@ describe("proteinEditor", function () {
});

it(`goTo, rotateTo work
-can't go to a position outside of the sequence
cy.visit("/#/Editor?moleculeType=Protein");
-can't go to a position outside of the sequence
-can go to a position inside the sequence
// -can rotate the sequence to that position
`, () => {
Expand All @@ -157,14 +178,16 @@ describe("proteinEditor", function () {
});

it(`can move the caret around correctly`, () => {
cy.visit("/#/Editor?moleculeType=Protein");
cy.contains(".veRowViewPrimaryProteinSequenceContainer svg g", "M").click({
force: true
});
cy.focused().type("{rightarrow}{rightarrow}{rightarrow}");
cy.contains("Caret Between AAs 3 and 4");
});
it(`
-can find AA's by default in the search bar
cy.visit("/#/Editor?moleculeType=Protein");
-can find AA's by default in the search bar
`, () => {
cy.get(`[data-test="ve-find-tool-toggle"]`).click().focused().type("mmh");
Expand All @@ -183,7 +206,8 @@ describe("proteinEditor", function () {
cy.contains("Selecting 5 AAs from 1 to 5");
});
it(`should
-has 1, 5, 10 AA's in the rowview axis
cy.visit("/#/Editor?moleculeType=Protein");
-has 1, 5, 10 AA's in the rowview axis
-can click an AA and have the selecting message display correctly
-not show circularity/cutsite/orf/translations tools or properties
`, () => {
Expand Down Expand Up @@ -227,7 +251,8 @@ describe("proteinEditor", function () {
});

it(`should
-show the AA count
cy.visit("/#/Editor?moleculeType=Protein");
-show the AA count
-the protein seq should be the primary sequence displayed
-not show any dna sequence by default
-should not show options to update restriction enzymes or simulate digestion
Expand Down
29 changes: 25 additions & 4 deletions packages/ove/demo/src/EditorDemo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ import _chromData from "../../../scratch/ab1ParsedGFPvv50.json";
import { convertBasePosTraceToPerBpTrace } from "@teselagen/bio-parsers";
import { defaultToolList } from "../../../src/ToolBar";
const chromData = convertBasePosTraceToPerBpTrace(_chromData);
const exampleProteinDataShort = {
name: "exampleProteinDataShort",
isProtein: true,
proteinSequence: "mmhlrlfcillaavs"
};
const exampleSequenceDataShort = {
name: "exampleSequenceDataShort",
sequence: "gtagagagagcc"
};

const MyCustomTab = connectToEditor(({ sequenceData = {} }) => {
//you can optionally grab additional editor data using the exported connectToEditor function
Expand Down Expand Up @@ -100,6 +109,7 @@ const defaultState = {
beforeSequenceInsertOrDelete: false,
beforeSequenceInsertOrDeleteAsync: false,
maintainOriginSplit: false,
shortSeq: false,
maxAnnotationsToDisplayAdjustment: false,
truncateLabelsThatDoNotFit: true,
withPartTags: true,
Expand Down Expand Up @@ -468,6 +478,10 @@ This feature requires beforeSequenceInsertOrDelete toggle to be true to be enabl
\`\`\`
`
}),
renderToggle({
that: this,
type: "shortSeq"
}),
renderToggle({
that: this,
type: "onCopy"
Expand Down Expand Up @@ -700,9 +714,14 @@ certain dna specific tools and annotations are automatically disabled when isPro
if (val === "Protein") {
updateEditor(store, "DemoEditor", {
readOnly: false,
sequenceData: tidyUpSequenceData(exampleProteinData, {
convertAnnotationsFromAAIndices: true
})
sequenceData: tidyUpSequenceData(
this.state.shortSeq
? exampleProteinDataShort
: exampleProteinData,
{
convertAnnotationsFromAAIndices: true
}
)
});
} else if (val === "RNA") {
updateEditor(store, "DemoEditor", {
Expand Down Expand Up @@ -738,7 +757,9 @@ certain dna specific tools and annotations are automatically disabled when isPro
) {
updateEditor(store, "DemoEditor", {
readOnly: false,
sequenceData: exampleSequenceData
sequenceData: this.state.shortSeq
? exampleSequenceDataShort
: exampleSequenceData
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ove/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@teselagen/ove",
"version": "0.7.15",
"version": "0.7.16",
"main": "./src/index.js",
"type": "module",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/range-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@teselagen/range-utils",
"version": "0.3.7",
"version": "0.3.9",
"type": "module",
"dependencies": {
"lodash-es": "^4.17.21"
Expand Down
1 change: 1 addition & 0 deletions packages/range-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ export { default as trimRangeByAnotherRange } from "./trimRangeByAnotherRange";
export { default as zeroSubrangeByContainerRange } from "./zeroSubrangeByContainerRange";
export { default as adjustRangeToRotation } from "./adjustRangeToRotation";
export { default as getZeroedRangeOverlaps } from "./getZeroedRangeOverlaps";
export { default as trimAnnStartEndToFitSeqLength } from "./trimAnnStartEndToFitSeqLength";
9 changes: 9 additions & 0 deletions packages/range-utils/src/trimAnnStartEndToFitSeqLength.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function trimAnnStartEndToFitSeqLength(
annStartOrEnd,
sequenceLength
) {
return Math.max(
0,
Math.min(annStartOrEnd || 0, Math.max(sequenceLength - 1, 0))
);
}
35 changes: 35 additions & 0 deletions packages/range-utils/src/trimAnnStartEndToFitSeqLength.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import trimAnnStartEndToFitSeqLength from "./trimAnnStartEndToFitSeqLength";

describe("trimAnnStartEndToFitSeqLength", () => {
test("should return 0 if annStartOrEnd is undefined", () => {
expect(trimAnnStartEndToFitSeqLength(undefined, 10)).toBe(0);
});

test("should return 0 if annStartOrEnd is null", () => {
expect(trimAnnStartEndToFitSeqLength(null, 10)).toBe(0);
});

test("should return 0 if annStartOrEnd is less than 0", () => {
expect(trimAnnStartEndToFitSeqLength(-5, 10)).toBe(0);
});

test("should return annStartOrEnd if it is within the sequence length", () => {
expect(trimAnnStartEndToFitSeqLength(5, 10)).toBe(5);
});

test("should return sequenceLength - 1 if annStartOrEnd is greater than sequenceLength", () => {
expect(trimAnnStartEndToFitSeqLength(15, 10)).toBe(9);
});

test("should return 0 if sequenceLength is 0", () => {
expect(trimAnnStartEndToFitSeqLength(5, 0)).toBe(0);
});

test("should return 0 if sequenceLength is negative", () => {
expect(trimAnnStartEndToFitSeqLength(5, -10)).toBe(0);
});

test("should return 0 if annStartOrEnd is 0", () => {
expect(trimAnnStartEndToFitSeqLength(0, 10)).toBe(0);
});
});
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@teselagen/ui",
"version": "0.7.17",
"version": "0.7.18",
"main": "./src/index.js",
"type": "module",
"exports": {
Expand Down

0 comments on commit a8fc851

Please sign in to comment.