import static org.testng.AssertJUnit.assertNotNull;
-import jalview.api.AlignExportSettingI;
+import jalview.api.AlignExportSettingsI;
+import jalview.datamodel.AlignExportSettingsAdapter;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.testng.Assert;
import org.testng.AssertJUnit;
private Alignment alignment;
- private HashMap<String, SequenceI> expectedSeqs = new HashMap<String, SequenceI>();
+ private HashMap<String, SequenceI> expectedSeqs = new HashMap<>();
- private HashMap<String, AlignmentAnnotation> expectedAnnots = new HashMap<String, AlignmentAnnotation>();
+ private HashMap<String, AlignmentAnnotation> expectedAnnots = new HashMap<>();
- private HashMap<String, SequenceGroup> expectedGrps = new HashMap<String, SequenceGroup>();
+ private HashMap<String, SequenceGroup> expectedGrps = new HashMap<>();
private HiddenColumns expectedColSel = new HiddenColumns();
private JSONFile jf;
- private AlignExportSettingI exportSettings;
+ private AlignExportSettingsI exportSettings;
@BeforeTest(alwaysRun = true)
public void setup() throws Exception
// create and add sequence features
SequenceFeature seqFeature2 = new SequenceFeature("feature_x",
- "description", "status", 6, 15, "Jalview");
+ "theDesc", 6, 15, "Jalview");
SequenceFeature seqFeature3 = new SequenceFeature("feature_x",
- "description", "status", 9, 18, "Jalview");
+ "theDesc", 9, 18, "Jalview");
SequenceFeature seqFeature4 = new SequenceFeature("feature_x",
- "description", "status", 9, 18, "Jalview");
+ "theDesc", 9, 18, "Jalview");
// non-positional feature:
SequenceFeature seqFeature5 = new SequenceFeature("Domain",
- "My description", "status", 0, 0, "Pfam");
+ "My description", 0, 0, "Pfam");
seqs[2].addSequenceFeature(seqFeature2);
seqs[3].addSequenceFeature(seqFeature3);
seqs[4].addSequenceFeature(seqFeature4);
}
// create and add a sequence group
- List<SequenceI> grpSeqs = new ArrayList<SequenceI>();
+ List<SequenceI> grpSeqs = new ArrayList<>();
grpSeqs.add(seqs[1]);
grpSeqs.add(seqs[2]);
grpSeqs.add(seqs[3]);
grpSeqs.add(seqs[4]);
- SequenceGroup seqGrp = new SequenceGroup(grpSeqs,
- "JGroup:1883305585",
+ SequenceGroup seqGrp = new SequenceGroup(grpSeqs, "JGroup:1883305585",
null, true, true, false, 21, 29);
- ColourSchemeI scheme = ColourSchemeMapper.getJalviewColourScheme(
- "zappo", seqGrp);
+ ColourSchemeI scheme = ColourSchemeMapper
+ .getJalviewColourScheme("zappo", seqGrp);
seqGrp.cs.setColourScheme(scheme);
seqGrp.setShowNonconserved(false);
seqGrp.setDescription(null);
TEST_SEQ_HEIGHT = expectedSeqs.size();
TEST_GRP_HEIGHT = expectedGrps.size();
TEST_ANOT_HEIGHT = expectedAnnots.size();
- TEST_CS_HEIGHT = expectedColSel.getHiddenRegions().size();
+ TEST_CS_HEIGHT = expectedColSel.getNumberOfRegions();
- exportSettings = new AlignExportSettingI()
- {
- @Override
- public boolean isExportHiddenSequences()
- {
- return true;
- }
-
- @Override
- public boolean isExportHiddenColumns()
- {
- return true;
- }
-
- @Override
- public boolean isExportGroups()
- {
- return true;
- }
-
- @Override
- public boolean isExportFeatures()
- {
- return true;
- }
-
- @Override
- public boolean isExportAnnotations()
- {
- return true;
- }
-
- @Override
- public boolean isCancelled()
- {
- return false;
- }
- };
+ exportSettings = new AlignExportSettingsAdapter(true);
AppletFormatAdapter formatAdapter = new AppletFormatAdapter();
try
AlignFrame.DEFAULT_HEIGHT);
af.getViewport().setShowSequenceFeatures(jf.isShowSeqFeatures());
String colourSchemeName = jf.getGlobalColourScheme();
- ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme(
- colourSchemeName, alignment);
+ ColourSchemeI cs = ColourSchemeMapper
+ .getJalviewColourScheme(colourSchemeName, alignment);
af.changeColour(cs);
af.getViewport().setFeaturesDisplayed(jf.getDisplayedFeatures());
- formatAdapter = new AppletFormatAdapter(af.alignPanel, exportSettings);
+ formatAdapter = new AppletFormatAdapter(af.alignPanel,
+ exportSettings);
String jsonOutput = formatAdapter.formatSequences(FileFormat.Json,
af.alignPanel.getAlignment(), false);
testAlignment = formatAdapter.readFile(jsonOutput,
DataSourceType.PASTE, FileFormat.Json);
testJsonFile = (JSONFile) formatAdapter.getAlignFile();
- // System.out.println(jsonOutput);
+ System.out.println(jsonOutput);
} catch (IOException e)
{
e.printStackTrace();
{
HiddenColumns cs = testJsonFile.getHiddenColumns();
Assert.assertNotNull(cs);
- Assert.assertNotNull(cs.getHiddenRegions());
- List<int[]> hiddenCols = cs.getHiddenRegions();
- Assert.assertEquals(hiddenCols.size(), TEST_CS_HEIGHT);
- Assert.assertEquals(hiddenCols.get(0), expectedColSel
- .getHiddenRegions().get(0),
+
+ Iterator<int[]> it = cs.iterator();
+ Iterator<int[]> colselit = expectedColSel.iterator();
+ Assert.assertTrue(it.hasNext());
+ Assert.assertEquals(cs.getNumberOfRegions(), TEST_CS_HEIGHT);
+ Assert.assertEquals(it.next(), colselit.next(),
"Mismatched hidden columns!");
}
SequenceGroup sg = new SequenceGroup();
sg.addSequence(_alignment.getSequenceAt(0), false);
sg.setColourScheme(null);
- ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme(
- ResidueColourScheme.NONE, _alignment);
+ ColourSchemeI cs = ColourSchemeMapper
+ .getJalviewColourScheme(ResidueColourScheme.NONE, _alignment);
alignFrame.changeColour(cs);
- alignFrame.getViewport().setFeaturesDisplayed(
- bioJsonFile.getDisplayedFeatures());
+ alignFrame.getViewport()
+ .setFeaturesDisplayed(bioJsonFile.getDisplayedFeatures());
formatAdapter = new AppletFormatAdapter(alignFrame.alignPanel,
exportSettings);
// export BioJSON string
for (AlignmentAnnotation annot : testAlignment.getAlignmentAnnotation())
{
AlignmentAnnotation expectedAnnot = expectedAnnots.get(annot.label);
- AssertJUnit.assertTrue("Failed AlignmentAnnotation Test for >>> "
- + annot.label, isAnnotationMatched(expectedAnnot, annot));
+ AssertJUnit.assertTrue(
+ "Failed AlignmentAnnotation Test for >>> " + annot.label,
+ isAnnotationMatched(expectedAnnot, annot));
passedCount++;
}
AssertJUnit.assertEquals("Some Sequences did not pass the test",
System.out.println("Testing >>> " + actualSeq.getName());
if (expectedSeq.getName().equals(actualSeq.getName())
- && expectedSeq.getSequenceAsString().equals(
- actualSeq.getSequenceAsString())
+ && expectedSeq.getSequenceAsString()
+ .equals(actualSeq.getSequenceAsString())
&& expectedSeq.getStart() == actualSeq.getStart()
&& expectedSeq.getEnd() == actualSeq.getEnd()
&& featuresMatched(expectedSeq, actualSeq))
+ actualGrp.getIgnoreGapsConsensus());
System.out.println(expectedGrp.getSequences().size() + " | "
+ actualGrp.getSequences().size());
- System.out.println(expectedGrp.getStartRes() + " | "
- + actualGrp.getStartRes());
- System.out.println(expectedGrp.getEndRes() + " | "
- + actualGrp.getEndRes());
+ System.out.println(
+ expectedGrp.getStartRes() + " | " + actualGrp.getStartRes());
+ System.out.println(
+ expectedGrp.getEndRes() + " | " + actualGrp.getEndRes());
System.out.println(expectedGrp.cs.getColourScheme() + " | "
+ actualGrp.cs.getColourScheme());
- boolean colourSchemeMatches = (expectedGrp.cs.getColourScheme() == null && actualGrp.cs
- .getColourScheme() == null)
+ boolean colourSchemeMatches = (expectedGrp.cs.getColourScheme() == null
+ && actualGrp.cs.getColourScheme() == null)
|| expectedGrp.cs.getColourScheme().getClass()
.equals(actualGrp.cs.getColourScheme().getClass());
if (expectedGrp.getName().equals(actualGrp.getName())
&& expectedGrp.getIgnoreGapsConsensus() == actualGrp
.getIgnoreGapsConsensus()
&& colourSchemeMatches
- && expectedGrp.getSequences().size() == actualGrp
- .getSequences().size()
+ && expectedGrp.getSequences().size() == actualGrp.getSequences()
+ .size()
&& expectedGrp.getStartRes() == actualGrp.getStartRes()
&& expectedGrp.getEndRes() == actualGrp.getEndRes())
{
for (SequenceFeature in : inFeature)
{
SequenceFeature out = outFeature.get(i);
+ /*
System.out.println(out.getType() + " | " + in.getType());
System.out.println(out.getBegin() + " | " + in.getBegin());
System.out.println(out.getEnd() + " | " + in.getEnd());
-
- if (in.getBegin() == out.getBegin() && in.getEnd() == out.getEnd()
- && in.getScore() == out.getScore()
- && in.getFeatureGroup().equals(out.getFeatureGroup())
- && in.getType().equals(out.getType()))
- {
- }
- else
+ */
+ if (!in.equals(out))
{
- System.err.println("Feature[" + i + "] mismatch, in: "
- + in.toString() + ", out: "
- + outFeature.get(i).toString());
+ System.err.println(
+ "Mismatch of " + in.toString() + " " + out.toString());
return false;
}
+ /*
+ if (in.getBegin() == out.getBegin() && in.getEnd() == out.getEnd()
+ && in.getScore() == out.getScore()
+ && in.getFeatureGroup().equals(out.getFeatureGroup())
+ && in.getType().equals(out.getType())
+ && mapsMatch(in.otherDetails, out.otherDetails))
+ {
+ }
+ else
+ {
+ System.err.println("Feature[" + i + "] mismatch, in: "
+ + in.toString() + ", out: "
+ + outFeature.get(i).toString());
+ return false;
+ }
+ */
i++;
}
} catch (Exception e)
return true;
}
+ boolean mapsMatch(Map<String, Object> m1, Map<String, Object> m2)
+ {
+ if (m1 == null || m2 == null)
+ {
+ if (m1 != null || m2 != null)
+ {
+ System.err.println(
+ "only one SequenceFeature.otherDetails is not null");
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+ if (m1.size() != m2.size())
+ {
+ System.err.println("otherDetails map different sizes");
+ return false;
+ }
+ for (String key : m1.keySet())
+ {
+ if (!m2.containsKey(key))
+ {
+ System.err.println(key + " in only one otherDetails");
+ return false;
+ }
+ if (m1.get(key) == null && m2.get(key) != null
+ || m1.get(key) != null && m2.get(key) == null
+ || !m1.get(key).equals(m2.get(key)))
+ {
+ System.err.println(key + " values in otherDetails don't match");
+ return false;
+ }
+ }
+ return true;
+ }
+
/**
* Test group roundtrip with null (None) group colour scheme
*
AlignmentI copy = new Alignment(testAlignment);
SequenceGroup sg = testAlignment.getGroups().get(0);
SequenceGroup copySg = new SequenceGroup(new ArrayList<SequenceI>(),
- sg.getName(),
- null, sg.getDisplayBoxes(), sg.getDisplayText(),
+ sg.getName(), null, sg.getDisplayBoxes(), sg.getDisplayText(),
sg.getColourText(), sg.getStartRes(), sg.getEndRes());
for (SequenceI seq : sg.getSequences())
{
AlignFrame af = new AlignFrame(copy, copy.getWidth(), copy.getHeight());
AppletFormatAdapter formatAdapter = new AppletFormatAdapter(
af.alignPanel);
- String jsonOutput = formatAdapter.formatSequences(FileFormat.Json,
- copy, false);
+ String jsonOutput = formatAdapter.formatSequences(FileFormat.Json, copy,
+ false);
formatAdapter = new AppletFormatAdapter();
AlignmentI newAlignment = formatAdapter.readFile(jsonOutput,
DataSourceType.PASTE, FileFormat.Json);