Skip to content

Commit

Permalink
Add bioSyntax color schemes as sequence alignment renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
hlfernandez committed Oct 4, 2018
1 parent 7b525ec commit fb35fed
Show file tree
Hide file tree
Showing 10 changed files with 365 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

import javax.swing.JFrame;

import org.sing_group.gc4s.msaviewer.BaseColorSequenceAlignmentRenderer;
import org.sing_group.gc4s.msaviewer.BioSyntaxBaseColorScheme;
import org.sing_group.gc4s.msaviewer.MultipleSequenceAlignmentTracksModel;
import org.sing_group.gc4s.msaviewer.MultipleSequenceAlignmentViewerConfiguration;
import org.sing_group.gc4s.msaviewer.MultipleSequenceAlignmentViewerControl;
Expand Down Expand Up @@ -153,12 +155,16 @@ public List<Track> getBottomTracks() {
return emptyList();
}
};

// For this second model, a BaseColorSequenceAlignmentRenderer will be created using
// a predefined color scheme provided by the BioSyntaxColorScheme.
SequenceAlignmentRenderer model2Renderer = new BaseColorSequenceAlignmentRenderer(new BioSyntaxBaseColorScheme());

// Now, a map is created to associate SequenceAlignmentRenderers to
// MultipleSequenceAlignmentTracksModel. In this case, a renderer is
// only associated to the first model.
// Now, a map is created to associate the SequenceAlignmentRenderer objects to
// their corresponding MultipleSequenceAlignmentTracksModel objects.
Map<MultipleSequenceAlignmentTracksModel, SequenceAlignmentRenderer> renderersMap = new HashMap<>();
renderersMap.put(model1, model1Renderer);
renderersMap.put(model2, model2Renderer);

// Then, a MultipleSequenceAlignmentViewerConfiguration is created to
// set the initial configuration of the viewer. This is optional since
Expand Down
5 changes: 4 additions & 1 deletion gc4s-multiple-sequence-alignment-viewer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ The `gc4s-multiple-sequence-alignment-viewer-demo` provides different examples o

![MultipleSequenceAlignmentViewerPanel](screenshots/MultipleSequenceAlignmentViewerPanel.png)

This module also provides the [bioSyntax](https://biosyntax.org/) nucleotide colouring scheme for the complete IUPAC ambiguous base set.

![MultipleSequenceAlignmentViewerPanel with bioSyntax colouring scheme](screenshots/MultipleSequenceAlignmentViewerPanel_bioSyntax.png)

Using this module
-----------------------
Add the following repository and dependency declarations to your `pom.xml`:
Expand Down Expand Up @@ -88,5 +92,4 @@ public class MinimalMultipleSequenceAlignmentViewerPanelDemo {
showComponent(viewerPanel, JFrame.MAXIMIZED_BOTH);
}
}

```
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* #%L
* GC4S multiple sequence alignment viewer
* %%
* Copyright (C) 2014 - 2018 Hugo López-Fernández, Daniel Glez-Peña, Miguel Reboiro-Jato,
* Florentino Fdez-Riverola, Rosalía Laza-Fidalgo, Reyes Pavón-Rial
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
package org.sing_group.gc4s.msaviewer;

import java.awt.Color;
import java.util.function.Function;

/**
* The interface that defines a color scheme used by a {@code BaseColorSequenceAlignmentRenderer}.
*
* @author hlfernandez
*
*/
public interface BaseColorScheme {
/**
* Returns a function that returns a background {@code Color} for each sequence base {@code Character}.
*
* @return a function that returns a background {@code Color} for each sequence base {@code Character}
*/
Function<Character, Color> getBaseBackgroundColorFunction();

/**
* Returns a function that returns a foreground {@code Color} for each sequence base {@code Character}.
*
* @return a function that returns a foreground {@code Color} for each sequence base {@code Character}
*/
Function<Character, Color> getBaseForegroundColorFunction();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* #%L
* GC4S multiple sequence alignment viewer
* %%
* Copyright (C) 2014 - 2018 Hugo López-Fernández, Daniel Glez-Peña, Miguel Reboiro-Jato,
* Florentino Fdez-Riverola, Rosalía Laza-Fidalgo, Reyes Pavón-Rial
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
package org.sing_group.gc4s.msaviewer;

import static java.util.Optional.of;

import java.awt.Color;
import java.util.Optional;
import java.util.function.Function;

/**
* A {@code DefaultSequenceAlignmentRenderer} implementation that renders each
* sequence base using the color specified by the {@code BaseColorScheme}.
*
* @author hlfernandez
* @see BaseColorScheme
* @see DefaultSequenceAlignmentRenderer
*
*/
public class BaseColorSequenceAlignmentRenderer extends DefaultSequenceAlignmentRenderer {
private Function<Character, Color> backgroundColorProvider;
private Function<Character, Color> foregroundColorProvider;

/**
* Creates a new {@code BaseColorSequenceAlignmentRenderer} with the specified {@code colorScheme}.
*
* @param colorScheme the {@code BaseColorScheme} to render sequence bases
*/
public BaseColorSequenceAlignmentRenderer(
BaseColorScheme colorScheme
) {
this.backgroundColorProvider = colorScheme.getBaseBackgroundColorFunction();
this.foregroundColorProvider = colorScheme.getBaseForegroundColorFunction();
}

@Override
public Optional<SequenceBaseRenderingInfo> render(Sequence sequence, int position) {
Character base = sequence.getSequence().charAt(position);
return of(
new SequenceBaseRenderingInfo(this.backgroundColorProvider.apply(base), this.foregroundColorProvider.apply(base), false, false)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* #%L
* GC4S multiple sequence alignment viewer
* %%
* Copyright (C) 2014 - 2018 Hugo López-Fernández, Daniel Glez-Peña, Miguel Reboiro-Jato,
* Florentino Fdez-Riverola, Rosalía Laza-Fidalgo, Reyes Pavón-Rial
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
package org.sing_group.gc4s.msaviewer;

import static java.awt.Color.decode;

import java.awt.Color;
import java.util.HashMap;
import java.util.Map;

/**
* An {@code DefaultBaseColorScheme} extension that returns the bioSyntax color scheme (https://biosyntax.org/,
* https://doi.org/10.1186/s12859-018-2315-y).
*
* @author hlfernandez
*
*/
public class BioSyntaxBaseColorScheme extends DefaultBaseColorScheme {
public static final Map<Character, Color> BIO_SYNTAX_COLOR_SCHEME = new HashMap<>();

static {
BIO_SYNTAX_COLOR_SCHEME.put('A', decode("#47ff19"));
BIO_SYNTAX_COLOR_SCHEME.put('G', decode("#f09000"));
BIO_SYNTAX_COLOR_SCHEME.put('C', decode("#ff4641"));
BIO_SYNTAX_COLOR_SCHEME.put('T', decode("#4192ff"));

BIO_SYNTAX_COLOR_SCHEME.put('U', decode("#8a89ff"));

BIO_SYNTAX_COLOR_SCHEME.put('R', decode("#fffe80"));
BIO_SYNTAX_COLOR_SCHEME.put('S', decode("#ff9b80"));
BIO_SYNTAX_COLOR_SCHEME.put('Y', decode("#e180ff"));
BIO_SYNTAX_COLOR_SCHEME.put('W', decode("#80fff2"));

BIO_SYNTAX_COLOR_SCHEME.put('D', decode("#c7ffb9"));
BIO_SYNTAX_COLOR_SCHEME.put('V', decode("#ffe3b9"));
BIO_SYNTAX_COLOR_SCHEME.put('B', decode("#f8c1c0"));
BIO_SYNTAX_COLOR_SCHEME.put('H', decode("#bfd8f9"));

BIO_SYNTAX_COLOR_SCHEME.put('X', decode("#e6e6e6"));
BIO_SYNTAX_COLOR_SCHEME.put('N', decode("#ffffff"));
BIO_SYNTAX_COLOR_SCHEME.put('M', decode("#83831f"));
BIO_SYNTAX_COLOR_SCHEME.put('K', decode("#8b4915"));
}

/**
* Creates a new {@code BioSyntaxBaseColorScheme} instance.
*/
public BioSyntaxBaseColorScheme() {
super(asFunction(BIO_SYNTAX_COLOR_SCHEME), (Character c) -> Color.BLACK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* #%L
* GC4S multiple sequence alignment viewer
* %%
* Copyright (C) 2014 - 2018 Hugo López-Fernández, Daniel Glez-Peña, Miguel Reboiro-Jato,
* Florentino Fdez-Riverola, Rosalía Laza-Fidalgo, Reyes Pavón-Rial
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
package org.sing_group.gc4s.msaviewer;

import static java.awt.Color.decode;

import java.awt.Color;
import java.util.HashMap;
import java.util.Map;

/**
* An {@code DefaultBaseColorScheme} extension that returns the bioSyntax color scheme (https://biosyntax.org/,
* https://doi.org/10.1186/s12859-018-2315-y).
*
* @author hlfernandez
*
*/
public class BioSyntaxHighContrastBaseColorScheme extends DefaultBaseColorScheme {
public static final Map<Character, Color> BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST = new HashMap<>();

static {
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST.put('A', decode("#d1d1d1"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST.put('G', decode("#fe3101"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST.put('C', decode("#010101"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST.put('T', decode("#4091fe"));

BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST.put('U', decode("#495bfe"));

BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST.put('R', decode("#f399cd"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST.put('S', decode("#7c0101"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST.put('Y', decode("#00007d"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST.put('W', decode("#7cc7fe"));

BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST.put('D', decode("#edb78d"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST.put('V', decode("#fe6331"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST.put('B', decode("#8a4814"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST.put('H', decode("#bed7f8"));

BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST.put('X', decode("#ffffff"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST.put('N', decode("#ffffff"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST.put('M', decode("#fefd7f"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST.put('K', decode("#9208a0"));
}

public static final Map<Character, Color> BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND = new HashMap<>();

static {
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND.put('A', decode("#010101"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND.put('G', decode("#010101"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND.put('C', decode("#fefefe"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND.put('T', decode("#fefefe"));

BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND.put('U', decode("#fefefe"));

BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND.put('R', decode("#010101"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND.put('S', decode("#fefefe"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND.put('Y', decode("#fefefe"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND.put('W', decode("#010101"));

BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND.put('D', decode("#fefefe"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND.put('V', decode("#fefefe"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND.put('B', decode("#fefefe"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND.put('H', decode("#010101"));

BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND.put('X', decode("#828282"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND.put('N', decode("#828282"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND.put('M', decode("#010101"));
BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND.put('K', decode("#010101"));
}

public BioSyntaxHighContrastBaseColorScheme() {
super(
asFunction(BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST), asFunction(BIO_SYNTAX_COLOR_SCHEME_HIGH_CONTRAST_FOREGROUND)
);
}
}
Loading

0 comments on commit fb35fed

Please sign in to comment.