* alignment.
*
* @param c
+ * gap character to use to recreate the alignment
* @return
*/
private SequenceI[] getVisibleSeqs(char c)
SequenceI[] aln = new SequenceI[sequences.length];
for (int i = 0, j = sequences.length; i < j; i++)
{
- aln[i] = sequences[i].getSeq('-');
- }
- // Remove hidden regions from sequence objects.
- String seqs[] = getSequenceStrings('-');
- for (int i = 0, j = aln.length; i < j; i++)
- {
- aln[i].setSequence(seqs[i]);
+ aln[i] = sequences[i].getSeq(c);
+ // Remove hidden regions from sequence
+ aln[i].setSequence(getASequenceString(c, i));
}
return aln;
}
}
/**
+ * build a string excluding hidden regions from a particular sequence in the
+ * view
+ *
+ * @param c
+ * @param n
+ * @return
+ */
+ private String getASequenceString(char c, int n)
+ {
+ String sqn;
+ String fullseq = sequences[n].getSequenceString(c);
+ if (contigs != null)
+ {
+ sqn = "";
+ int p = 0;
+ for (int h = 0; h < contigs.length; h += 3)
+ {
+ sqn += fullseq.substring(p, contigs[h + 1]);
+ p = contigs[h + 1] + contigs[h + 2];
+ }
+ sqn += fullseq.substring(p);
+ }
+ else
+ {
+ sqn = fullseq;
+ }
+ return sqn;
+ }
+
+ /**
* get an array of visible sequence strings for a view on an alignment using
- * the given gap character
+ * the given gap character uses getASequenceString
*
* @param c
* char
String[] seqs = new String[sequences.length];
for (int n = 0; n < sequences.length; n++)
{
- String fullseq = sequences[n].getSequenceString(c);
- if (contigs != null)
- {
- seqs[n] = "";
- int p = 0;
- for (int h = 0; h < contigs.length; h += 3)
- {
- seqs[n] += fullseq.substring(p, contigs[h + 1]);
- p = contigs[h + 1] + contigs[h + 2];
- }
- seqs[n] += fullseq.substring(p);
- }
- else
- {
- seqs[n] = fullseq;
- }
+ seqs[n] = getASequenceString(c, n);
}
return seqs;
}
--- /dev/null
+package jalview.datamodel;
+import static org.testng.Assert.assertEquals;
+
+import org.testng.annotations.Test;
+
+public class AlignmentViewTest
+{
+ @Test(groups = { "Functional" })
+ public void testGetVisibleAlignmentGapChar()
+ {
+ SeqCigar ss = new SeqCigar(new Sequence("One", "A..CDE"));
+ CigarArray ca = new CigarArray(new CigarSimple[] { ss });
+ AlignmentView av = new AlignmentView(ca);
+ String dots = av.getSequenceStrings('.')[0];
+ assertEquals(dots, "A..CDE");
+ String dollars = av.getSequenceStrings('$')[0];
+ assertEquals(dollars, "A$$CDE");
+ assertEquals(av.getVisibleAlignment('$').getSequenceAt(0)
+ .getSequenceAsString(), "A$$CDE");
+ }
+}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.io;
+
+import static org.testng.AssertJUnit.assertTrue;
+
+import jalview.datamodel.SequenceGroup;
+import jalview.gui.AlignFrame;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * tests which verify that properties and preferences are correctly interpreted
+ * when exporting/importing data
+ *
+ * @author jprocter
+ *
+ */
+public class JalviewExportPropertiesTests
+{
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass(alwaysRun = true)
+ public static void setUpBeforeClass() throws Exception
+ {
+ jalview.bin.Jalview.main(new String[]
+ { "-props", "test/jalview/io/testProps.jvprops" });
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception
+ {
+ jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
+
+ }
+ @Test(groups ={ "Functional" })
+ public void testImportExportPeriodGaps() throws Exception
+ {
+ jalview.bin.Cache.setProperty("GAP_SYMBOL", ".");
+ assertTrue("Couldn't set gap character to '.'",
+ ".".equals("" + jalview.bin.Cache.getProperty("GAP_SYMBOL")));
+ AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
+ "examples/uniref50.fa", FormatAdapter.FILE);
+ assertTrue("Didn't read in the example file correctly.", af != null);
+ assertTrue("Didn't set the gap character correctly", af.getViewport()
+ .getAlignment().getSequenceAt(0).getCharAt(5) == '.');
+
+ SequenceGroup sg = new SequenceGroup();
+ sg.addSequence(af.getViewport().getAlignment().getSequenceAt(0),false);
+ sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1),false);
+ sg.setStartRes(1);
+ sg.setEndRes(7);
+ af.getViewport().setSelectionGroup(sg);
+ String fseqs = new FormatAdapter(af.alignPanel).formatSequences(
+ "FASTA", af.alignPanel, true);
+ assertTrue("Couldn't find '.' in the exported region\n" + fseqs,
+ fseqs.indexOf(".") > -1);
+ }
+}