Giter Site home page Giter Site logo

lattice-automation / seqviz Goto Github PK

View Code? Open in Web Editor NEW
227.0 12.0 49.0 114.99 MB

a JavaScript DNA, RNA, and protein sequence viewer

Home Page: https://tools.latticeautomation.com/seqviz

License: MIT License

JavaScript 0.87% TypeScript 98.92% Shell 0.21%
dna igem synthetic-biology vector plasmid rna biology protein

seqviz's Introduction

SeqViz is a DNA, RNA, and protein sequence viewer.

Used By

                               

Table of Contents

Demo

You can see a demo at tools.latticeautomation.com/seqviz. The source is in /demo.

Features

Linear and Circular Sequence Viewers

  • Annotations, primers, and highlights with names and colors
  • Amino acid translations
  • Enzyme cut sites
  • Searching with mismatches and highlighting

Sequence and Element Selection

  • Selecting a range on the viewer(s), or clicking an annotation, translation, primer, cutSite, or searchResult, highlights the selection and passes it to the onSelection() callback.

Usage

Installation

npm

npm install seqviz

CDN

<script src="https://unpkg.com/seqviz"></script>

Instantiation

React

import { SeqViz } from "seqviz";

export default () => (
  <SeqViz
    name="J23100"
    seq="TTGACGGCTAGCTCAGTCCTAGGTACAGTGCTAGC"
    annotations={[{ name: "promoter", start: 0, end: 34, direction: 1, color: "blue" }]}
  />
);

Non-React

More details are in the Viewer without React section.

<script>
  window.seqviz
    .Viewer("root", {
      name: "L09136",
      seq: "tcgcgcgtttcggtgatgacggtgaaaacctctgacacatgca",
      style: { height: "100vh", width: "100vw" },
    })
    .render();
</script>

Props

All the following are usable as props for the React component (seqviz.SeqViz) or as options for the plain JS implementation (seqviz.Viewer()).

Required

seq (='')

A sequence to render. Can be a DNA, RNA, or amino acid sequence.

File or Accession

These props are @deprecated and may be removed in a future major release. We recommend parsing sequence files outside of SeqViz with the seqparse package.

  • file is a FASTA, GenBank, SnapGene, JBEI, or SBOL file (string | File)
  • accession is an NCBI accession-ID (string)

For example:

import seqparse from "seqparse";

export default () => {
  const [seq, setSeq] = useState({ name: "", seq: "", annotations: [] });

  // fetch and parse a sequence from NCBI: https://www.ncbi.nlm.nih.gov/nuccore/MN623123.1
  useEffect(async () => setSeq(await seqparse("MN623123.1")));

  return <SeqViz name={seq.name} seq={seq.seq} annotations={seq.annotations} />;
};

Optional

viewer (='both')

The type and orientation of the sequence viewers. One of "linear" | "circular" | "both" | "both_flip". both means the circular viewer fills the left side of SeqViz, and the linear viewer fills the right. both_flip is the opposite: the linear viewer is on the left, and the circular viewer is on the right.

name (='')

The name of the sequence/plasmid. Shown at the center of the circular viewer.

annotations (=[])

An array of Annotations to render. Each Annotation requires 0-based start (inclusive) and end (exclusive) indexes. names are rendered on top of the annotations. Set the annotation's direction to 1 for forward arrows and -1 for reverse arrows.

annotations = [
  { start: 0, end: 22, name: "Strong promoter", direction: 1 }, // [0, 22)
  { start: 23, end: 273, name: "GFP" },
  { start: 300, end: 325, name: "Weak promoter", direction: -1, color: "#FAA887" },
];

In the example above, the "Strong promoter" would span the first to twenty-second base pair.

primers (=[])

An array of Primers to render. Each Primer requires 0-based start (inclusive) and end (exclusive) indexes. names are rendered on top of the primers. Set the primer's direction to 1 for forward primer and -1 for reverse primer.

primers = [
  { start: 33, end: 53, name: "LacZ Foward Primer", direction: 1 },
  { start: 3098, end: 3128, name: "LacZ Reverse Primer", direction: -1, color: "#FAA887" },
];

In the example above, the forward and reverse primers of LacZ are define by the direction parameter. Notice that color could be used optionally.

translations (=[])

An array of translations: sequence ranges to translate and render as amino acids sequences. Requires 0-based start (inclusive) and end (exclusive) indexes relative the DNA sequence. A direction is required: 1 (FWD) or -1 (REV). It will also render a handle to select the entire range. A color is optional for the handle. If the empry string ("") is provided as the name, the handle will not be rendered.

translations = [
  { start: 0, end: 90, direction: 1, name: "ORF 1", color: "#FAA887" }, // [0, 90)
  { start: 191, end: 522, direction: -1, name: "" },
];

enzymes (=[])

An array of restriction enzymes to show recognition sites for. A list of pre-defined enzymes in src/enzymes.ts can be referenced by name. Example:

enzymes = [
  "EcoRI",
  "PstI",
  {
    name: "Cas9",
    rseq: "NGG", // recognition sequence
    fcut: 0, // cut index on FWD strand, relative to start of rseq
    rcut: 1, // cut index on REV strand, relative to start of rseq
    color: "#D7E5F0", // color to highlight recognition site with
    // (optional) only show recognition sites between 100th and 250th index [100, 250)
    range: {
      start: 100,
      end: 250,
    },
  },
];

highlights (=[])

Ranges of sequence to highlight. A default color from colors is used if none is provided.

highlights = [
  { start: 36, end: 66, color: "magenta" },
  { start: 70, end: 80 },
];

zoom (={ linear: 50 })

How zoomed the viewer(s) should be 0-100. Key'ed by viewer type, but only linear is supported.

colors (=[])

An array of colors to use for annotations, translations, and highlights. Defaults are in src/colors.ts.

bpColors (={})

An object mapping base pairs to their color. The key/bp is either a nucleotide type or 0-based index. Example:

bpColors = { A: "#FF0000", T: "blue", 12: "#00FFFF" };

style (={})

Style for seqviz's outer container div. Empty by default. Useful for setting the height and width of the viewer if the element around seqviz lacks one. For example:

style = { height: "100vh", width: "100vw" };

selection (={})

This (optional) selection prop is useful if you want to externally manage and set the selection state:

selection = {
  start: 133,
  end: 457,
  clockwise: true,
};

onSelection (=(_: Selection) => {})

A callback executed after selection events. It accepts a single Selection type argument.

This occurs after drag/drop selections and clicks. It will have meta on annotation, translation, enzyme, highlight or search elements if one was selected. The example below shows an annotation selection:

{
  "end": 457,
  "length": 324,
  "name": "lacZ fragment",
  "start": 133,
  "type": "ANNOTATION",
}

search (={})

Sequence search parameters. Takes a query sequence and the maximum allowable mismatch for a match (default: 0). Matches are highlighted.

search = { query: "aatggtctc", mismatch: 1 };

Searching supports wildcard symbols, e.g. { query: "AANAA" }. All symbols supported are in src/sequence.ts.

onSearch (=(_: Range) => {})

A callback executed after a search event. This is called once on initial render and every time the sequence changes thereafter. An example of search results is below:

[
  {
    start: 728,
    end: 733,
    direction: 1,
    index: 0,
  },
  {
    start: 1788,
    end: 1793,
    direction: -1,
    index: 1,
  },
];

copyEvent (=(e: KeyboardEvent) => e.key === "c" && (e.metaKey || e.ctrlKey))

A function returning whether to copy the viewer(s) current selection during a keyboard event. The default method copies sequence after any ctrl+c or meta+c keyboard events.

selectAllEvent (=(e: KeyboardEvent) => e.key === "a" && (e.metaKey || e.ctrlKey))

A function returning whether to select the whole sequence during a keyboard event. The default method select whole sequence after any ctrl+a or meta+a keyboard events.

showComplement (=true)

Whether to show the complement sequence.

rotateOnScroll (=true)

By default, the circular viewer rotates when scrolling over the viewer. That can be disabled with rotateOnScroll: false.

disableExternalFonts (=false)

If true, SeqViz will not download fonts from external sites. By default the library will attempt to download "Roboto Mono:300,400,500" after first mount.

refs (={ circular: undefined, linear: undefined })

See: custom viewer positioning

Custom Viewer Positioning

This makes use of the children and refs props to allow custom rendering of the sequence viewers. For example, to render the linear viewer above the circular viewer:

import { useRef } from "react";
import { Circular, Linear, SeqViz } from "seqviz";

export default () => {
  const circular = useRef();
  const linearRef = useRef();

  return (
    <SeqViz name="J23100" seq="TTGACGGCTAGCTCAGTCCTAGGTACAGTGCTAGC" refs={{ circular, linear }}>
      {({ circularProps, linearProps, ...props }) => (
        <div style={{ display: "flex", flexDirection: "column", width: "100%" }}>
          <div ref={linear} style={{ height: "25%", width: "100%" }}>
            <Linear {...linearProps} {...props} />
          </div>
          <div ref={circular} style={{ height: "75%", width: "100%" }}>
            <Circular {...circularProps} {...props} />
          </div>
        </div>
      )}
    </SeqViz>
  );
};

Without React

For usability in non-React apps, we provide a thin wrapper around the React component. The viewer's constructor accepts two arguments:

  • element: either an element id or an HTMLElement
  • props: props as documented above
const element = document.getElementById("root");
const viewer = seqviz.Viewer(element, props);
// Render the viewer to the DOM at the node passed in $element`.
viewer.render();
// To later update the viewer's configuration and re-renders.
viewer.setState(props);
// To render the viewer, eg for server-side rendering, and returns it as an HTML string.
viewer.renderToString();

Contact Us

This library is maintained by Lattice Automation.

You can report bugs and request features at Issues or contact us directly at [email protected]

seqviz's People

Contributors

bugzpodder avatar dependabot[bot] avatar digithed avatar eng-elias avatar guzmanvig avatar isaacguerreir avatar jcxldn avatar jjti avatar kevinwuhoo avatar leshane avatar ninjha01 avatar razzyoshi avatar rgavan-chr avatar zeptonaut avatar zeroaltitude avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

seqviz's Issues

Improve sequence selection meta labels size responsive

Sequence selection meta labels in the header can exceed allotted space and push into a new line creating unwanted UI problems. Handle the labels div exceeding the predefined width for their section by collapsing into a single label dropdown.

Refactor direction to int

Describe the feature you'd like added
Direction is "REVERSE", "NONE", "FORWARD". This is simpler as -1, 0, 1. Will leave support for the string flags to avoid breaking changes but will remove them from docs

(Optional) Describe examples of similar features elsewhere
This is how it's done in SBOL

Additional context
...

Allow viewer to export raw HTML for rendering

The viewer can currently render using ReactDOM or return the React component for the viewer. Returning the raw HTML for the viewer is not currently fully supported. The returned HTML should be sufficient to render a working viewer.

React component does not re-render when file prop changes

Hello,

Thank you for this really nice plasmid visualization tool.

I noticed that when the SeqViz components re-renders with a new file property, nothing changes. The first file value that was passed is the one getting rendered indefinitely.

This seems like a bug to me.

Add translations

Is your feature request related to a problem? Please describe.
Translations are absent from SeqViz. Are a way to visualize translated amino acid sequences. Should be exposed via something similar to the annotations schema.

Describe the solution you'd like

  • Be able to programmatically specify a translated region through a "translations" property on input
  • Be able to infer which open reading frames are large enough to automatically have translations shown (with a programmatically exposed default parameter)

Describe alternatives you've considered
Only ambiguity here is around:

  1. automatic inference open reading frames that should be translated (based on length, or length as a ratio of full sequence, or whether the sequence is just a single ORF)?
  2. whether we also want an ORF toggle. I put ORFs (different from translations) in Loom but that wasn't ported over either

Additional context
I already made this in Loom's sequence viewer, see screenshot below, but it wasn't copied over when parts of that viewer were made open-source.

Screen Shot 2019-10-22 at 11 06 05 AM

Add color-coded bp

Describe the feature you'd like added
Nucleotides should be color-codable for differentiation.

(Optional) Describe examples of similar features elsewhere
Benchling's circular viewer almost has this but not quite since the bp are shown are rectangles when zoomed in enough.

Screen Shot 2019-10-22 at 11 30 07 AM

Additional context
Will likely be added as a key-value object through input. Example below. Undefined colorings will remain black.

An alternative or secondary approach would be to have bpColors accept a boolean, and use the "colors" already passed for annotations to seed the bp colors.

{
    ...restOfOptions,
    bpColors: {
        A: "#ff0000",
        T: "#00ff00",
        G: "#ffa500",
        C: "#ffff00",
    }
}

Add primers to SeqViz

Is your feature request related to a problem? Please describe.

Add visualizations for primers in linear and circular viewer so that constructed parts can have their primers shown

Describe the solution you'd like

Port over visualization code for primers from Loom

Describe alternatives you've considered

None

Additional context

Added to support Gibson Tool demo, also requested by SeqViz Survey respondent.

Only print notice about loading part from cache once per part

Possibly/probably related to #13.

I'm noticing an excessive number of duplicate console log statements when interacting with the sequence viewers after initial load of a part + backbone. This message is only useful once, if necessary at all in production. I would consider removing entirely.

Sidebar enzyme selection TypeError bug

The error below was produced by opening SeqViz in Chrome (v. 79.0.3945.88), loading the default part K1598008, and click-selecting any of the enzymes in the sidebar.

react-dom.production.min.js:5940 Uncaught TypeError: e is not a function
at t.exports (seqviz.min.js:56)
at t.exports (seqviz.min.js:18)
at seqviz.min.js:56
at seqviz.min.js:56
at Array.reduce (<anonymous>)
at seqviz.min.js:56
at t.value (seqviz.min.js:56)
at Pi (react-dom.production.min.js:3785)
at Si (react-dom.production.min.js:3776)
at Ii (react-dom.production.min.js:3960)

Add back primers

Describe the bug
Primers aren't documented and their shape doesn't match other elements (namely "sequence" versus "seq").

Expected behavior
Should match other input elements and be better documented in the README

Sequences with only one annotation are not rendered correctly

Describe the bug
It looks like there is an issue rendering sequences with only one annotation. Sometimes the end of the annotation does not line up with the end of the sequence. Additionally, the direction is not represented and you can no longer click on it to select the whole sequence (though perhaps that is intended)

To Reproduce
The following props were passed into the component:

{
  "name": "BCDRBS_alt1_BD14",
  "seq": "gcgaaaaatcaataaggaggcaacaagatgtgcgaaaaacatcttaatcatgcggtggagggtttctaatg",
  "annotations": [
    {
      "start": 0,
      "end": 71,
      "direction": "FORWARD",
      "name": "RBS",
      "type": "RBS",
      "color": "#80D849"
    }
  ],
  "annotate": false,
  "searchQuery": {
    "query": "",
    "mismatch": 0
  },
  "translations": [],
  "viewer": "linear",
  "showComplement": true,
  "bpColors": {
    "a": "#000000",
    "t": "#000000",
    "c": "#000000",
    "g": "#000000"
  },
  "zoom": {
    "linear": 50
  },
  "accession": "",
  "backbone": "",
  "colors": [],
  "copySeq": {
    "key": "",
    "meta": false,
    "ctrl": false,
    "shift": false,
    "alt": false
  },
  "compSeq": "",
  "enzymes": [],
  "file": null,
  "onSearch": "onSearch()",
  "onSelection": "onSelection()",
  "searchNext": {
    "key": "",
    "meta": false,
    "ctrl": false,
    "shift": false,
    "alt": false
  },
  "showAnnotations": true,
  "showIndex": true,
  "showPrimers": true
}

Expected behavior
I expect the end of the sequence to line up with the end of the annotation and for the direction to be represented.

Additional context
Screen Shot 2019-12-11 at 11 54 51 AM

Thanks!

Add React Component interface

Describe the feature you'd like added
Interface right now is "JS-agnostic" but will add a simple import/export for the React component that's already used in viewer.js.

Slow demo load speed

Describe the bug
Demo page takes multiple seconds to load. Back button isn't working

To Reproduce
Steps to reproduce the behavior:

Example:

visit https://tools.latticeautomation.com/seqviz/?backbone=pSB1C3&biobrick=BBa_E0040

Expected behavior
Load quicker

Additional context
Add any other context about the problem here.

demo in vanilla js

Hi,
I'm trying to redo the show meta from demo but in vanilla js im encourtering some trouble to do so because the tutorial is made for react. Could it be possible to do the demo in vanilla js ?

Viewer is too short

Describe the bug
Viewer is too short

To Reproduce
See screenshot

Expected behavior
Should have padding below the last SeqBlock

Screenshots
Screen Shot 2019-12-05 at 11 19 36 AM

Make sure the library only re-renders what changes

I am experiencing noticeable lag when interacting with the rendered sequence viewers. There may be a full viewer re-render for every drag-select highlight movement made. This would cause the viewers to re-render excessively and cause lag. If this is the cause, this should be resolved.

Add Lattice branding and Links out

Include a section about SeqViz being "powered by Lattice" with a Lattice brand, link to the SeqViz library repo, Documentation (if appropriate), and some contact details.

Viewer cut short within some containers

Describe the bug
Viewer is being cut short: not all SeqBlocks are being rendered

To Reproduce
Wrap in another div that doesn't fill vertical space of the viewer?

Additional context
unnamed

Annotation end does not line up with sequence

Describe the bug
When rendering seqviz with a longer sequence and annotation, the end of the annotation and sequence do not line up.

To Reproduce
Steps to reproduce the behavior:

  • Replicable with the following part:
annotations: Array(1)
    0:
        color: "#80D849"

        direction: "REVERSE"

        end: 266
        
name: "Promoter"

        start: 0

        type: "PROMOTER"
name: "pC^rbs"

seq: "tgccgatacaagaacaacagcgcgttgagcgcctgccggtgggtggccggcgccacttgcttctcggtggcgagcatggtcagaaaaccctcgacttcagcttgccccatttcgcgcggatgtcgaaacccaccaaggctgcgggccgtccacaacacaaatgccttggcccagtagacataagccttctcggtctgtaggctgtaatgcaggtagcgaacccgttcaagaaataattttgtttaactttaagaaggagatatacat"

Expected behavior
The end of the sequence and the end of the annotation should line up assuming the endIndex is the same length as the sequence - 1.

Screenshots
Screen Shot 2019-12-04 at 2 12 34 PM

Desktop (please complete the following information):

  • OS: iOS
  • Browser: Chrome
  • Version: 78

Refactor `part` input prop into `accession` and `seq`

Describe the feature you'd like added

Rather than part being a catch-all for an object, accession, iGEM name, etc. might be easier if SeqViz accepts either an NCBI accession/iGEM id as "accession" string prop, or each of the part properties independently. Example:

<SeqViz name="plasmid_name" seq="ATGATAG" annotations={[]} />

OR

<SeqViz accession="BBa_B00015" />

Additional context
This change will be breaking but will reduce a lot of defensive code and, imo, make the props' purpose more obvious, rather than having part which is a weird amalgum of string/id/sequence/part-object. It's doing too much imo

Annotation extends too far with short sequences

Describe the bug
For sequences that have a length shorter than the first row, the annotation extends past the end of the sequence to the end of the row.

To Reproduce
Using part:
Screen Shot 2019-12-06 at 2 33 43 PM

Results in:
Screen Shot 2019-12-06 at 2 34 24 PM

Expected behavior
I expect the annotation to only extend to the length of the sequence.

Add a check for zero height or width

SeqViz uses React SizeMe to calculate its viewer(s) heights. If the element that contains SeqViz lacks a defined height or width, there's a good change SeqViz will as well. This can be addressed by a user by either:

  1. Giving an expanded height + width to the element that contains SeqViz or
  2. Passing an options.style down to SeqViz that manually sets its height and width

I'll add a check within SeqViz that will throw a warning/error (undecided) if the height or width is detected to be zero.

Slow down scroll

Scroll rate on edge of the sequence viewer is too fast now imo

Changing bpColors does not immediately re-render

Describe the bug
When toggling bpColors on and off, the colors do not appear until you scroll down to view parts of the sequence that are not currently visible.

To Reproduce
Steps to reproduce the behavior:

  • Create a toggle to turn bpColors on and off
  • When toggling, see the colors don't immediately change

Expected behavior
The colors should immediately change when toggling bpColors on and off

Screenshots
Screen Shot 2019-12-04 at 10 55 37 AM

Desktop (please complete the following information):

  • OS: iOS
  • Browser: Chrome
  • Version: 78

Add RNA support

Mostly minor changes required:

  • add RNA tests for filesToParts.js
  • refactor search to also support RNA characters

Add to npm

Describe the feature you'd like added
Distribute through NPM in addition to the CDN. Simplfying installation instructions.

CDN not working

Hi All,

I would like to use this package via CDN. However, the provided link gives the following error:

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>344D8B9144E39E40</RequestId>
<HostId>
FBex/FohCVLEi3j0GjvWRhgpJDKzQxbxlldjRz1oilArV3gEL1S7KfJeTB2SAJg5she9DAE97As=
</HostId>
</Error>

Have I misunderstood something and it is only a package for internal use, or is this really an error?

Thank you!

Unnecessary re-renders on selection

Describe the bug
During a sequence selection, almost every SeqBlock in Linear is re-rendered. Only the Selection blocks/edges need to be updating. This causes a perceptable lag, particulary when translations are shown on the viewer as well.

To Reproduce
Add translations and start quickly making selections on linear

Expected behavior
Selection should be an instantaneous as the cursor movement

Add more Viewer level integration tests

Should add more tests to ensure that the viewer renders without breaking to viewer.test.js.

  • Render with PUC, predefined part as input
  • Render with iGEM part input through the accession input
  • Render followed by setState to update bpColors
  • Render without an annotations array, just seq and name
  • Render with window.File input:
    • Genbank
    • Fasta
    • SBOL
    • Snapgene
  • Render with a zoom outside the 0-100 range

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.