/*
* Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
* Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Jalview 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 Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Jalview. If not, see .
* The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.ext.jmol;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.awt.Color;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
import jalview.gui.AlignFrame;
import jalview.gui.SequenceRenderer;
import jalview.schemes.JalviewColourScheme;
import jalview.structure.AtomSpecModel;
import jalview.structure.StructureCommandI;
import jalview.structure.StructureMapping;
import jalview.structure.StructureSelectionManager;
public class JmolCommandsTest
{
private JmolCommands testee;
@BeforeClass(alwaysRun = true)
public void setUp()
{
testee = new JmolCommands();
}
@Test(groups = { "Functional" })
public void testGetColourBySequenceCommands_hiddenColumns()
{
/*
* load these sequences, coloured by Strand propensity,
* with columns 2-4 hidden
*/
SequenceI seq1 = new Sequence("seq1", "MHRSQSSSGG");
SequenceI seq2 = new Sequence("seq2", "MVRSNGGSSS");
AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
AlignFrame af = new AlignFrame(al, 800, 500);
af.changeColour_actionPerformed(JalviewColourScheme.Strand.toString());
ColumnSelection cs = new ColumnSelection();
cs.addElement(2);
cs.addElement(3);
cs.addElement(4);
af.getViewport().setColumnSelection(cs);
af.hideSelColumns_actionPerformed(null);
SequenceRenderer sr = new SequenceRenderer(af.getViewport());
SequenceI[][] seqs = new SequenceI[][] { { seq1 }, { seq2 } };
String[] files = new String[] { "seq1.pdb", "seq2.pdb" };
StructureSelectionManager ssm = new StructureSelectionManager();
/*
* map residues 1-10 to residues 21-30 (atoms 105-150) in structures
*/
HashMap map = new HashMap<>();
for (int pos = 1; pos <= seq1.getLength(); pos++)
{
map.put(pos, new int[] { 20 + pos, 5 * (20 + pos) });
}
StructureMapping sm1 = new StructureMapping(seq1, "seq1.pdb", "pdb1",
"A", map, null);
ssm.addStructureMapping(sm1);
StructureMapping sm2 = new StructureMapping(seq2, "seq2.pdb", "pdb2",
"B", map, null);
ssm.addStructureMapping(sm2);
String[] commands = testee.colourBySequence(ssm,
files,
seqs, sr, af.alignPanel);
assertEquals(commands.length, 2);
String chainACommand = commands[0];
// M colour is #82827d == (130, 130, 125) (see strand.html help page)
assertTrue(
chainACommand.contains("select 21:A/1.1;color[130,130,125]")); // first
// one
// H colour is #60609f == (96, 96, 159)
assertTrue(chainACommand.contains(";select 22:A/1.1;color[96,96,159]"));
// hidden columns are Gray (128, 128, 128)
assertTrue(chainACommand
.contains(";select 23-25:A/1.1;color[128,128,128]"));
// S and G are both coloured #4949b6 == (73, 73, 182)
assertTrue(
chainACommand.contains(";select 26-30:A/1.1;color[73,73,182]"));
String chainBCommand = commands[1];
// M colour is #82827d == (130, 130, 125)
assertTrue(
chainBCommand.contains("select 21:B/2.1;color[130,130,125]"));
// V colour is #ffff00 == (255, 255, 0)
assertTrue(chainBCommand.contains(";select 22:B/2.1;color[255,255,0]"));
// hidden columns are Gray (128, 128, 128)
assertTrue(chainBCommand
.contains(";select 23-25:B/2.1;color[128,128,128]"));
// S and G are both coloured #4949b6 == (73, 73, 182)
assertTrue(
chainBCommand.contains(";select 26-30:B/2.1;color[73,73,182]"));
}
@Test(groups = "Functional")
public void testGetAtomSpec()
{
AtomSpecModel model = new AtomSpecModel();
assertEquals(testee.getAtomSpec(model, false), "");
model.addRange("1", 2, 4, "A");
assertEquals(testee.getAtomSpec(model, false), "2-4:A/1.1");
model.addRange("1", 8, 8, "A");
assertEquals(testee.getAtomSpec(model, false), "2-4:A/1.1|8:A/1.1");
model.addRange("1", 5, 7, "B");
assertEquals(testee.getAtomSpec(model, false),
"2-4:A/1.1|8:A/1.1|5-7:B/1.1");
model.addRange("1", 3, 5, "A");
assertEquals(testee.getAtomSpec(model, false),
"2-5:A/1.1|8:A/1.1|5-7:B/1.1");
model.addRange("2", 1, 4, "B");
assertEquals(testee.getAtomSpec(model, false),
"2-5:A/1.1|8:A/1.1|5-7:B/1.1|1-4:B/2.1");
model.addRange("2", 5, 9, "C");
assertEquals(testee.getAtomSpec(model, false),
"2-5:A/1.1|8:A/1.1|5-7:B/1.1|1-4:B/2.1|5-9:C/2.1");
model.addRange("1", 8, 10, "B");
assertEquals(testee.getAtomSpec(model, false),
"2-5:A/1.1|8:A/1.1|5-10:B/1.1|1-4:B/2.1|5-9:C/2.1");
model.addRange("1", 8, 9, "B");
assertEquals(testee.getAtomSpec(model, false),
"2-5:A/1.1|8:A/1.1|5-10:B/1.1|1-4:B/2.1|5-9:C/2.1");
model.addRange("2", 3, 10, "C"); // subsumes 5-9
assertEquals(testee.getAtomSpec(model, false),
"2-5:A/1.1|8:A/1.1|5-10:B/1.1|1-4:B/2.1|3-10:C/2.1");
model.addRange("5", 25, 35, " ");
assertEquals(testee.getAtomSpec(model, false),
"2-5:A/1.1|8:A/1.1|5-10:B/1.1|1-4:B/2.1|3-10:C/2.1|25-35:/5.1");
}
@Test(groups = { "Functional" })
public void testColourBySequence()
{
Map