Skip to content

Multiple Sequence Alignment

This example visualizes the 16SRNA_Deino_87seq.aln nucleotide alignment used in the NCBI Multiple Sequence Alignment Viewer tutorial. The top track is a sequence logo that summarizes the bases and information content at each alignment position. The lower track shows the aligned bases for each sequence, with zoom-dependent labels.

{
  "description": [
    "Multiple Sequence Alignment",
    "Visualizes the 16SRNA_Deino_87seq nucleotide alignment with a sequence logo showing per-position information content and a zoomable base-by-base alignment.",
    "Data source: 16SRNA_Deino_87seq.aln from NCBI's Multiple Sequence Alignment Viewer tutorial and NCBI FTP. NCBI places no restrictions on use or distribution of molecular data in its databases, but original submitters may hold third-party intellectual-property rights."
  ],

  "data": {
    "url": "https://data.genomespy.app/sample-data/16SRNA_Deino_87seq.aln",
    "format": {
      "type": "fasta"
    }
  },

  "transform": [{ "type": "flattenSequence" }],

  "encoding": {
    "color": {
      "field": "sequence",
      "type": "nominal",
      "scale": {
        "type": "ordinal",
        "domain": ["A", "C", "T", "G", "-"],
        "range": ["#7BD56C", "#FF9B9B", "#86BBF1", "#FFC56C", "#f5f5f5"]
      }
    }
  },

  "scales": {
    "x": {
      "domain": [190, 230],
      "zoom": { "extent": "data" }
    }
  },

  "resolve": {
    "scale": { "x": "shared" },
    "axis": { "x": "independent" }
  },

  "vconcat": [
    {
      "height": 50,

      "transform": [
        {
          "type": "aggregate",
          "groupby": ["pos", "sequence"]
        },
        {
          "type": "formula",
          "expr": "datum.sequence == '-' ? null : datum.sequence",
          "as": "sequence"
        },
        {
          "type": "stack",
          "field": "count",
          "groupby": ["pos"],
          "offset": "information",
          "as": ["_y0", "_y1"],
          "baseField": "sequence",
          "sort": { "field": "count", "order": "ascending" }
        }
      ],
      "encoding": {
        "x": { "field": "pos", "type": "index", "axis": null },
        "y": {
          "field": "_y0",
          "type": "quantitative",
          "scale": { "domain": [0, 2] },
          "title": "Information"
        },
        "y2": { "field": "_y1" },
        "text": { "field": "sequence", "title": "base" }
      },
      "stops": [0.25],
      "multiscale": [
        {
          "name": "Sequence logo overview",
          "layer": [
            {
              "mark": {
                "type": "text",
                "font": "Source Sans Pro",
                "fontWeight": 700,
                "size": 100,
                "squeeze": true,
                "fitToBand": true,

                "paddingX": 0,
                "paddingY": 0,

                "logoLetters": true
              }
            },
            {
              "mark": "rect"
            }
          ]
        },
        {
          "name": "Sequence logo detail",
          "mark": {
            "type": "text",
            "font": "Source Sans Pro",
            "fontWeight": 700,
            "size": 100,
            "squeeze": true,
            "fitToBand": true,

            "paddingX": 0,
            "paddingY": 0,

            "logoLetters": true
          }
        }
      ]
    },
    {
      "height": { "step": 13 },
      "viewportHeight": "container",

      "view": { "stroke": "lightgray" },

      "encoding": {
        "x": { "field": "pos", "type": "index" },
        "y": {
          "field": "identifier",
          "type": "nominal",
          "axis": { "maxExtent": 90, "title": null }
        }
      },
      "layer": [
        {
          "mark": "rect"
        },
        {
          "mark": {
            "type": "text",
            "size": 11,
            "fitToBand": true,
            "paddingX": 1.5,
            "paddingY": 1,
            "opacity": 0.7
          },
          "encoding": {
            "color": { "value": "black" },
            "text": { "field": "sequence", "title": "base" }
          }
        }
      ]
    }
  ],

  "config": { "legend": { "disable": true } }
}

The alignment file 16SRNA_Deino_87seq.aln is identified by the NCBI tutorial and is available from the NCBI FTP server. NCBI states that it places no restrictions on the use or distribution of molecular data in its databases, but original submitters may claim intellectual-property rights in submitted data. This dataset is used here for demonstration and visualization purposes.

What to notice

The sequence logo encodes the frequency of each base in a column and uses the stack transform's information-content offset to make conserved positions taller. Its multiscale overview includes colored rectangles behind the logo letters; those rectangles fade out as the view reaches base-level detail. Gap characters are omitted from the logo letters but still affect the information content calculation. The lower alignment track preserves one row per input sequence and colors bases and gaps separately.

The initial view focuses on alignment positions 190–230. Pan and zoom to move through the full alignment. At higher zoom levels, the base letters fit inside their position bands and become readable; at lower zoom levels, the colored rectangles provide a compact overview.

GenomeSpy Features

This example combines several GenomeSpy capabilities in one alignment view:

  • FASTA data loads the aligned sequences with their identifiers.
  • flattenSequence expands each sequence into one row per aligned position.
  • aggregate, formula, and stack count bases and prepare the sequence-logo layout.
  • multiscale cross-fades the sequence-logo overview and detail levels according to units per pixel.
  • text uses logoLetters and fitToBand to render bases inside their stacked or aligned position bands.
  • vconcat keeps the information logo and sequence alignment in separate tracks while sharing the x scale.