Help - Alignment GUI components

From LibrAlign Documentation

The two most important GUI components in LibrAlign are AlignmentArea which displays a multiple sequence alignment including attached data areas and MultipleAlignmentsContainer which allows to combine several AlignmentArea instances.

Using AlignmentArea

The documentation of the AlignmentArea class can be found in its API documentation. This article describes in addition how to use AlignmentArea together with related classes to display a multiple sequence alignment.

Basic example

The following code would be needed to create an alignment area, that is used as a stand-alone component.


AlignmentArea area = new AlignmentArea();
area.setAlignmentModel(new PackedAlignmentModel<Character>(CharacterTokenSet.newNucleotideInstance()), false);  // Define a model


After a new instance was created, an associated model needs to be defined. In this case a PackedAlignmentModel was used. As its token set java characters representing nucleotides were selected. (See Alignment and data models for details.) The alignment model currently does not contain any sequences, but could already be modified by the user.

Using token painters

A TokenPainter is needed to determine the way tokens are displayed by an AlignmentArea. Since we are using nucleotide data in this example, we replace the default painter by a NucleotideTokenPainter.


area.getPaintSettings().getTokenPainterList().set(0, new NucleotideTokenPainter());  // Define how sequences shall be painted


Token painters used by an AlignmentArea are stored in the associated PaintSettings instance, which can store a whole list of token painters. This is only relevant if an ConcatenatedAlignmentModel is used. In all other cases that list contains only one element, which is why we replace the first element of the list (with the index 0) here.

The list length of token painters is automatically updated by LibrAlign every time AlignmentModel.setAlignmentModel() is called. If no previous model was defined for a position in the list, an instance of the default token painter is added (usually SingleColorTokenPainter). In order to use the default nucleotide colors here, we replaced that default painter by a NucleotideTokenPainter.

Adding data areas

Using MultipleAlignmentsContainer

See also