Print or save the "Overview" window of the aligned sequences

Hello all,

I want to create a heatmap of 100s of files, each containing six aligned fasta sequences. The “overview” tool of jalview is great for visualizing the different features of the sequences and can theoretically be also used as a heatmap. I was wondering if it is possible to save/print the overview window. I tried taking a screenshot but the resolution is not great.

Perhaps using some commandline tool?

Many thanks for your help!

Abhishek

Hi Abhishek,

There isn’t currently a direct way to do this with command line arguments, but it would be possible to do with a groovy script. I’ve written up such a script which I think will do what you’re after.

To get a colour scheme to automatically apply go to ToolsPreferences and change settings in the Visual and Colours tab (and also the Overview tab). Click OK to save these preferences, which will then be used by default when any new files are opened. If you want to save your original settings, make a copy of ~/.jalview_properties before making the changes and then move it back when you’ve finished.

For efficiency, it’s best to run through all the files in one instance of Jalview (otherwise the Java Virtual Machine will have to start every time which would take forever for hundreds of files!) so I’ve added that loop into the groovy script too.

For this to work:

  1. First of all put all your fasta files into a single folder, say /home/user/fafolder.
  2. Then save the following script as a text file, called (e.g.) faToOverviewPNG.groovy and change the path for faFolder near the top of the script to the folder you put the fasta files into. Also change the value of extension to match the extension you used for your fasta files (if you didn’t use “.fa”).
import java.awt.image.BufferedImage
import javax.imageio.ImageIO

def faFolder = new File("/home/user/fafolder")
def extension = ".fa"

for(def file: faFolder.listFiles()) {
    if (!file.getName().endsWith(extension))
      continue

    def loader = new jalview.io.FileLoader(false)
    def af = loader.LoadFileWaitTillLoaded(file, jalview.io.DataSourceType.FILE, null)
    def view = af.getCurrentView()
    view.setShowText(false)
    view.setShowAnnotation(false)
    af.overviewMenuItem_actionPerformed(null)
    def ov = af.alignPanel.getOverviewPanel()
    ov.progressPanel.setVisible(false);
    try {
      Thread.sleep(50)
    } catch(Exception e) {}
    ov.od.setBoxPosition(-100,-100,0,0)
    ov.repaint()
    def img = new BufferedImage(ov.getWidth(), ov.getHeight(), BufferedImage.TYPE_INT_RGB)
    ov.paint(img.getGraphics())
    def filename = file.getAbsolutePath()
    def pngFile = new File(filename.substring(0,filename.length() - extension.length())+".png")
    ImageIO.write(img, "png", pngFile)
    
    af.doDefaultCloseAction()    
}

Jalview.quit();
  1. Then you can launch Jalview on the command line with
jalview -nowebservicediscovery -groovy fafolderOverviewPNG.groovy

which will still open the GUI but launch straight into the groovy script. If you want to save the Visual and Colour preferences you’ve set for another time, you can copy ~/.jalview_properties to some other file and load that with -props some_other_file in addition to the arguments above.

As an alternative to using the command line you could launch Jalview the normal way, then open ToolsGroovy Console… and paste the script into the console (you will probably want to delete the Jalview.quit() line at the end!) and click on the Execute Groovy Script button to run it. This is good for debugging problems if you want to adjust the script too.

Let us know how you get on!

Ben

faToOverviewPNG.groovy.txt (1.1 KB)

PS The line view.setShowText(false) isn’t needed for the overview window, but could be used to make a similar PNG directly from the alignment window.

Hello Dr Soares

I tried the second method (open jalview application, launch groovy console and copy paste the script). The script throws up an error. I wish I had some experience with java to debug this. Really appreciate any help!

File format identified as Fasta
Exception whilst opening file '/Users/aaj30/Documents/ucam/faFolder/x1.fa
java.lang.NullPointerException
at javax.swing.DefaultDesktopManager.maximizeFrame(DefaultDesktopManager.java:131)
at javax.swing.plaf.basic.BasicInternalFrameUI.maximizeFrame(BasicInternalFrameUI.java:559)
at javax.swing.plaf.basic.BasicInternalFrameUI$Handler.propertyChange(BasicInternalFrameUI.java:1414)
at java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:335)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:327)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:263)
at java.awt.Component.firePropertyChange(Component.java:8434)
at javax.swing.JInternalFrame.setMaximum(JInternalFrame.java:1024)
at jalview.io.FileLoader.run(FileLoader.java:491)
at jalview.io.FileLoader._LoadFileWaitTillLoaded(FileLoader.java:211)
at jalview.io.FileLoader.LoadFileWaitTillLoaded(FileLoader.java:182)
at jalview.io.FileLoader$LoadFileWaitTillLoaded.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:144)
at ConsoleScript1.run(ConsoleScript1:23)
at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)
at groovy.lang.GroovyShell.run(GroovyShell.java:507)
at groovy.lang.GroovyShell.run(GroovyShell.java:486)
at groovy.lang.GroovyShell.run(GroovyShell.java:171)
at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy:1006)
at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
at groovy.lang.Closure.call(Closure.java:420)
at groovy.lang.Closure.call(Closure.java:414)
at groovy.lang.Closure.run(Closure.java:501)
at java.lang.Thread.run(Thread.java:750)

I just realized that I can use a representative set of 10 aligned fasta files to make the same argument as the 100s of files. Each file will however need its own Feature Setting and some manual tweaking. I was wondering if it was also possible to save the overview for each file as a highres png/svg?

With your 10 representative alignments, which you’re going to do some manual editing anyway, I would suggest to get a high resolution image of the heatmap-like overview, you could adjust some view settings of the alignment and export an SVG of the alignment. You could then edit out the sequence IDs and/or scale in an SVG editor like Inkscape (open source/free download: https://inkscape.org/).

In the alignment window,

  1. remove the residue letters with FormatText (toggle off);
  2. remove the annotations with AnnotationsShow annotations (also a toggle).; and
  3. ensure no selection box with SelectDeselect all

then export with FileExport ImageSVG.

If you want to automate all that, have your 10 alignments open coloured as you want, and run the following groovy script:

jalview.bin.Cache.setProperty("SVG_RENDERING", "Text")
for(def af: Jalview.getAlignFrames()) {
    def title = af.getTitle()
    println("Title: "+af.getTitle())
    def av = af.getCurrentView()
    av.setShowText(false)
    av.setShowAnnotation(false)
    af.deselectAllSequenceMenuItem_actionPerformed(null)
    af.repaint()
    af.createSVG(new File(title+".svg"))
}

Note that it will save the SVG file with the same name as the .fa file that was opened, with .svg appended, and will overwrite any existing .svg file with that name. If the title isn’t a path name then be careful what it saves it as!

The first script I posted above is more akin to a screenshot of the overview window, which might lose some definition if the sequences are long, so that would not be good. This script’s method call (af.createSVG()) uses internal Jalview functions to create a full-length high definition output of the alignment.

Let us know how you get on.

Ben

Dear Dr Sores

Thanks again for the prompt response. The problem with this approach is that the aspect ratio of the final image is dependent on the sequence length. In my case, each polypeptide is 1000 amino acids long, so the heatmap comes out looking super-squished in one dimension. The advantage of the overview window is that the aspect ratio can be adjusted. Would there be a way to save the overview window as svg after I have done the manual editing. Given that I am now focussing on only 10 files, I can do everything without script or automation.

Hi Abhishek,

The beauty of an SVG is that its size or aspect ratio can be adjusted without loss of information or definition. If you import those SVGs into software like Inkscape you will be able to stretch them in length or height as desired, without losing any residue colourings (although your screen might not show them without zooming in).

There isn’t a way built into Jalview to output the Overview window as an SVG, and since the overview colouring only exists as a bitmap, a (lossless) PNG screenshot is essentially as good.

I strongly recommend looking at the exported SVG in Adobe Illustrator or Inkscape to see what you can do with it to adjust the aspect ratio.

Ben