for (SequenceI aaSeq : thisSeqs)
{
- AlignedCodonFrame acf = new AlignedCodonFrame(
- proteinAlignment.getWidth());
+ AlignedCodonFrame acf = new AlignedCodonFrame();
List<SequenceI> candidates = cdnaSeqs.get(aaSeq.getName());
if (candidates == null)
{
*/
package jalview.analysis;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Vector;
-import java.util.Hashtable;
-
import jalview.datamodel.AlignedCodonFrame;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
-import jalview.datamodel.DBRefSource;
import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.DBRefSource;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
import jalview.ws.SequenceFetcher;
import jalview.ws.seqfetcher.ASequenceFetcher;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Vector;
+
/**
* Functions for cross-referencing sequence databases. user must first specify
* if cross-referencing from protein or dna (set dna==true)
{
Vector rseqs = new Vector();
Alignment ral = null;
- AlignedCodonFrame cf = new AlignedCodonFrame(0); // nominal width
+ AlignedCodonFrame cf = new AlignedCodonFrame(); // nominal width
for (int s = 0; s < seqs.length; s++)
{
SequenceI dss = seqs[s];
for (int r = 0; xrfs != null && r < xrfs.length; r++)
{
if (source != null && !source.equals(xrfs[r].getSource()))
+ {
continue;
+ }
if (xrfs[r].hasMap())
{
if (xrfs[r].getMap().getTo() != null)
{
found |= searchDataset(dss, xrfs[r], dataset, rseqs, cf); // ,false,!dna);
if (found)
+ {
xrfs[r] = null; // we've recovered seqs for this one.
+ }
}
}
}
for (int r = 0; r < xrfs.length; r++)
{
if (xrfs[r] != null)
+ {
t[l++] = xrfs[r];
+ }
}
xrfs = t;
try
{
boolean found = false;
if (lrfs == null)
+ {
return false;
+ }
for (int i = 0; i < lrfs.length; i++)
{
DBRefEntry xref = new DBRefEntry(lrfs[i]);
boolean found = false;
SequenceI[] typer = new SequenceI[1];
if (dataset == null)
+ {
return false;
+ }
if (dataset.getSequences() == null)
{
System.err.println("Empty dataset sequence set - NO VECTOR");
synchronized (ds = dataset.getSequences())
{
for (SequenceI nxt : ds)
+ {
if (nxt != null)
{
if (nxt.getDatasetSequence() != null)
}
}
+ }
}
return found;
}
*/
package jalview.analysis;
+import jalview.api.AlignViewportI;
import jalview.bin.Cache;
import jalview.datamodel.AlignedCodonFrame;
import jalview.datamodel.Alignment;
public class Dna
{
+ private static final String STOP_X = "X";
+
+ final private List<SequenceI> selection;
+
+ final private String[] seqstring;
+
+ final private int[] contigs;
+
+ final private char gapChar;
+
+ final private AlignmentAnnotation[] annotations;
+
+ final private int dnaWidth;
+
+ final private Alignment dataset;
+
+ private int aaWidth = 0;
+
+ /**
+ * Constructor given a viewport and the visible contigs.
+ *
+ * @param viewport
+ * @param visibleContigs
+ */
+ public Dna(AlignViewportI viewport, int[] visibleContigs)
+ {
+ this.selection = Arrays.asList(viewport.getSequenceSelection());
+ this.seqstring = viewport.getViewAsString(true);
+ this.contigs = visibleContigs;
+ this.gapChar = viewport.getGapCharacter();
+ this.annotations = viewport.getAlignment().getAlignmentAnnotation();
+ this.dnaWidth = viewport.getAlignment().getWidth();
+ this.dataset = viewport.getAlignment().getDataset();
+ }
+
/**
* Test whether codon positions cdp1 should align before, with, or after cdp2.
* Returns zero if all positions match (or either argument is null). Returns
}
/**
- * DNA->mapped protein sequence alignment translation given set of sequences
- * 1. id distinct coding regions within selected region for each sequence 2.
- * generate peptides based on inframe (or given) translation or (optionally
- * and where specified) out of frame translations (annotated appropriately) 3.
- * align peptides based on codon alignment
- */
- /**
- * id potential products from dna 1. search for distinct products within
- * selected region for each selected sequence 2. group by associated DB type.
- * 3. return as form for input into above function
- */
- /**
- *
- */
- /**
- * create a new alignment of protein sequences by an inframe translation of
- * the provided NA sequences
- *
- * @param selection
- * @param seqstring
- * @param viscontigs
- * @param gapCharacter
- * @param annotations
- * @param aWidth
- * @param dataset
- * destination dataset for translated sequences and mappings
- * @return
- */
- public static AlignmentI cdnaTranslate(SequenceI[] selection,
- String[] seqstring, int viscontigs[], char gapCharacter,
- AlignmentAnnotation[] annotations, int aWidth, Alignment dataset)
- {
- return cdnaTranslate(Arrays.asList(selection), seqstring, null,
- viscontigs, gapCharacter, annotations, aWidth, dataset);
- }
-
- /**
*
- * @param cdnaseqs
- * @param seqstring
- * @param product
- * - array of DbRefEntry objects from which exon map in seqstring is
- * derived
- * @param viscontigs
- * @param gapCharacter
- * @param annotations
- * @param aWidth
- * @param dataset
* @return
*/
- public static AlignmentI cdnaTranslate(List<SequenceI> cdnaseqs,
- String[] seqstring, DBRefEntry[] product, int viscontigs[],
- char gapCharacter, AlignmentAnnotation[] annotations, int aWidth,
- Alignment dataset)
+ public AlignmentI translateCdna()
{
- AlignedCodonFrame acf = new AlignedCodonFrame(aWidth);
+ AlignedCodonFrame acf = new AlignedCodonFrame();
/*
* This array will be built up so that position i holds the codon positions
* Note this implies a contract that if two codons do not align exactly,
* their translated products must occupy different column positions.
*/
- int[][] alignedCodons = new int[aWidth][];
+ int[][] alignedCodons = new int[dnaWidth][];
int s;
- int sSize = cdnaseqs.size();
+ int sSize = selection.size();
List<SequenceI> pepseqs = new ArrayList<SequenceI>();
for (s = 0; s < sSize; s++)
{
- SequenceI newseq = translateCodingRegion(cdnaseqs.get(s),
- seqstring[s], viscontigs, acf, alignedCodons, pepseqs,
- gapCharacter,
- false);
+ SequenceI newseq = translateCodingRegion(selection.get(s),
+ seqstring[s], acf, alignedCodons, pepseqs);
if (newseq != null)
{
* when true stop codons will translate as '*', otherwise as 'X'
* @return sequence ready to be added to alignment.
*/
- protected static SequenceI translateCodingRegion(SequenceI selection,
- String seqstring, int[] viscontigs, AlignedCodonFrame acf,
- int[][] alignedCodons, List<SequenceI> proteinSeqs,
- char gapCharacter,
- final boolean starForStop)
+ protected SequenceI translateCodingRegion(SequenceI selection,
+ String seqstring, AlignedCodonFrame acf,
+ int[][] alignedCodons, List<SequenceI> proteinSeqs)
{
List<int[]> skip = new ArrayList<int[]>();
int skipint[] = null;
ShiftList vismapping = new ShiftList(); // map from viscontigs to seqstring
// intervals
- int vc, scontigs[] = new int[viscontigs.length];
+ int vc;
+ int[] scontigs = new int[contigs.length];
int npos = 0;
- for (vc = 0; vc < viscontigs.length; vc += 2)
+ for (vc = 0; vc < contigs.length; vc += 2)
{
if (vc == 0)
{
- vismapping.addShift(npos, viscontigs[vc]);
+ vismapping.addShift(npos, contigs[vc]);
}
else
{
// hidden region
- vismapping.addShift(npos, viscontigs[vc] - viscontigs[vc - 1] + 1);
+ vismapping.addShift(npos, contigs[vc] - contigs[vc - 1] + 1);
}
- scontigs[vc] = viscontigs[vc];
- scontigs[vc + 1] = viscontigs[vc + 1];
+ scontigs[vc] = contigs[vc];
+ scontigs[vc + 1] = contigs[vc + 1];
}
// allocate a roughly sized buffer for the protein sequence
*/
String aa = ResidueProperties.codonTranslate(new String(codon));
rf = 0;
- final String gapString = String.valueOf(gapCharacter);
+ final String gapString = String.valueOf(gapChar);
if (aa == null)
{
aa = gapString;
}
if (aa.equals("STOP"))
{
- aa = starForStop ? "*" : "X";
+ aa = STOP_X;
}
resSize++;
}
// debug
System.out.println(seq + "/" + aa + " codons: "
+ Arrays.deepToString(alignedCodons));
+ for (SequenceI s : proteinSeqs)
+ {
+ System.out.println(s.getSequenceAsString());
+ }
System.out
.println(("Compare " + Arrays.toString(cdp) + " at pos "
+ aspos + " with "
* This codon should precede the mapped positions - need to insert a
* gap in all prior sequences.
*/
- insertAAGap(aspos, gapCharacter, alignedCodons, proteinSeqs);
+ alignedCodons = insertAAGap(aspos, alignedCodons, proteinSeqs);
findpos = false;
break;
throw new IllegalStateException("Tried to coalign "
+ Arrays.asList(alignedCodons[aspos], cdp));
}
- if (aspos >= acf.aaWidth)
+ System.out.println(aspos + "/" + aaWidth);
+ if (aspos >= aaWidth)
{
// update maximum alignment width
// (we can do this without calling checkCodonFrameWidth because it was
// already done above)
- System.out.println("aspos " + aspos + " >= " + acf.aaWidth);
- acf.setAaWidth(aspos);
+ aaWidth = aspos;
}
// ready for next translated reading frame alignment position (if any)
aspos++;
* Insert a gap into the aligned proteins and the codon mapping array.
*
* @param pos
- * @param gapCharacter
* @param alignedCodons
* @param proteinSeqs
+ * @return
*/
- protected static void insertAAGap(int pos, char gapCharacter,
- int[][] alignedCodons, List<SequenceI> proteinSeqs)
+ protected int[][] insertAAGap(int pos, int[][] alignedCodons,
+ List<SequenceI> proteinSeqs)
{
System.out.println("insertAAGap " + pos + "/" + proteinSeqs.size());
- // aaWidth++;
+ aaWidth++;
for (SequenceI seq : proteinSeqs)
{
- seq.insertCharAt(pos, gapCharacter);
+ seq.insertCharAt(pos, gapChar);
}
- // if (pos < aaWidth)
- // {
- // aaWidth++;
- System.arraycopy(alignedCodons, pos, alignedCodons, pos + 1,
- alignedCodons.length - pos - 1);
- alignedCodons[pos] = null; // clear so new codon position can be marked.
- // }
+ int[][] resized = checkCodonFrameWidth(alignedCodons, pos);
+ if (pos < aaWidth)
+ {
+ aaWidth++;
+ System.arraycopy(resized, pos, resized, pos + 1, resized.length - pos
+ - 1);
+ resized[pos] = null; // clear so new codon position can be marked.
+ }
+ return resized;
}
/**
{
// TODO why not codons.length < aspos ?
// should codons expand if length is 2 or 3 and aslen==2 ?
+ System.out.println("Checking " + alignedCodons.length + "/" + aspos);
if (alignedCodons.length <= aspos + 1)
{
// probably never have to do this ?
*
* @param aWidth
*/
- public AlignedCodonFrame(int aWidth)
+ public AlignedCodonFrame()
{
- if (aWidth <= 0)
- {
- codons = null;
- return;
- }
- codons = new int[aWidth][];
- for (int res = 0; res < aWidth; res++)
- {
- codons[res] = null;
- }
}
/**
import jalview.analysis.AlignmentUtils;
import jalview.analysis.Conservation;
import jalview.analysis.CrossRef;
+import jalview.analysis.Dna;
import jalview.analysis.NJTree;
import jalview.analysis.ParseProperties;
import jalview.analysis.SequenceIdMatcher;
/**
* Construct and display a new frame containing the translation of this
- * frame's cDNA sequences to their protein (amino acid) equivalents.
+ * frame's cDNA sequences to their aligned protein (amino acid) equivalents.
*/
@Override
public void showTranslation_actionPerformed(ActionEvent e)
{
- // /////////////////////////////
- // Collect Data to be translated/transferred
-
- SequenceI[] selection = viewport.getSequenceSelection();
- String[] seqstring = viewport.getViewAsString(true);
AlignmentI al = null;
try
{
- al = jalview.analysis.Dna.cdnaTranslate(selection, seqstring,
- viewport.getViewAsVisibleContigs(true), viewport
- .getGapCharacter(), viewport.getAlignment()
- .getAlignmentAnnotation(), viewport.getAlignment()
- .getWidth(), viewport.getAlignment().getDataset());
+ Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
+
+ al = dna.translateCdna();
} catch (Exception ex)
{
- al = null;
jalview.bin.Cache.log.error(
"Exception during translation. Please report this !", ex);
- JOptionPane
- .showMessageDialog(
- Desktop.desktop,
- MessageManager
- .getString("label.error_when_translating_sequences_submit_bug_report"),
- MessageManager
- .getString("label.implementation_error")
- + MessageManager
- .getString("translation_failed"),
- JOptionPane.ERROR_MESSAGE);
+ final String msg = MessageManager
+ .getString("label.error_when_translating_sequences_submit_bug_report");
+ final String title = MessageManager
+ .getString("label.implementation_error")
+ + MessageManager.getString("translation_failed");
+ JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
+ JOptionPane.ERROR_MESSAGE);
return;
}
if (al == null)
{
- JOptionPane
- .showMessageDialog(
- Desktop.desktop,
- MessageManager
- .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation"),
- MessageManager.getString("label.translation_failed"),
- JOptionPane.WARNING_MESSAGE);
+ final String msg = MessageManager
+ .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
+ final String title = MessageManager
+ .getString("label.translation_failed");
+ JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
+ JOptionPane.WARNING_MESSAGE);
}
else
{
AlcodonFrame[] alc = vamsasSet.getAlcodonFrame();
for (int i = 0; i < alc.length; i++)
{
- AlignedCodonFrame cf = new AlignedCodonFrame(0);
+ AlignedCodonFrame cf = new AlignedCodonFrame();
if (alc[i].getAlcodMapCount() > 0)
{
AlcodMap[] maps = alc[i].getAlcodMap();
*/
package jalview.io.vamsas;
-import java.util.Vector;
-
import jalview.datamodel.AlignedCodonFrame;
import jalview.datamodel.Mapping;
import jalview.datamodel.SequenceI;
import jalview.gui.Desktop;
import jalview.io.VamsasAppDatastore;
-import uk.ac.vamsas.client.Vobject;
+
+import java.util.Vector;
+
import uk.ac.vamsas.objects.core.AlignmentSequence;
import uk.ac.vamsas.objects.core.DataSet;
import uk.ac.vamsas.objects.core.Sequence;
jalview.bin.Cache.log.info("Ignoring non sequence-sequence mapping");
return;
}
- mobj = this.getvObj2jv((Vobject) sdloc);
+ mobj = this.getvObj2jv(sdloc);
if (mobj instanceof SequenceI)
{
from = (SequenceI) mobj;
}
- mobj = this.getvObj2jv((Vobject) sdmap);
+ mobj = this.getvObj2jv(sdmap);
if (mobj instanceof SequenceI)
{
to = (SequenceI) mobj;
.getV_parent());
jalview.datamodel.AlignmentI dsMap = (jalview.datamodel.AlignmentI) getvObj2jv(sdmap
.getV_parent());
- AlignedCodonFrame afc = new AlignedCodonFrame(0);
+ AlignedCodonFrame afc = new AlignedCodonFrame();
if (dsLoc != null && dsLoc != dsMap)
{
package jalview.analysis;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import jalview.api.AlignViewportI;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.ColumnSelection;
+import jalview.gui.AlignViewport;
import jalview.io.FormatAdapter;
import java.io.IOException;
public class DnaTest
{
+ // @formatter:off
// AA encoding codons as ordered on the Jalview help page Amino Acid Table
private static String fasta = ">B\n" + "GCT" + "GCC" + "GCA" + "GCG"
+ "TGT" + "TGC" + "GAT" + "GAC" + "GAA" + "GAG" + "TTT" + "TTC"
+ "ACA" + "ACG" + "GTT" + "GTC" + "GTA" + "GTG" + "TGG" + "TAT"
+ "TAC" + "TAA" + "TAG" + "TGA";
+ private static String JAL_1312_example_align_fasta = ">B.FR.83.HXB2_LAI_IIIB_BRU_K03455/45-306\n"
+ + "ATGGGAAAAAATTCGGTTAAGGCCAGGGGGAAAGAAAAAATATAAATTAAAACATATAGTATGGGCAAGCAG\n"
+ + "GGAGCTAGAACGATTCGCAGTTAATCCTGGCCTGTTAGAAACATCAGAAGGCTGTAGACAAATACTGGGACA\n"
+ + "GCTACAACCATCCCTTCAGACAGGATCAGAAGAACTTAGATCATTATATAATACAGTAGCAACCCTCTATTG\n"
+ + "TGTGCATCAAAGGATAGAGATAAAAGACACCAAGGAAGCTTTAGAC\n"
+ + ">gi|27804621|gb|AY178912.1|/1-259\n"
+ + "-TGGGAGAA-ATTCGGTT-CGGCCAGGGGGAAAGAAAAAATATCAGTTAAAACATATAGTATGGGCAAGCAG\n"
+ + "AGAGCTAGAACGATTCGCAGTTAACCCTGGCCTTTTAGAGACATCACAAGGCTGTAGACAAATACTGGGACA\n"
+ + "GCTACAACCATCCCTTCAGACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
+ + "TGTTCATCAAAGGATAGATATAAAAGACACCAAGGAAGCTTTAGAT\n"
+ + ">gi|27804623|gb|AY178913.1|/1-259\n"
+ + "-TGGGAGAA-ATTCGGTT-CGGCCAGGGGGAAAGAAAAAATATCAGTTAAAACATATAGTATGGGCAAGCAG\n"
+ + "AGAGCTAGAACGATTCGCAGTTAACCCTGGCCTTTTAGAGACATCACAAGGCTGTAGACAAATACTGGAACA\n"
+ + "GCTACAACCATCCCTTCAGACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
+ + "TGTTCATCAAAGGATAGATGTAAAAGACACCAAGGAAGCTTTAGAT\n"
+ + ">gi|27804627|gb|AY178915.1|/1-260\n"
+ + "-TGGGAAAA-ATTCGGTTAAGGCCAGGGGGAAAGAAAAAATATAAGTTAAAACATATAGTATGGGCAAGCAG\n"
+ + "GGAGCTAGAACGATTCGCAGTTAACCCTGGCCTGTTAGAAACATCAGAAGGTTGTAGACAAATATTGGGACA\n"
+ + "GCTACAACCATCCCTTGAGACAGGATCAGAAGAACTTAAATCATTATWTAATACCATAGCAGTCCTCTATTG\n"
+ + "TGTACATCAAAGGATAGATATAAAAGACACCAAGGAAGCTTTAGAG\n"
+ + ">gi|27804631|gb|AY178917.1|/1-261\n"
+ + "-TGGGAAAAAATTCGGTTGAGGCCAGGGGGAAAGAAAAAATATAAGTTAAAACATATAGTATGGGCAAGCAG\n"
+ + "GGAGCTAGAACGATTCGCAGTCAACCCTGGCCTGTTAGAAACACCAGAAGGCTGTAGACAAATACTGGGACA\n"
+ + "GCTACAACCGTCCCTTCAGACAGGATCGGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
+ + "TGTGCATCAAAGGATAGATGTAAAAGACACCAAGGAGGCTTTAGAC\n"
+ + ">gi|27804635|gb|AY178919.1|/1-261\n"
+ + "-TGGGAGAGAATTCGGTTACGGCCAGGAGGAAAGAAAAAATATAAATTGAAACATATAGTATGGGCAGGCAG\n"
+ + "AGAGCTAGATCGATTCGCAGTCAATCCTGGCCTGTTAGAAACATCAGAAGGCTGCAGACAGATATTGGGACA\n"
+ + "GCTACAACCGTCCCTTAAGACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
+ + "TGTACATCAAAGGATAGATGTAAAAGACACCAAGGAAGCTTTAGAT\n"
+ + ">gi|27804641|gb|AY178922.1|/1-261\n"
+ + "-TGGGAGAAAATTCGGTTACGGCCAGGGGGAAAGAAAAGATATAAGTTAAAACATATAGTATGGGCAAGCAG\n"
+ + "GGAGCTAGAACGATTCGCAGTCAACCCTGGCCTGTTAGAAACATCAGAAGGCTGCAGACAAATACTGGGACA\n"
+ + "GTTACACCCATCCCTTCATACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
+ + "TGTGCATCAAAGGATAGAAGTAAAAGACACCAAGGAAGCTTTAGAC\n"
+ + ">gi|27804647|gb|AY178925.1|/1-261\n"
+ + "-TGGGAAAAAATTCGGTTAAGGCCAGGGGGAAAGAAAAAATATCAATTAAAACATGTAGTATGGGCAAGCAG\n"
+ + "GGAACTAGAACGATTCGCAGTTAATCCTGGCCTGTTAGAAACATCAGAAGGCTGTAGACAAATATTGGGACA\n"
+ + "GCTACAACCATCCCTTCAGACAGGATCAGAGGAACTTAAATCATTATTTAATACAGTAGCAGTCCTCTATTG\n"
+ + "TGTACATCAAAGAATAGATGTAAAAGACACCAAGGAAGCTCTAGAA\n"
+ + ">gi|27804649|gb|AY178926.1|/1-261\n"
+ + "-TGGGAAAAAATTCGGTTAAGGCCAGGGGGAAAGAAAAAATATAAGTTAAAACATATAGTATGGGCAAGCAG\n"
+ + "GGAGCTAGAACGATTCGCGGTCAATCCTGGCCTGTTAGAAACATCAGAAGGCTGTAGACAACTACTGGGACA\n"
+ + "GTTACAACCATCCCTTCAGACAGGATCAGAAGAACTCAAATCATTATATAATACAATAGCAACCCTCTATTG\n"
+ + "TGTGCATCAAAGGATAGAGATAAAAGACACCAAGGAAGCCTTAGAT\n"
+ + ">gi|27804653|gb|AY178928.1|/1-261\n"
+ + "-TGGGAAAGAATTCGGTTAAGGCCAGGGGGAAAGAAACAATATAAATTAAAACATATAGTATGGGCAAGCAG\n"
+ + "GGAGCTAGACCGATTCGCACTTAACCCCGGCCTGTTAGAAACATCAGAAGGCTGTAGACAAATATTGGGACA\n"
+ + "GCTACAATCGTCCCTTCAGACAGGATCAGAAGAACTTAGATCACTATATAATACAGTAGCAGTCCTCTATTG\n"
+ + "TGTGCATCAAAAGATAGATGTAAAAGACACCAAGGAAGCCTTAGAC\n"
+ + ">gi|27804659|gb|AY178931.1|/1-261\n"
+ + "-TGGGAAAAAATTCGGTTACGGCCAGGAGGAAAGAAAAGATATAAATTAAAACATATAGTATGGGCAAGCAG\n"
+ + "GGAGCTAGAACGATTYGCAGTTAATCCTGGCCTTTTAGAAACAGCAGAAGGCTGTAGACAAATACTGGGACA\n"
+ + "GCTACAACCATCCCTTCAGACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
+ + "TGTACATCAAAGGATAGAGATAAAAGACACCAAGGAAGCTTTAGAA\n";
+ // @formatter:on
+
+ /**
+ * Corner case for this test is the presence of codons after codons that were
+ * not translated.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testTranslateCdna_withUntranslatableCodons()
+ throws IOException
+ {
+ AlignmentI alf = new FormatAdapter().readFile(
+ JAL_1312_example_align_fasta, jalview.io.FormatAdapter.PASTE,
+ "FASTA");
+ ColumnSelection cs = new ColumnSelection();
+ AlignViewportI av = new AlignViewport(alf, cs);
+ Dna dna = new Dna(av, new int[]
+ { 0, alf.getWidth() - 1 });
+ AlignmentI translated = dna.translateCdna();
+ assertNotNull("Couldn't do a full width translation of test data.",
+ translated);
+ }
+
+ /**
+ * Test variant in which 15 column blocks at a time are translated (the rest
+ * hidden).
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testTranslateCdna_withUntranslatableCodonsAndHiddenColumns()
+ throws IOException
+ {
+ AlignmentI alf = new FormatAdapter().readFile(
+ JAL_1312_example_align_fasta, jalview.io.FormatAdapter.PASTE,
+ "FASTA");
+ int vwidth = 15;
+ for (int ipos = 0; ipos + vwidth < alf.getWidth(); ipos += vwidth)
+ {
+ ColumnSelection cs = new ColumnSelection();
+ if (ipos > 0)
+ {
+ cs.hideColumns(0, ipos - 1);
+ }
+ cs.hideColumns(ipos + vwidth, alf.getWidth());
+ int[] vcontigs = cs.getVisibleContigs(0, alf.getWidth());
+ AlignViewportI av = new AlignViewport(alf, cs);
+ Dna dna = new Dna(av, vcontigs);
+ AlignmentI transAlf = dna.translateCdna();
+
+ assertTrue("Translation failed (ipos=" + ipos
+ + ") No alignment data.", transAlf != null);
+ assertTrue("Translation failed (ipos=" + ipos + ") Empty alignment.",
+ transAlf.getHeight() > 0);
+ assertTrue("Translation failed (ipos=" + ipos + ") Translated "
+ + transAlf.getHeight() + " sequences from " + alf.getHeight()
+ + " sequences", alf.getHeight() == transAlf.getHeight());
+ }
+ }
+
/**
* Test simple translation to Amino Acids (with STOP codons translated to X).
*
* @throws IOException
*/
@Test
- public void testCdnaTranslate_simple() throws IOException
+ public void testTranslateCdna_simple() throws IOException
{
AlignmentI alf = new FormatAdapter().readFile(fasta,
FormatAdapter.PASTE, "FASTA");
- final String sequenceAsString = alf
- .getSequenceAt(0).getSequenceAsString();
- AlignmentI translated = Dna.cdnaTranslate(alf.getSequencesArray(),
- new String[]
- { sequenceAsString }, new int[]
- { 0, alf.getWidth() - 1 }, alf.getGapCharacter(), null,
- alf.getWidth(), null);
+ ColumnSelection cs = new ColumnSelection();
+ AlignViewportI av = new AlignViewport(alf, cs);
+ Dna dna = new Dna(av, new int[]
+ { 0, alf.getWidth() - 1 });
+ AlignmentI translated = dna.translateCdna();
String aa = translated.getSequenceAt(0).getSequenceAsString();
assertEquals(
"AAAACCDDEEFFGGGGHHIIIKKLLLLLLMNNPPPPQQRRRRRRSSSSSSTTTTVVVVWYYXXX",
* @throws IOException
*/
@Test
- public void testCdnaTranslate_hiddenColumns() throws IOException
+ public void testTranslatCdna_hiddenColumns() throws IOException
{
AlignmentI alf = new FormatAdapter().readFile(fasta,
FormatAdapter.PASTE, "FASTA");
cs.hideColumns(6, 14); // hide codons 3/4/5
cs.hideColumns(24, 35); // hide codons 9-12
cs.hideColumns(177, 191); // hide codons 60-64
- AlignmentI translated = Dna.cdnaTranslate(alf.getSequencesArray(),
- cs.getVisibleSequenceStrings(0, alf.getWidth(),
- alf.getSequencesArray()), new int[]
- { 0, alf.getWidth() - 1 }, alf.getGapCharacter(), null,
- alf.getWidth(), null);
+ AlignViewportI av = new AlignViewport(alf, cs);
+ Dna dna = new Dna(av, new int[]
+ { 0, alf.getWidth() - 1 });
+ AlignmentI translated = dna.translateCdna();
String aa = translated.getSequenceAt(0).getSequenceAsString();
assertEquals("AACDDGGGGHHIIIKKLLLLLLMNNPPPPQQRRRRRRSSSSSSTTTTVVVVW", aa);
}
+++ /dev/null
-/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 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.analysis;
-
-import static org.junit.Assert.*;
-import jalview.datamodel.ColumnSelection;
-
-import java.io.IOException;
-
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-public class DnaTranslation
-{
-
- private static String JAL_1312_example_align_fasta = ">B.FR.83.HXB2_LAI_IIIB_BRU_K03455/45-306\n"
- + "ATGGGAAAAAATTCGGTTAAGGCCAGGGGGAAAGAAAAAATATAAATTAAAACATATAGTATGGGCAAGCAG\n"
- + "GGAGCTAGAACGATTCGCAGTTAATCCTGGCCTGTTAGAAACATCAGAAGGCTGTAGACAAATACTGGGACA\n"
- + "GCTACAACCATCCCTTCAGACAGGATCAGAAGAACTTAGATCATTATATAATACAGTAGCAACCCTCTATTG\n"
- + "TGTGCATCAAAGGATAGAGATAAAAGACACCAAGGAAGCTTTAGAC\n"
- + ">gi|27804621|gb|AY178912.1|/1-259\n"
- + "-TGGGAGAA-ATTCGGTT-CGGCCAGGGGGAAAGAAAAAATATCAGTTAAAACATATAGTATGGGCAAGCAG\n"
- + "AGAGCTAGAACGATTCGCAGTTAACCCTGGCCTTTTAGAGACATCACAAGGCTGTAGACAAATACTGGGACA\n"
- + "GCTACAACCATCCCTTCAGACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
- + "TGTTCATCAAAGGATAGATATAAAAGACACCAAGGAAGCTTTAGAT\n"
- + ">gi|27804623|gb|AY178913.1|/1-259\n"
- + "-TGGGAGAA-ATTCGGTT-CGGCCAGGGGGAAAGAAAAAATATCAGTTAAAACATATAGTATGGGCAAGCAG\n"
- + "AGAGCTAGAACGATTCGCAGTTAACCCTGGCCTTTTAGAGACATCACAAGGCTGTAGACAAATACTGGAACA\n"
- + "GCTACAACCATCCCTTCAGACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
- + "TGTTCATCAAAGGATAGATGTAAAAGACACCAAGGAAGCTTTAGAT\n"
- + ">gi|27804627|gb|AY178915.1|/1-260\n"
- + "-TGGGAAAA-ATTCGGTTAAGGCCAGGGGGAAAGAAAAAATATAAGTTAAAACATATAGTATGGGCAAGCAG\n"
- + "GGAGCTAGAACGATTCGCAGTTAACCCTGGCCTGTTAGAAACATCAGAAGGTTGTAGACAAATATTGGGACA\n"
- + "GCTACAACCATCCCTTGAGACAGGATCAGAAGAACTTAAATCATTATWTAATACCATAGCAGTCCTCTATTG\n"
- + "TGTACATCAAAGGATAGATATAAAAGACACCAAGGAAGCTTTAGAG\n"
- + ">gi|27804631|gb|AY178917.1|/1-261\n"
- + "-TGGGAAAAAATTCGGTTGAGGCCAGGGGGAAAGAAAAAATATAAGTTAAAACATATAGTATGGGCAAGCAG\n"
- + "GGAGCTAGAACGATTCGCAGTCAACCCTGGCCTGTTAGAAACACCAGAAGGCTGTAGACAAATACTGGGACA\n"
- + "GCTACAACCGTCCCTTCAGACAGGATCGGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
- + "TGTGCATCAAAGGATAGATGTAAAAGACACCAAGGAGGCTTTAGAC\n"
- + ">gi|27804635|gb|AY178919.1|/1-261\n"
- + "-TGGGAGAGAATTCGGTTACGGCCAGGAGGAAAGAAAAAATATAAATTGAAACATATAGTATGGGCAGGCAG\n"
- + "AGAGCTAGATCGATTCGCAGTCAATCCTGGCCTGTTAGAAACATCAGAAGGCTGCAGACAGATATTGGGACA\n"
- + "GCTACAACCGTCCCTTAAGACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
- + "TGTACATCAAAGGATAGATGTAAAAGACACCAAGGAAGCTTTAGAT\n"
- + ">gi|27804641|gb|AY178922.1|/1-261\n"
- + "-TGGGAGAAAATTCGGTTACGGCCAGGGGGAAAGAAAAGATATAAGTTAAAACATATAGTATGGGCAAGCAG\n"
- + "GGAGCTAGAACGATTCGCAGTCAACCCTGGCCTGTTAGAAACATCAGAAGGCTGCAGACAAATACTGGGACA\n"
- + "GTTACACCCATCCCTTCATACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
- + "TGTGCATCAAAGGATAGAAGTAAAAGACACCAAGGAAGCTTTAGAC\n"
- + ">gi|27804647|gb|AY178925.1|/1-261\n"
- + "-TGGGAAAAAATTCGGTTAAGGCCAGGGGGAAAGAAAAAATATCAATTAAAACATGTAGTATGGGCAAGCAG\n"
- + "GGAACTAGAACGATTCGCAGTTAATCCTGGCCTGTTAGAAACATCAGAAGGCTGTAGACAAATATTGGGACA\n"
- + "GCTACAACCATCCCTTCAGACAGGATCAGAGGAACTTAAATCATTATTTAATACAGTAGCAGTCCTCTATTG\n"
- + "TGTACATCAAAGAATAGATGTAAAAGACACCAAGGAAGCTCTAGAA\n"
- + ">gi|27804649|gb|AY178926.1|/1-261\n"
- + "-TGGGAAAAAATTCGGTTAAGGCCAGGGGGAAAGAAAAAATATAAGTTAAAACATATAGTATGGGCAAGCAG\n"
- + "GGAGCTAGAACGATTCGCGGTCAATCCTGGCCTGTTAGAAACATCAGAAGGCTGTAGACAACTACTGGGACA\n"
- + "GTTACAACCATCCCTTCAGACAGGATCAGAAGAACTCAAATCATTATATAATACAATAGCAACCCTCTATTG\n"
- + "TGTGCATCAAAGGATAGAGATAAAAGACACCAAGGAAGCCTTAGAT\n"
- + ">gi|27804653|gb|AY178928.1|/1-261\n"
- + "-TGGGAAAGAATTCGGTTAAGGCCAGGGGGAAAGAAACAATATAAATTAAAACATATAGTATGGGCAAGCAG\n"
- + "GGAGCTAGACCGATTCGCACTTAACCCCGGCCTGTTAGAAACATCAGAAGGCTGTAGACAAATATTGGGACA\n"
- + "GCTACAATCGTCCCTTCAGACAGGATCAGAAGAACTTAGATCACTATATAATACAGTAGCAGTCCTCTATTG\n"
- + "TGTGCATCAAAAGATAGATGTAAAAGACACCAAGGAAGCCTTAGAC\n"
- + ">gi|27804659|gb|AY178931.1|/1-261\n"
- + "-TGGGAAAAAATTCGGTTACGGCCAGGAGGAAAGAAAAGATATAAATTAAAACATATAGTATGGGCAAGCAG\n"
- + "GGAGCTAGAACGATTYGCAGTTAATCCTGGCCTTTTAGAAACAGCAGAAGGCTGTAGACAAATACTGGGACA\n"
- + "GCTACAACCATCCCTTCAGACAGGATCAGAAGAACTTAAATCATTATATAATACAGTAGCAACCCTCTATTG\n"
- + "TGTACATCAAAGGATAGAGATAAAAGACACCAAGGAAGCTTTAGAA\n";
-
- @Test
- public void translationWithUntranslatableCodonsTest()
- {
- // Corner case for this test is the presence of codons after codons that
- // were not translated.
- jalview.datamodel.AlignmentI alf = null;
- try
- {
- alf = new jalview.io.FormatAdapter().readFile(
- JAL_1312_example_align_fasta, jalview.io.FormatAdapter.PASTE,
- "FASTA");
- } catch (IOException x)
- {
- x.printStackTrace();
- fail("Unexpected IOException (" + x.getMessage()
- + ") - check test environment");
- }
- {
- // full translation
- ColumnSelection cs = new jalview.datamodel.ColumnSelection();
- assertNotNull("Couldn't do a full width translation of test data.",
- jalview.analysis.Dna.cdnaTranslate(
- alf.getSequencesArray(),
- cs.getVisibleSequenceStrings(0, alf.getWidth(),
- alf.getSequencesArray()), new int[]
- { 0, alf.getWidth() - 1 }, alf.getGapCharacter(),
- null, alf.getWidth(), null));
- }
- int vwidth = 15; // translate in 15 base stretches
- for (int ipos = 0; ipos + vwidth < alf.getWidth(); ipos += vwidth)
- {
- ColumnSelection cs = new jalview.datamodel.ColumnSelection();
- if (ipos > 0)
- {
- cs.hideColumns(0, ipos - 1);
- }
- cs.hideColumns(ipos + vwidth, alf.getWidth());
- int[] vcontigs = cs.getVisibleContigs(0, alf.getWidth());
- String[] sel = cs.getVisibleSequenceStrings(0, alf.getWidth(),
- alf.getSequencesArray());
- jalview.datamodel.AlignmentI transAlf = jalview.analysis.Dna
- .cdnaTranslate(alf.getSequencesArray(), sel, vcontigs,
- alf.getGapCharacter(), null, alf.getWidth(), null);
-
- assertTrue("Translation failed (ipos=" + ipos
- + ") No alignment data.", transAlf != null);
- assertTrue("Translation failed (ipos=" + ipos + ") Empty algnment.",
- transAlf.getHeight() > 0);
- assertTrue("Translation failed (ipos=" + ipos + ") Translated "
- + transAlf.getHeight() + " sequences from " + alf.getHeight()
- + " sequences", alf.getHeight() == transAlf.getHeight());
- }
-
- }
-}