</field>
</class>
<class name="jalview.datamodel.xdb.embl.EmblEntry">
- <map-to xml="entry"/>
<field name="accession" type="string">
<bind-xml location="accession" node="attribute"/>
</field>
+ <!-- May 2015 changed from last-updated to match xml -->
<field name="lastUpdated" type="string">
- <bind-xml location="last-updated" node="attribute"/>
+ <bind-xml location="lastUpdated" node="attribute"/>
</field>
<field name="version" type="string">
<bind-xml location="version" node="attribute"/>
</field>
-
<field name="rCreated" type="string">
<bind-xml location="releaseCreated" node="attribute"/>
</field>
<field name="desc" type="string">
<bind-xml name="description" node="element"/>
</field>
- <field name="Keywords" type="string" collection="vector">
+ <field name="keywords" type="string" collection="vector">
<bind-xml name="keyword" node="element"/>
</field>
<field name="features" type="jalview.datamodel.xdb.embl.EmblFeature" collection="vector">
<bind-xml name="dbreference" />
</field>
<field name="sequence" type="jalview.datamodel.xdb.embl.EmblSequence">
- <bind-xml name="sequence"/> <!-- location="sequence" node="element"/ -->
+ <bind-xml name="sequence"/>
</field>
</class>
<class name="jalview.datamodel.xdb.embl.EmblSequence">
- <map-to xml="sequence"/>
<field name="type" type="string">
<bind-xml name="type" node="attribute" location="type"/>
</field>
</field>
</class>
<class name="jalview.datamodel.xdb.embl.EmblFeature" verify-constructable="false">
- <map-to xml="feature"/>
<field name="name" type="string">
<bind-xml name="name" node="attribute"/>
</field>
</field>
</class>
<class name="jalview.datamodel.DBRefEntry" verify-constructable="false">
- <field name="accessionId" type="java.lang.String"><!-- set-method="setAccessionId" get-method="getAccessionId"> -->
+ <field name="accessionId" type="java.lang.String">
<bind-xml name="primary" node="attribute"/>
</field>
- <field name="source" type="java.lang.String"> <!--set-method="setSource" get-method="getSource"> -->
+ <field name="source" type="java.lang.String">
<bind-xml name="db" node="attribute"/>
</field>
- <field name="version" type="string"><!-- set-method="setVersion" get-method="getVersion"> -->
+ <field name="version" type="string">
<bind-xml name="secondary" node="attribute"/>
</field>
</class>
<class name="jalview.datamodel.xdb.embl.Qualifier" verify-constructable="false">
- <map-to xml="Qualifier"/>
<field name="name">
<bind-xml name="name" node="attribute"/>
</field>
</field>
</class>
<class name="jalview.datamodel.xdb.embl.EmblFeatureLocations">
- <map-to xml="location"/>
<field name="locationType" type="string">
<bind-xml name="type" node="attribute"/>
</field>
</field>
</class>
<class name="jalview.datamodel.xdb.embl.EmblFeatureLocElement">
- <map-to xml="locationElement"/>
<field name="type" type="string">
<bind-xml name="type" node="attribute"/>
</field>
</field>
</class>
<class name="jalview.datamodel.xdb.embl.BasePosition">
- <map-to xml="basePosition"/>
<field name="type">
<bind-xml name="type" node="attribute"/>
</field>
//
package com.stevesoft.pat;
-import java.io.*;
+import java.io.IOException;
+import java.io.Writer;
-import com.stevesoft.pat.wrap.*;
+import com.stevesoft.pat.wrap.WriterWrap;
/**
* A basic extension of FilterWriter that uses Transformer to make replacements
*
* @deprecated
*/
+ @Deprecated
public char getEOLchar()
{
return EOLchar;
*
* @deprecated
*/
+ @Deprecated
public void setEOLchar(char c)
{
EOLchar = c;
*
* @deprecated
*/
+ @Deprecated
public int getMaxLines()
{
return max_lines;
*
* @deprecated
*/
+ @Deprecated
public void setMaxLines(int ml)
{
max_lines = ml;
{
bufferSize = i;
}
-
- static void test(String re, String inp, int n) throws Exception
- {
- StringWriter sw = new StringWriter();
- Regex rex = Regex.perlCode(re);
- String res1 = rex.replaceAll(inp);
- RegexWriter rw = new RegexWriter(rex, sw);
- for (int i = 0; i < inp.length(); i++)
- {
- rw.write(inp.charAt(i));
- }
- rw.close();
- String res2 = sw.toString();
- if (!res1.equals(res2))
- {
- System.out.println("nmax=" + n);
- System.out.println("re=" + re);
- System.out.println("inp=" + inp);
- System.out.println("res1=" + res1);
- System.out.println("res2=" + res2);
- System.exit(255);
- }
- }
-
- public static void main(String[] args) throws Exception
- {
- for (int n = 1; n <= 1; n++)
- {
- test("s/x/y/", "-----x123456789", n);
- test("s/x/y/", "x123456789", n);
- test("s/x/y/", "-----x", n);
- test("s/x.*?x/y/", ".xx..x..x...x...x....x....x", n);
- test("s/x.*x/[$&]/", "--x........x--xx", n);
- test("s/x.*x/[$&]/", "--x........x------", n);
- test("s/.$/a/m", "bb\nbbb\nbbbb\nbbbbb\nbbbbbb\nbbbbbbbbbbbb", n);
- test("s/.$/a/", "123", n);
- test("s/.$/a/", "bb\nbbb\nbbbb\nbbbbb\nbbbbbb\nbb", n);
- test("s/^./a/", "bb\nbbb\nbbbb\nbbbbb\nbbbbbb\nbb", n);
- test("s/$/a/", "bbb", n);
- test("s/^/a/", "bbb", n);
- test("s/^/a/", "", n);
- test("s{.*}{N}", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", n);
- test("s/.{0,7}/y/", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", n);
- test("s/x/$&/", "xxx", n);
- }
- System.out.println("Success!!!");
- }
}
package jalview.analysis;
-import jalview.datamodel.AlignmentAnnotation;
-import jalview.datamodel.SequenceI;
-import jalview.renderer.AnnotationRenderer;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.List;
import java.util.Map;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.SequenceI;
+import jalview.renderer.AnnotationRenderer;
+
public class AlignmentAnnotationUtils
{
for (AlignmentAnnotation aa : annotations)
{
+ /*
+ * Ignore non-positional annotations, can't render these against an
+ * alignment
+ */
+ if (aa.annotations == null)
+ {
+ continue;
+ }
if (forSequences != null
&& (aa.sequenceRef != null && forSequences
.contains(aa.sequenceRef)))
for (SequenceI s : core.getSequences())
{
SequenceI newSeq = s.deriveSequence();
- if (newSeq.getStart() > maxoffset
+ final int newSeqStart = newSeq.getStart() - 1;
+ if (newSeqStart > maxoffset
&& newSeq.getDatasetSequence().getStart() < s.getStart())
{
- maxoffset = newSeq.getStart();
+ maxoffset = newSeqStart;
}
sq.add(newSeq);
}
if (flankSize > -1)
{
- maxoffset = flankSize;
+ maxoffset = Math.min(maxoffset, flankSize);
}
- // now add offset to create a new expanded alignment
+
+ /*
+ * now add offset left and right to create an expanded alignment
+ */
for (SequenceI s : sq)
{
SequenceI ds = s;
}
int s_end = s.findPosition(s.getStart() + s.getLength());
// find available flanking residues for sequence
- int ustream_ds = s.getStart() - ds.getStart(), dstream_ds = ds
- .getEnd() - s_end;
+ int ustream_ds = s.getStart() - ds.getStart();
+ int dstream_ds = ds.getEnd() - s_end;
// build new flanked sequence
offset = maxoffset - flankSize;
ustream_ds = flankSize;
}
- if (flankSize < dstream_ds)
+ if (flankSize <= dstream_ds)
{
- dstream_ds = flankSize;
+ dstream_ds = flankSize - 1;
}
}
+ // TODO use Character.toLowerCase to avoid creating String objects?
char[] upstream = new String(ds.getSequence(s.getStart() - 1
- ustream_ds, s.getStart() - 1)).toLowerCase().toCharArray();
- char[] downstream = new String(ds.getSequence(s_end - 1, s_end + 1
+ char[] downstream = new String(ds.getSequence(s_end - 1, s_end
+ dstream_ds)).toLowerCase().toCharArray();
char[] coreseq = s.getSequence();
char[] nseq = new char[offset + upstream.length + downstream.length
+ coreseq.length];
char c = core.getGapCharacter();
- // TODO could lowercase the flanking regions
+
int p = 0;
for (; p < offset; p++)
{
nseq[p] = c;
}
- // s.setSequence(new String(upstream).toLowerCase()+new String(coreseq) +
- // new String(downstream).toLowerCase());
+
System.arraycopy(upstream, 0, nseq, p, upstream.length);
System.arraycopy(coreseq, 0, nseq, p + upstream.length,
coreseq.length);
{
for (AlignmentAnnotation aa : s.getAnnotation())
{
+ aa.adjustForAlignment(); // JAL-1712 fix
newAl.addAnnotation(aa);
}
}
import com.stevesoft.pat.Regex;
-import jalview.datamodel.*;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
public class ParseProperties
{
ScoreNames = tnames;
String descrbase = ScoreDescriptions[onamelen - 1];
if (descrbase == null)
+ {
descrbase = "Score parsed from (" + regex + ")";
+ }
tnames = new String[pattern.numSubs() + 1];
System.arraycopy(ScoreDescriptions, 0, tnames, 0,
ScoreDescriptions.length);
{
String descr = seqs[i].getDescription();
if (descr == null)
+ {
continue;
+ }
int pos = 0;
boolean added = false;
int reps = 0;
+ ((reps > 0) ? "_" + reps : ""),
ScoreDescriptions[cols], null);
an.setScore(score);
- System.out.println("Score: " + ScoreNames[cols] + "=" + score); // DEBUG
+ System.out.println(seqs[i].getName() + " score: '"
+ + ScoreNames[cols] + "' = " + score); // DEBUG
an.setSequenceRef(seqs[i]);
seqs[i].addAlignmentAnnotation(an);
al.addAnnotation(an);
}
return count;
}
-
- public static void main(String argv[])
- {
- SequenceI[] seqs = new SequenceI[]
- { new Sequence("sq1", "THISISAPLACEHOLDER"),
- new Sequence("sq2", "THISISAPLACEHOLDER"),
- new Sequence("sq3", "THISISAPLACEHOLDER"),
- new Sequence("sq4", "THISISAPLACEHOLDER") };
- seqs[0].setDescription("1 mydescription1");
- seqs[1].setDescription("mydescription2");
- seqs[2].setDescription("2. 0.1 mydescription3");
- seqs[3].setDescription("3 0.01 mydescription4");
- // seqs[4].setDescription("5 mydescription5");
- Alignment al = new Alignment(seqs);
- ParseProperties pp = new ParseProperties(al);
- String regex = ".*([-0-9.+]+)";
- System.out.println("Matched "
- + pp.getScoresFromDescription("my Score",
- "my Score Description", regex, true) + " for " + regex);
- regex = ".*([-0-9.+]+).+([-0-9.+]+).*";
- System.out.println("Matched "
- + pp.getScoresFromDescription("my Score",
- "my Score Description", regex, true) + " for " + regex);
- System.out.println("Finished.");
- }
}
*/
package jalview.appletgui;
-import java.util.*;
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.datamodel.*;
+import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Choice;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.GridLayout;
+import java.awt.Label;
+import java.awt.Panel;
+import java.awt.ScrollPane;
+import java.awt.TextArea;
+import java.awt.TextField;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Hashtable;
+
+import jalview.datamodel.SearchResults;
+import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.SequenceI;
import jalview.schemes.AnnotationColourGradient;
import jalview.schemes.GraduatedColor;
import jalview.util.MessageManager;
import jalview.viewmodel.AlignmentViewport;
-import jalview.viewmodel.seqfeatures.FeaturesDisplayed;
/**
* DOCUMENT ME!
* @author $author$
* @version $Revision$
*/
-public class FeatureRenderer extends jalview.renderer.seqfeatures.FeatureRenderer
+public class FeatureRenderer extends
+ jalview.renderer.seqfeatures.FeatureRenderer
{
// Holds web links for feature groups and feature types
super();
this.av = av;
- setTransparencyAvailable(!System.getProperty("java.version").startsWith("1.1"));
+ setTransparencyAvailable(!System.getProperty("java.version")
+ .startsWith("1.1"));
}
static String lastFeatureAdded;
}
else
{
- throw new Error(MessageManager.getString("error.invalid_colour_for_mycheckbox"));
+ throw new Error(
+ MessageManager
+ .getString("error.invalid_colour_for_mycheckbox"));
}
if (col != null)
{
+ "-" + features[i].getEnd();
if (features[i].getFeatureGroup() != null)
+ {
item += " (" + features[i].getFeatureGroup() + ")";
+ }
overlaps.addItem(item);
}
}
}
- String title = newFeatures ? MessageManager.getString("label.create_new_sequence_features")
- : MessageManager.formatMessage("label.amend_delete_features", new String[]{sequences[0].getName()});
+ String title = newFeatures ? MessageManager
+ .getString("label.create_new_sequence_features")
+ : MessageManager.formatMessage("label.amend_delete_features",
+ new String[]
+ { sequences[0].getName() });
final JVDialog dialog = new JVDialog(ap.alignFrame, title, true, 385,
240);
}
if (lastFeatureGroupAdded != null && lastFeatureGroupAdded.length() < 1)
+ {
lastFeatureGroupAdded = null;
+ }
if (!newFeatures)
{
}
ffile.parseDescriptionHTML(sf, false);
- setVisible(lastFeatureAdded); // if user edited name then make sure new type is visible
+ setVisible(lastFeatureAdded); // if user edited name then make sure new
+ // type is visible
}
if (deleteFeature)
{
ffile.parseDescriptionHTML(features[i], false);
}
- col = colourPanel.getBackground();
+ Color newColour = colourPanel.getBackground();
// setColour(lastFeatureAdded, fcol);
if (lastFeatureGroupAdded != null)
{
setGroupVisibility(lastFeatureGroupAdded, true);
}
- setColour(lastFeatureAdded, fcol);
+ setColour(lastFeatureAdded, newColour); // was fcol
setVisible(lastFeatureAdded);
- findAllFeatures(false); // different to original applet behaviour ?
+ findAllFeatures(false); // different to original applet behaviour ?
// findAllFeatures();
}
else
*/
package jalview.appletgui;
-import jalview.datamodel.SequenceGroup;
-import jalview.schemes.ColourSchemeI;
-import jalview.schemes.GraduatedColor;
-import jalview.schemes.ResidueProperties;
-import jalview.schemes.UserColourScheme;
-import jalview.util.MessageManager;
-
import java.awt.Button;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
import java.awt.event.MouseEvent;
import java.util.Vector;
+import jalview.datamodel.SequenceGroup;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.GraduatedColor;
+import jalview.schemes.ResidueProperties;
+import jalview.schemes.UserColourScheme;
+import jalview.util.MessageManager;
+
public class UserDefinedColours extends Panel implements ActionListener,
- AdjustmentListener
+ AdjustmentListener, FocusListener
{
AlignmentPanel ap;
public void actionPerformed(ActionEvent evt)
{
- if (evt.getSource() == okButton)
+ final Object source = evt.getSource();
+ if (source == okButton)
{
okButton_actionPerformed();
}
- else if (evt.getSource() == applyButton)
+ else if (source == applyButton)
{
applyButton_actionPerformed();
}
- else if (evt.getSource() == cancelButton)
+ else if (source == cancelButton)
{
cancelButton_actionPerformed();
}
- else if (evt.getSource() == rText)
+ else if (source == rText)
{
rText_actionPerformed();
}
- else if (evt.getSource() == gText)
+ else if (source == gText)
{
gText_actionPerformed();
}
- else if (evt.getSource() == bText)
+ else if (source == bText)
{
bText_actionPerformed();
}
rText.setText("0 ");
rText.setBounds(new Rectangle(156, 27, 53, 19));
rText.addActionListener(this);
+ rText.addFocusListener(this);
label4.setAlignment(Label.RIGHT);
label4.setText("G");
label4.setBounds(new Rectangle(15, 56, 20, 15));
gText.setText("0 ");
gText.setBounds(new Rectangle(156, 52, 53, 20));
gText.addActionListener(this);
+ gText.addFocusListener(this);
label5.setAlignment(Label.RIGHT);
label5.setText("B");
label5.setBounds(new Rectangle(14, 82, 20, 15));
bText.setText("0 ");
bText.setBounds(new Rectangle(157, 78, 52, 20));
bText.addActionListener(this);
+ bText.addFocusListener(this);
target.setBackground(Color.black);
target.setBounds(new Rectangle(229, 26, 134, 79));
this.add(okcancelPanel, null);
okcancelPanel.add(okButton, null);
okcancelPanel.add(applyButton, null);
okcancelPanel.add(cancelButton, null);
+ this.add(rText);
+ this.add(gText);
+ this.add(bText);
this.add(buttonPanel, null);
this.add(target, null);
this.add(gScroller);
this.add(label5);
this.add(label4);
this.add(label1);
- this.add(gText);
- this.add(rText);
- this.add(bText);
+ }
+
+ @Override
+ public void focusGained(FocusEvent e)
+ {
+ // noop
+ }
+
+ /**
+ * This method applies any change to an RGB value if the user tabs out of the
+ * field instead of pressing Enter
+ */
+ @Override
+ public void focusLost(FocusEvent e)
+ {
+ Component c = e.getComponent();
+ if (c == rText)
+ {
+ rText_actionPerformed();
+ }
+ else
+ {
+ if (c == gText)
+ {
+ gText_actionPerformed();
+ }
+ else
+ {
+ if (c == bText)
+ {
+ bText_actionPerformed();
+ }
+ }
+ }
}
}
*/
package jalview.datamodel;
-import jalview.analysis.Rna;
-import jalview.analysis.SecStrConsensus.SimpleBP;
-import jalview.analysis.WUSSParseException;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
+import jalview.analysis.Rna;
+import jalview.analysis.SecStrConsensus.SimpleBP;
+import jalview.analysis.WUSSParseException;
+
/**
* DOCUMENT ME!
*
{
if (properties == null)
{
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
return properties.keySet();
}
+
+ /**
+ * Returns the Annotation for the given sequence position (base 1) if any,
+ * else null
+ *
+ * @param position
+ * @return
+ */
+ public Annotation getAnnotationForPosition(int position)
+ {
+ return sequenceMapping == null ? null : sequenceMapping.get(position);
+
+ }
}
*/
package jalview.datamodel;
-import jalview.util.MapList;
-
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Vector;
+import jalview.util.MapList;
+
public class Mapping
{
/**
return copy;
}
- public static void main(String[] args)
- {
- /**
- * trite test of the intersectVisContigs method for a simple DNA -> Protein
- * exon map and a range of visContigs
- */
- MapList fk = new MapList(new int[]
- { 1, 6, 8, 13, 15, 23 }, new int[]
- { 1, 7 }, 3, 1);
- Mapping m = new Mapping(fk);
- Mapping m_1 = m.intersectVisContigs(new int[]
- { fk.getFromLowest(), fk.getFromHighest() });
- Mapping m_2 = m.intersectVisContigs(new int[]
- { 1, 7, 11, 20 });
- System.out.println("" + m_1.map.getFromRanges());
-
- }
-
/**
* get the sequence being mapped to - if any
*
return file;
}
+ public void setType(String t)
+ {
+ this.type = t;
+ }
public void setType(PDBEntry.Type type)
{
- this.type = type.toString();
+ this.type = type == null ? null : type.toString();
}
public String getType()
import java.util.Enumeration;
import java.util.Hashtable;
-import jalview.analysis.*;
-import jalview.util.*;
+import jalview.analysis.AlignSeq;
+import jalview.analysis.SeqsetUtils;
+import jalview.util.MessageManager;
+import jalview.util.ShiftList;
public class SeqCigar extends CigarSimple
{
}
/**
- * non rigorous testing
- */
- /**
- *
- * @param seq
- * Sequence
- * @param ex_cs_gapped
- * String
- * @return String
- */
- public static String testCigar_string(Sequence seq, String ex_cs_gapped)
- {
- SeqCigar c_sgapped = new SeqCigar(seq);
- String cs_gapped = c_sgapped.getCigarstring();
- if (!cs_gapped.equals(ex_cs_gapped))
- {
- System.err.println("Failed getCigarstring: incorect string '"
- + cs_gapped + "' != " + ex_cs_gapped);
- }
- return cs_gapped;
- }
-
- public static boolean testSeqRecovery(SeqCigar gen_sgapped,
- SequenceI s_gapped)
- {
- // this is non-rigorous - start and end recovery is not tested.
- SequenceI gen_sgapped_s = gen_sgapped.getSeq('-');
- if (!gen_sgapped_s.getSequence().equals(s_gapped.getSequence()))
- {
- System.err.println("Couldn't reconstruct sequence.\n"
- + gen_sgapped_s.getSequenceAsString() + "\n"
- + s_gapped.getSequenceAsString());
- return false;
- }
- return true;
- }
-
- public static void main(String argv[]) throws Exception
- {
- String o_seq;
- Sequence s = new Sequence("MySeq",
- o_seq = "asdfktryasdtqwrtsaslldddptyipqqwaslchvhttt", 39, 80);
- String orig_gapped;
- Sequence s_gapped = new Sequence(
- "MySeq",
- orig_gapped = "----asdf------ktryas---dtqwrtsasll----dddptyipqqwa----slchvhttt",
- 39, 80);
- String ex_cs_gapped = "4I4M6I6M3I11M4I12M4I9M";
- s_gapped.setDatasetSequence(s);
- String sub_gapped_s;
- Sequence s_subsequence_gapped = new Sequence(
- "MySeq",
- sub_gapped_s = "------ktryas---dtqwrtsasll----dddptyipqqwa----slchvh",
- 43, 77);
-
- s_subsequence_gapped.setDatasetSequence(s);
- SeqCigar c_null = new SeqCigar(s);
- String cs_null = c_null.getCigarstring();
- if (!cs_null.equals("42M"))
- {
- System.err
- .println("Failed to recover ungapped sequence cigar operations:"
- + ((cs_null == "") ? "empty string" : cs_null));
- }
- testCigar_string(s_gapped, ex_cs_gapped);
- SeqCigar gen_sgapped = SeqCigar.parseCigar(s, ex_cs_gapped);
- if (!gen_sgapped.getCigarstring().equals(ex_cs_gapped))
- {
- System.err.println("Failed parseCigar(" + ex_cs_gapped
- + ")->getCigarString()->'" + gen_sgapped.getCigarstring()
- + "'");
- }
- testSeqRecovery(gen_sgapped, s_gapped);
- // Test dataset resolution
- SeqCigar sub_gapped = new SeqCigar(s_subsequence_gapped);
- if (!testSeqRecovery(sub_gapped, s_subsequence_gapped))
- {
- System.err
- .println("Failed recovery for subsequence of dataset sequence");
- }
- // width functions
- if (sub_gapped.getWidth() != sub_gapped_s.length())
- {
- System.err.println("Failed getWidth()");
- }
-
- sub_gapped.getFullWidth();
- if (sub_gapped.hasDeletedRegions())
- {
- System.err.println("hasDeletedRegions is incorrect.");
- }
- // Test start-end region SeqCigar
- SeqCigar sub_se_gp = new SeqCigar(s_subsequence_gapped, 8, 48);
- if (sub_se_gp.getWidth() != 41)
- {
- System.err
- .println("SeqCigar(seq, start, end) not properly clipped alignsequence.");
- }
- System.out.println("Original sequence align:\n" + sub_gapped_s
- + "\nReconstructed window from 8 to 48\n" + "XXXXXXXX"
- + sub_se_gp.getSequenceString('-') + "..." + "\nCigar String:"
- + sub_se_gp.getCigarstring() + "\n");
- SequenceI ssgp = sub_se_gp.getSeq('-');
- System.out.println("\t " + ssgp.getSequenceAsString());
- for (int r = 0; r < 10; r++)
- {
- sub_se_gp = new SeqCigar(s_subsequence_gapped, 8, 48);
- int sl = sub_se_gp.getWidth();
- int st = sl - 1 - r;
- for (int rs = 0; rs < 10; rs++)
- {
- int e = st + rs;
- sub_se_gp.deleteRange(st, e);
- String ssgapedseq = sub_se_gp.getSeq('-').getSequenceAsString();
- System.out.println(st + "," + e + "\t:" + ssgapedseq);
- st -= 3;
- }
- }
- {
- SeqCigar[] set = new SeqCigar[]
- { new SeqCigar(s), new SeqCigar(s_subsequence_gapped, 8, 48),
- new SeqCigar(s_gapped) };
- Alignment al = new Alignment(set);
- for (int i = 0; i < al.getHeight(); i++)
- {
- System.out.println("" + al.getSequenceAt(i).getName() + "\t"
- + al.getSequenceAt(i).getStart() + "\t"
- + al.getSequenceAt(i).getEnd() + "\t"
- + al.getSequenceAt(i).getSequenceAsString());
- }
- }
- {
- System.out.println("Gapped.");
- SeqCigar[] set = new SeqCigar[]
- { new SeqCigar(s), new SeqCigar(s_subsequence_gapped, 8, 48),
- new SeqCigar(s_gapped) };
- set[0].deleteRange(20, 25);
- Alignment al = new Alignment(set);
- for (int i = 0; i < al.getHeight(); i++)
- {
- System.out.println("" + al.getSequenceAt(i).getName() + "\t"
- + al.getSequenceAt(i).getStart() + "\t"
- + al.getSequenceAt(i).getEnd() + "\t"
- + al.getSequenceAt(i).getSequenceAsString());
- }
- }
- // if (!ssgapedseq.equals("ryas---dtqqwa----slchvh"))
- // System.err.println("Subseqgaped\n------ktryas---dtqwrtsasll----dddptyipqqwa----slchvhryas---dtqwrtsasll--qwa----slchvh\n"+ssgapedseq+"\n"+sub_se_gp.getCigarstring());
- }
-
- /**
* references to entities that this sequence cigar is associated with.
*/
private Hashtable selGroups = null;
*/
package jalview.datamodel;
-import jalview.analysis.AlignSeq;
-import jalview.util.StringUtils;
-
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import fr.orsay.lri.varna.models.rna.RNA;
+import jalview.analysis.AlignSeq;
+import jalview.util.StringUtils;
+
/**
*
* Implements the SequenceI interface for a char[] based sequence object.
.println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
name = "";
}
- // Does sequence have the /start-end signiature?
+ // Does sequence have the /start-end signature?
if (limitrx.search(name))
{
name = limitrx.left();
* @param id
* DOCUMENT ME!
*/
- public void setPDBId(Vector id)
+ @Override
+ public void setPDBId(Vector<PDBEntry> id)
{
pdbIds = id;
}
*
* @return DOCUMENT ME!
*/
- public Vector getPDBId()
+ @Override
+ public Vector<PDBEntry> getPDBId()
{
return pdbIds;
}
{
if (this.annotation == null)
{
- this.annotation = new Vector();
+ this.annotation = new Vector<AlignmentAnnotation>();
}
if (!this.annotation.contains(annotation))
{
public char[] getSequence(int start, int end);
/**
- * create a new sequence object from start to end of this sequence
+ * create a new sequence object with a subsequence of this one but sharing the
+ * same dataset sequence
*
* @param start
- * int index for start position
+ * int index for start position (base 0, inclusive)
* @param end
- * int index for end position
+ * int index for end position (base 0, exclusive)
*
* @return SequenceI
* @note implementations may use getSequence to get the sequence data
*/
package jalview.datamodel;
-import java.util.*;
+import java.util.Vector;
+/**
+ * Data model for an entry returned from a Uniprot query
+ *
+ * @see uniprot_mapping.xml
+ */
public class UniprotEntry
{
UniprotSequence sequence;
- Vector name;
+ Vector<String> name;
- Vector accession;
+ Vector<String> accession;
- Vector feature;
+ Vector<SequenceFeature> feature;
- Vector dbrefs;
+ Vector<PDBEntry> dbrefs;
UniprotProteinName protName;
- public void setAccession(Vector items)
+ public void setAccession(Vector<String> items)
{
accession = items;
}
- public void setFeature(Vector items)
+ public void setFeature(Vector<SequenceFeature> items)
{
feature = items;
}
- public Vector getFeature()
+ public Vector<SequenceFeature> getFeature()
{
return feature;
}
- public Vector getAccession()
+ public Vector<String> getAccession()
{
return accession;
}
return protName;
}
- public void setName(Vector na)
+ public void setName(Vector<String> na)
{
name = na;
}
- public Vector getName()
+ public Vector<String> getName()
{
return name;
}
sequence = seq;
}
- public Vector getDbReference()
+ public Vector<PDBEntry> getDbReference()
{
return dbrefs;
}
- public void setDbReference(Vector dbref)
+ public void setDbReference(Vector<PDBEntry> dbref)
{
this.dbrefs = dbref;
}
*/
package jalview.datamodel;
-import java.util.*;
+import java.util.Vector;
+/**
+ * Data model of a retrieved Uniprot entry, as unmarshalled by Castor using a
+ * binding file (uniprot_mapping.xml)
+ */
public class UniprotFile
{
- Vector _items;
+ Vector<UniprotEntry> _items;
- public void setUniprotEntries(Vector items)
+ public void setUniprotEntries(Vector<UniprotEntry> items)
{
_items = items;
}
- public Vector getUniprotEntries()
+ public Vector<UniprotEntry> getUniprotEntries()
{
return _items;
}
*/
package jalview.datamodel;
+import java.util.Vector;
+
+/**
+ * Data model for protein name returned from a Uniprot query
+ *
+ * Protein names are read from the Uniprot XML element
+ * uniprot/entry/protein/recommendedName/fullName
+ *
+ * @see uniprot_mapping.xml
+ */
public class UniprotProteinName
{
- /**
- * internal content storage
- */
- private java.util.Vector names;
+ private Vector<String> names;
- public void setName(java.util.Vector names)
+ public void setName(Vector<String> names)
{
this.names = names;
}
- public java.util.Vector getName()
+ public Vector<String> getName()
{
return names;
}
*/
package jalview.datamodel;
+/**
+ * Data model for the sequence returned by a Uniprot query
+ *
+ * @see uniprot_mapping.xml
+ */
public class UniprotSequence
{
+ private String _content = "";
+
/**
- * internal content storage
+ * Sets the content string, omitting any space characters
+ *
+ * @param seq
*/
- private java.lang.String _content = "";
-
public void setContent(String seq)
{
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < seq.length(); i++)
+ if (seq != null)
{
- if (seq.charAt(i) != ' ')
+ StringBuilder sb = new StringBuilder(seq.length());
+ for (int i = 0; i < seq.length(); i++)
{
- sb.append(seq.charAt(i));
+ if (seq.charAt(i) != ' ')
+ {
+ sb.append(seq.charAt(i));
+ }
}
+ _content = sb.toString();
}
- _content = sb.toString();
}
public String getContent()
*/
package jalview.datamodel.xdb.embl;
+/**
+ * Data model for a feature/location/locationElement/basePosition read from an
+ * EMBL query reply
+ *
+ * @see embl_mapping.xml
+ */
public class BasePosition
{
String type;
*/
package jalview.datamodel.xdb.embl;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Vector;
+
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.DBRefSource;
import jalview.datamodel.FeatureProperties;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Vector;
-
+/**
+ * Data model for one entry returned from an EMBL query, as marshalled by a
+ * Castor binding file
+ *
+ * For example: http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/embl/x53828/emblxml
+ *
+ * @see embl_mapping.xml
+ */
public class EmblEntry
{
String accession;
String lastUpdated;
- Vector keywords;
-
- Vector refs;
+ Vector<String> keywords;
- Vector dbRefs;
+ Vector<DBRefEntry> dbRefs;
- Vector features;
+ Vector<EmblFeature> features;
EmblSequence sequence;
/**
* @return the dbRefs
*/
- public Vector getDbRefs()
+ public Vector<DBRefEntry> getDbRefs()
{
return dbRefs;
}
* @param dbRefs
* the dbRefs to set
*/
- public void setDbRefs(Vector dbRefs)
+ public void setDbRefs(Vector<DBRefEntry> dbRefs)
{
this.dbRefs = dbRefs;
}
/**
* @return the features
*/
- public Vector getFeatures()
+ public Vector<EmblFeature> getFeatures()
{
return features;
}
* @param features
* the features to set
*/
- public void setFeatures(Vector features)
+ public void setFeatures(Vector<EmblFeature> features)
{
this.features = features;
}
/**
* @return the keywords
*/
- public Vector getKeywords()
+ public Vector<String> getKeywords()
{
return keywords;
}
* @param keywords
* the keywords to set
*/
- public void setKeywords(Vector keywords)
+ public void setKeywords(Vector<String> keywords)
{
this.keywords = keywords;
}
}
/**
- * @return the refs
- */
- public Vector getRefs()
- {
- return refs;
- }
-
- /**
- * @param refs
- * the refs to set
- */
- public void setRefs(Vector refs)
- {
- this.refs = refs;
- }
-
- /**
* @return the releaseCreated
*/
public String getRCreated()
* @param releaseCreated
* the releaseCreated to set
*/
- public void setRcreated(String releaseCreated)
+ public void setRCreated(String releaseCreated)
{
this.rCreated = releaseCreated;
}
*/
package jalview.datamodel.xdb.embl;
+/**
+ * Data model mapped from any <error> elements returned from an EMBL query
+ *
+ * @see embl_mapping.xml
+ */
public class EmblError
{
String accession;
import java.util.Vector;
+import jalview.datamodel.DBRefEntry;
+
+/**
+ * Data model for a <feature> element returned from an EMBL query reply
+ *
+ * @see embl_mapping.xml
+ */
public class EmblFeature
{
String name;
- Vector dbRefs;
+ Vector<DBRefEntry> dbRefs;
- Vector qualifiers;
+ Vector<Qualifier> qualifiers;
- Vector locations;
+ Vector<EmblFeatureLocations> locations;
/**
* @return the dbRefs
*/
- public Vector getDbRefs()
+ public Vector<DBRefEntry> getDbRefs()
{
return dbRefs;
}
* @param dbRefs
* the dbRefs to set
*/
- public void setDbRefs(Vector dbRefs)
+ public void setDbRefs(Vector<DBRefEntry> dbRefs)
{
this.dbRefs = dbRefs;
}
/**
* @return the locations
*/
- public Vector getLocations()
+ public Vector<EmblFeatureLocations> getLocations()
{
return locations;
}
* @param locations
* the locations to set
*/
- public void setLocations(Vector locations)
+ public void setLocations(Vector<EmblFeatureLocations> locations)
{
this.locations = locations;
}
/**
* @return the qualifiers
*/
- public Vector getQualifiers()
+ public Vector<Qualifier> getQualifiers()
{
return qualifiers;
}
* @param qualifiers
* the qualifiers to set
*/
- public void setQualifiers(Vector qualifiers)
+ public void setQualifiers(Vector<Qualifier> qualifiers)
{
this.qualifiers = qualifiers;
}
*/
package jalview.datamodel.xdb.embl;
+/**
+ * Data model for a feature/location/locationElement read from an EMBL query
+ * reply
+ *
+ * @see embl_mapping.xml
+ */
public class EmblFeatureLocElement
{
String type;
*/
package jalview.datamodel.xdb.embl;
-import java.util.Enumeration;
import java.util.Vector;
+/**
+ * Data model for a <loctaion> child element of a <feature> read
+ * from an EMBL query reply
+ *
+ * @see embl_mapping.xml
+ */
public class EmblFeatureLocations
{
- Vector locElements;
+ Vector<EmblFeatureLocElement> locElements;
String locationType;
/**
* @return the locElements
*/
- public Vector getLocElements()
+ public Vector<EmblFeatureLocElement> getLocElements()
{
return locElements;
}
* @param locElements
* the locElements to set
*/
- public void setLocElements(Vector locElements)
+ public void setLocElements(Vector<EmblFeatureLocElement> locElements)
{
this.locElements = locElements;
}
{
int sepos = 0;
int[] se = new int[locElements.size() * 2];
- if (locationType.equalsIgnoreCase("single"))
+ if (locationType.equalsIgnoreCase("single")) // TODO: or "simple" ?
{
- for (Enumeration le = locElements.elements(); le.hasMoreElements();)
+ for (EmblFeatureLocElement loce : locElements)
{
- EmblFeatureLocElement loce = (EmblFeatureLocElement) le
- .nextElement();
if (accession == null || loce.accession != null
&& accession.equals(loce.accession))
{
}
else if (locationType.equalsIgnoreCase("join"))
{
- for (Enumeration le = locElements.elements(); le.hasMoreElements();)
+ for (EmblFeatureLocElement loce : locElements)
{
- EmblFeatureLocElement loce = (EmblFeatureLocElement) le
- .nextElement();
if (accession == null || loce.accession != null
&& accession.equals(loce.accession))
{
else if (locationType != null)
{
if (jalview.bin.Cache.log != null)
+ {
jalview.bin.Cache.log
.error("EmbleFeatureLocations.getElementRanges cannot deal with locationType=='"
+ locationType + "'");
+ }
else
+ {
System.err
.println("EmbleFeatureLocations.getElementRanges cannot deal with locationType=='"
+ locationType + "'");
+ }
}
// trim range if necessary.
if (se != null && sepos != se.length)
import java.io.File;
import java.io.FileReader;
+import java.io.PrintWriter;
import java.io.Reader;
import java.util.Vector;
import org.exolab.castor.mapping.Mapping;
import org.exolab.castor.xml.Unmarshaller;
+/**
+ * Data model for entries returned from an EMBL query, as marshalled by a Castor
+ * binding file
+ *
+ * For example: http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/embl/x53828/emblxml
+ *
+ * @see embl_mapping.xml
+ */
public class EmblFile
{
- Vector entries;
+ Vector<EmblEntry> entries;
- Vector errors;
+ Vector<EmblError> errors;
/**
* @return the entries
*/
- public Vector getEntries()
+ public Vector<EmblEntry> getEntries()
{
return entries;
}
* @param entries
* the entries to set
*/
- public void setEntries(Vector entries)
+ public void setEntries(Vector<EmblEntry> entries)
{
this.entries = entries;
}
/**
* @return the errors
*/
- public Vector getErrors()
+ public Vector<EmblError> getErrors()
{
return errors;
}
* @param errors
* the errors to set
*/
- public void setErrors(Vector errors)
+ public void setErrors(Vector<EmblError> errors)
{
this.errors = errors;
}
public static EmblFile getEmblFile(File file)
{
if (file == null)
+ {
return null;
+ }
try
{
return EmblFile.getEmblFile(new FileReader(file));
{
// 1. Load the mapping information from the file
Mapping map = new Mapping(record.getClass().getClassLoader());
+
java.net.URL url = record.getClass().getResource("/embl_mapping.xml");
map.loadMapping(url);
try
{
// uncomment to DEBUG EMBLFile reading
- if (((String) jalview.bin.Cache.getDefault(
- jalview.bin.Cache.CASTORLOGLEVEL, "debug"))
+ if (jalview.bin.Cache.getDefault(
+ jalview.bin.Cache.CASTORLOGLEVEL, "debug")
.equalsIgnoreCase("DEBUG"))
+ {
unmar.setDebug(jalview.bin.Cache.log.isDebugEnabled());
+ }
} catch (Exception e)
{
}
- ;
unmar.setIgnoreExtraElements(true);
+ unmar.setIgnoreExtraAttributes(true);
unmar.setMapping(map);
-
+ unmar.setLogWriter(new PrintWriter(System.out));
record = (EmblFile) unmar.unmarshal(file);
} catch (Exception e)
{
return record;
}
-
- public static void main(String args[])
- {
- File mf = null;
- if (args.length == 1)
- {
- mf = new File(args[0]);
- }
- if (!mf.exists())
- {
- mf = new File(
- "C:\\Documents and Settings\\JimP\\workspace-3.2\\Jalview Release\\schemas\\embleRecordV1.1.xml");
- }
- EmblFile myfile = EmblFile.getEmblFile(mf);
- if (myfile != null && myfile.entries != null
- && myfile.entries.size() > 0)
- System.out.println(myfile.entries.size() + " Records read. (" + mf
- + ")");
- }
}
*/
package jalview.datamodel.xdb.embl;
+/**
+ * Data model for the sequence extracted from an EMBL query reply
+ *
+ * @see embl_mapping.xml
+ */
public class EmblSequence
{
String version;
*/
package jalview.datamodel.xdb.embl;
+/**
+ * Data model for a <qualifier> child element of a <feature> read
+ * from an EMBL query reply
+ *
+ * @see embl_mapping.xml
+ */
public class Qualifier
{
String name;
public void addEvidence(String qevidence)
{
+ // TODO - not used? can remove?
if (evidence == null)
{
evidence = new String[1];
public void addValues(String value)
{
+ // TODO - not used? can remove?
if (values == null)
{
values = new String[1];
for (AlignmentAnnotation aa : alignPanel.getAlignment()
.getAlignmentAnnotation())
{
+ /*
+ * don't display non-positional annotations on an alignment
+ */
+ if (aa.annotations == null)
+ {
+ continue;
+ }
boolean apply = (aa.sequenceRef == null && forAlignment)
|| (aa.sequenceRef != null && forSequences);
if (apply)
*/
package jalview.gui;
-import jalview.datamodel.SearchResults;
-import jalview.datamodel.SequenceFeature;
-import jalview.datamodel.SequenceI;
-import jalview.jbgui.GFinder;
-import jalview.util.MessageManager;
-import jalview.viewmodel.AlignmentViewport;
-
import java.awt.event.ActionEvent;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.beans.PropertyVetoException;
import java.util.Vector;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
+import jalview.datamodel.SearchResults;
+import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.SequenceI;
+import jalview.jbgui.GFinder;
+import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
+
/**
* Performs the menu option for searching the alignment, for the next or all
* matches. If matches are found, they are highlighted, and the user has the
frame = new JInternalFrame();
frame.setContentPane(this);
frame.setLayer(JLayeredPane.PALETTE_LAYER);
+ addKeyListener();
Desktop.addInternalFrame(frame, MessageManager.getString("label.find"),
WIDTH, HEIGHT);
}
/**
+ * Add a key listener that closes the find dialog on 'Esc' key press
+ */
+ private void addKeyListener()
+ {
+ /*
+ * add the listener to the field with focus
+ */
+ textfield.addKeyListener(new KeyAdapter()
+ {
+ @Override
+ public void keyPressed(KeyEvent evt)
+ {
+ switch (evt.getKeyCode())
+ {
+ case 27:
+ // close this window on Esc key
+ Finder.this.setVisible(false);
+ try
+ {
+ Finder.this.frame.setClosed(true);
+ } catch (PropertyVetoException e)
+ {
+ // ignore
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ });
+ }
+
+ /**
* Performs the 'Find Next' action.
*
* @param e
*
* @param request
* @param response
+ * @throws IOException
*/
protected abstract void processRequest(HttpServletRequest request,
- HttpServletResponse response);
+ HttpServletResponse response) throws IOException;
/**
* For debug - writes HTTP request details to stdout
// "HttpServer started with %d threads", server.getThreadPool()
// .getThreads()));
contextRoot = server.getURI();
- System.out.println("Jalview endpoint " + contextRoot);
} catch (Exception e)
{
System.err.println("Error trying to start HttpServer: "
*/
package jalview.io;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Vector;
+
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.SequenceI;
import jalview.util.MessageManager;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Vector;
-
/**
* DOCUMENT ME!
*
for (int i = 0; i < seqs.size(); i++)
{
- s[i] = (SequenceI) seqs.elementAt(i);
+ s[i] = seqs.elementAt(i);
}
return s;
* Rna.GetBasePairsFromAlignmentAnnotation(annotations.elementAt(i));
* Rna.HelixMap(pairArray);
*/
- AlignmentAnnotation an = (AlignmentAnnotation) annotations
+ AlignmentAnnotation an = annotations
.elementAt(i);
an.validateRangeAndDisplay();
al.addAnnotation(an);
*/
protected void initData()
{
- seqs = new Vector();
- annotations = new Vector();
+ seqs = new Vector<SequenceI>();
+ annotations = new Vector<AlignmentAnnotation>();
seqGroups = new ArrayList<SequenceGroup>();
parseCalled=false;
}
*/
protected void setSeqs(SequenceI[] s)
{
- seqs = new Vector();
+ seqs = new Vector<SequenceI>();
for (int i = 0; i < s.length; i++)
{
/**
* vector of String[] treeName, newickString pairs
*/
- Vector newickStrings = null;
+ Vector<String[]> newickStrings = null;
protected void addNewickTree(String treeName, String newickString)
{
if (newickStrings == null)
{
- newickStrings = new Vector();
+ newickStrings = new Vector<String[]>();
}
newickStrings.addElement(new String[]
{ treeName, newickString });
protected int getTreeCount()
{
- if (newickStrings == null)
- {
- return 0;
- }
- return newickStrings.size();
+ return newickStrings == null ? 0 : newickStrings.size();
}
}
*/
@Override
protected void processRequest(HttpServletRequest request,
- HttpServletResponse response)
+ HttpServletResponse response) throws IOException
{
/*
* Currently just echoes the request; add helper classes as required to
*/
final String queryString = request.getQueryString();
final String reply = "REST not yet implemented; received "
- + request.getRequestURL()
+ + request.getMethod() + ": " + request.getRequestURL()
+ (queryString == null ? "" : "?" + queryString);
System.out.println(reply);
- try
- {
- final PrintWriter writer = response.getWriter();
- writer.write(reply);
- writer.close();
- } catch (IOException e)
- {
- System.err.println("Error writing REST response: " + e.getMessage());
- }
+ response.setHeader("Cache-Control", "no-cache/no-store");
+ response.setHeader("Content-type", "text/plain");
+ final PrintWriter writer = response.getWriter();
+ writer.write(reply);
+ writer.close();
}
/**
*/
package jalview.ws.dbsources;
+import java.io.File;
+
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.SequenceI;
import jalview.datamodel.xdb.embl.EmblEntry;
+import jalview.datamodel.xdb.embl.EmblFile;
import jalview.util.MessageManager;
import jalview.ws.ebi.EBIFetchClient;
-import java.io.File;
-import java.util.Iterator;
-
public abstract class EmblXmlSource extends EbiFileRetrievedProxy
{
/**
* Last properly parsed embl file.
*/
- public jalview.datamodel.xdb.embl.EmblFile efile = null;
+ public EmblFile efile = null;
public EmblXmlSource()
{
file = reply.getAbsolutePath();
if (reply.length() > 25)
{
- efile = jalview.datamodel.xdb.embl.EmblFile.getEmblFile(reply);
+ efile = EmblFile.getEmblFile(reply);
}
else
{
}
if (efile != null)
{
- for (Iterator i = efile.getEntries().iterator(); i.hasNext();)
+ for (EmblEntry entry : efile.getEntries())
{
- EmblEntry entry = (EmblEntry) i.next();
- SequenceI[] seqparts = entry.getSequences(false, true, emprefx); // TODO:
- // use
- // !fetchNa,!fetchPeptide
- // here
- // instead
- // -
- // see
- // todo
- // in
- // emblEntry
+ SequenceI[] seqparts = entry.getSequences(false, true, emprefx);
+ // TODO: use !fetchNa,!fetchPeptide here instead - see todo in EmblEntry
if (seqparts != null)
{
SequenceI[] newseqs = null;
}
for (int j = 0; j < seqparts.length; si++, j++)
{
- newseqs[si] = seqparts[j].deriveSequence(); // place DBReferences on
- // dataset and refer
+ newseqs[si] = seqparts[j].deriveSequence();
+ // place DBReferences on dataset and refer
}
seqs = newseqs;
import java.io.File;
import java.io.FileReader;
-import java.util.Enumeration;
+import java.io.Reader;
import java.util.Vector;
import org.exolab.castor.xml.Unmarshaller;
*/
public class Uniprot extends DbSourceProxyImpl implements DbSourceProxy
{
+
+ private static final String BAR_DELIMITER = "|";
+
+ private static final String NEWLINE = "\n";
+
+ private static org.exolab.castor.mapping.Mapping map;
+
+ /**
+ * Constructor
+ */
public Uniprot()
{
super();
return "0"; // we really don't know what version we're on.
}
- private EBIFetchClient ebi = null;
-
- private static org.exolab.castor.mapping.Mapping map;
-
- public Vector getUniprotEntries(File file)
+ /**
+ * Reads a file containing the reply to the EBI Fetch Uniprot data query,
+ * unmarshals it to a UniprotFile object, and returns the list of UniprotEntry
+ * data models (mapped from <entry> elements)
+ *
+ * @param fileReader
+ * @return
+ */
+ public Vector<UniprotEntry> getUniprotEntries(Reader fileReader)
{
UniprotFile uni = new UniprotFile();
try
Unmarshaller unmar = new Unmarshaller(uni);
unmar.setIgnoreExtraElements(true);
unmar.setMapping(map);
- if (file != null)
+ if (fileReader != null)
{
- uni = (UniprotFile) unmar.unmarshal(new FileReader(file));
+ uni = (UniprotFile) unmar.unmarshal(fileReader);
}
} catch (Exception e)
{
queries = queries.toUpperCase().replaceAll(
"(UNIPROT\\|?|UNIPROT_|UNIREF\\d+_|UNIREF\\d+\\|?)", "");
Alignment al = null;
- ebi = new EBIFetchClient();
- StringBuffer result = new StringBuffer();
+ EBIFetchClient ebi = new EBIFetchClient();
// uniprotxml parameter required since december 2007
// uniprotkb dbname changed introduced december 2008
File file = ebi.fetchDataAsFile("uniprotkb:" + queries, "uniprotxml",
null);
- Vector entries = getUniprotEntries(file);
+ Vector<UniprotEntry> entries = getUniprotEntries(new FileReader(file));
if (entries != null)
{
+ /*
+ * If Castor binding included sequence@length, we could guesstimate the
+ * size of buffer to hold the alignment
+ */
+ StringBuffer result = new StringBuffer(128);
// First, make the new sequences
- Enumeration en = entries.elements();
- while (en.hasMoreElements())
+ for (UniprotEntry entry : entries)
{
- UniprotEntry entry = (UniprotEntry) en.nextElement();
-
- StringBuffer name = new StringBuffer(">UniProt/Swiss-Prot");
- Enumeration en2 = entry.getAccession().elements();
- while (en2.hasMoreElements())
- {
- name.append("|");
- name.append(en2.nextElement());
- }
- en2 = entry.getName().elements();
- while (en2.hasMoreElements())
- {
- name.append("|");
- name.append(en2.nextElement());
- }
-
- if (entry.getProtein() != null
- && entry.getProtein().getName() != null)
- {
- for (int nm = 0, nmSize = entry.getProtein().getName().size(); nm < nmSize; nm++)
- {
- name.append(" " + entry.getProtein().getName().elementAt(nm));
- }
- }
-
- result.append(name + "\n"
- + entry.getUniprotSequence().getContent() + "\n");
+ StringBuilder name = constructSequenceFastaHeader(entry);
+ result.append(name).append(NEWLINE)
+ .append(entry.getUniprotSequence().getContent())
+ .append(NEWLINE);
}
// Then read in the features and apply them to the dataset
}
/**
+ * Construct a Fasta-format sequence header by concatenating the source,
+ * accession id(s) and name(s), delimited by '|', plus any protein names, now
+ * with space rather than bar delimiter
+ *
+ * @param entry
+ * @return
+ */
+ public static StringBuilder constructSequenceFastaHeader(
+ UniprotEntry entry)
+ {
+ StringBuilder name = new StringBuilder(32);
+ name.append(">UniProt/Swiss-Prot");
+ for (String accessionId : entry.getAccession())
+ {
+ name.append(BAR_DELIMITER);
+ name.append(accessionId);
+ }
+ for (String n : entry.getName())
+ {
+ name.append(BAR_DELIMITER);
+ name.append(n);
+ }
+
+ if (entry.getProtein() != null
+ && entry.getProtein().getName() != null)
+ {
+ for (String nm : entry.getProtein().getName())
+ {
+ name.append(" ").append(nm);
+ }
+ }
+ return name;
+ }
+
+ /**
* add an ordered set of UniprotEntry objects to an ordered set of seuqences.
*
* @param al
* - a sequence of n sequences
* @param entries
- * a seuqence of n uniprot entries to be analysed.
+ * a list of n uniprot entries to be analysed.
*/
- public void addUniprotXrefs(Alignment al, Vector entries)
+ public void addUniprotXrefs(Alignment al, Vector<UniprotEntry> entries)
{
+ final String dbVersion = getDbVersion();
+
for (int i = 0; i < entries.size(); i++)
{
- UniprotEntry entry = (UniprotEntry) entries.elementAt(i);
- Enumeration e = entry.getDbReference().elements();
- Vector<PDBEntry> onlyPdbEntries = new Vector();
- Vector dbxrefs = new Vector();
- while (e.hasMoreElements())
+ UniprotEntry entry = entries.elementAt(i);
+ Vector<PDBEntry> onlyPdbEntries = new Vector<PDBEntry>();
+ Vector<DBRefEntry> dbxrefs = new Vector<DBRefEntry>();
+
+ for (PDBEntry pdb : entry.getDbReference())
{
- PDBEntry pdb = (PDBEntry) e.nextElement();
DBRefEntry dbr = new DBRefEntry();
dbr.setSource(pdb.getType());
dbr.setAccessionId(pdb.getId());
- dbr.setVersion(DBRefSource.UNIPROT + ":" + getDbVersion());
+ dbr.setVersion(DBRefSource.UNIPROT + ":" + dbVersion);
dbxrefs.addElement(dbr);
- if (!pdb.getType().equals("PDB"))
+ if ("PDB".equals(pdb.getType()))
{
- continue;
+ onlyPdbEntries.addElement(pdb);
}
-
- onlyPdbEntries.addElement(pdb);
}
+
SequenceI sq = al.getSequenceAt(i);
while (sq.getDatasetSequence() != null)
{
sq = sq.getDatasetSequence();
}
- Enumeration en2 = entry.getAccession().elements();
- while (en2.hasMoreElements())
+ for (String accessionId : entry.getAccession())
{
- // we always add as uniprot if we retrieved from uniprot or uniprot name
- sq.addDBRef(new DBRefEntry(DBRefSource.UNIPROT, getDbVersion(), en2
- .nextElement().toString()));
+ /*
+ * add as uniprot whether retrieved from uniprot or uniprot_name
+ */
+ sq.addDBRef(new DBRefEntry(DBRefSource.UNIPROT, dbVersion,
+ accessionId));
}
- en2 = dbxrefs.elements();
- while (en2.hasMoreElements())
- {
- // we always add as uniprot if we retrieved from uniprot or uniprot name
- sq.addDBRef((DBRefEntry) en2.nextElement());
+ for (DBRefEntry dbRef : dbxrefs)
+ {
+ sq.addDBRef(dbRef);
}
sq.setPDBId(onlyPdbEntries);
if (entry.getFeature() != null)
{
- e = entry.getFeature().elements();
- while (e.hasMoreElements())
+ for (SequenceFeature sf : entry.getFeature())
{
- SequenceFeature sf = (SequenceFeature) e.nextElement();
sf.setFeatureGroup("Uniprot");
sq.addSequenceFeature(sf);
}
*/
package jalview.ws.ebi;
-import jalview.util.MessageManager;
-
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
+import java.util.List;
import java.util.StringTokenizer;
+import jalview.util.MessageManager;
+
/**
* DOCUMENT ME!
*
throw new Error(MessageManager.getString("error.not_yet_implemented"));
}
+ /**
+ * Send an HTTP fetch request to EBI and save the reply in a temporary file.
+ *
+ * @param ids
+ * the query formatted as db:query1;query2;query3
+ * @param f
+ * the format wanted
+ * @param s
+ * - unused parameter
+ * @return the file holding the response
+ * @throws OutOfMemoryError
+ */
public File fetchDataAsFile(String ids, String f, String s)
throws OutOfMemoryError
{
* @param f
* raw/xml
* @param s
- * ?
+ * not used - remove?
*
* @return Raw string array result of query set
*/
+ db.toLowerCase() + "/" + ids.toLowerCase()
+ (f != null ? "/" + f : ""));
- BufferedInputStream is = new BufferedInputStream(rcall.openStream());
+ InputStream is = new BufferedInputStream(rcall.openStream());
if (outFile != null)
{
FileOutputStream fio = new FileOutputStream(outFile);
{
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String rtn;
- ArrayList<String> arl = new ArrayList<String>();
+ List<String> arl = new ArrayList<String>();
while ((rtn = br.readLine()) != null)
{
arl.add(rtn);
*/
package jalview.ws.rest;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.event.MenuEvent;
+import javax.swing.event.MenuListener;
+
import jalview.bin.Cache;
import jalview.datamodel.AlignmentView;
import jalview.gui.AlignFrame;
import jalview.ws.WSClientI;
import jalview.ws.WSMenuEntryProviderI;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.Hashtable;
-import java.util.Vector;
-
-import javax.swing.JMenu;
-import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
-import javax.swing.event.MenuEvent;
-import javax.swing.event.MenuListener;
-
/**
* @author JimP
*
return lst;
}
- public static void main(String args[])
- {
- try
- {
- RestClient[] clients = getRestClients();
- System.out.println("Got " + clients.length + " clients.");
- int i = 0;
- Vector<String> urls = new Vector<String>();
- for (RestClient cl : clients)
- {
- System.out.println("" + (++i) + ": " + cl.service.toString());
- urls.add(cl.service.toString());
- }
- setRsbsServices(urls);
- if (clients.length != getRestClients().length)
- {
- System.err
- .println("Failed. Differing numbers of clients when stringified and parsed again.");
- }
-
- } catch (Throwable x)
- {
- System.err.println("Failed. Unexpected exception.");
- x.printStackTrace();
- }
- }
-
public String getAction()
{
return service.details.Action;
--- /dev/null
+package com.stevesoft.pat;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+import org.junit.Test;
+
+/**
+ * Test class refactored from RegexWriter main method
+ */
+public class RegexWriterTest
+{
+
+ /**
+ * Asserts that the result of performing 'replaceAll' on the input using the
+ * regular expression is the same as the output of a RegexWriter, constructed
+ * from the regular expression, writing out each character of the input
+ * string.
+ *
+ * @param re
+ * a regular expression
+ * @param inp
+ * an input string
+ * @throws Exception
+ */
+ void test(String re, String inp) throws IOException
+ {
+ StringWriter sw = new StringWriter();
+ Regex rex = Regex.perlCode(re);
+ String res1 = rex.replaceAll(inp);
+ RegexWriter rw = new RegexWriter(rex, sw);
+ for (int i = 0; i < inp.length(); i++)
+ {
+ rw.write(inp.charAt(i));
+ }
+ rw.close();
+ String res2 = sw.toString();
+ if (!res1.equals(res2))
+ {
+ System.out.println("re=" + re);
+ System.out.println("inp=" + inp);
+ System.out.println("res1=" + res1);
+ System.out.println("res2=" + res2);
+ assertEquals(res1, res2);
+ }
+ }
+
+ @Test
+ public void testWrite() throws IOException
+ {
+ for (int n = 1; n <= 1; n++)
+ {
+ test("s/x/y/", "-----x123456789");
+ test("s/x/y/", "x123456789");
+ test("s/x/y/", "-----x");
+ test("s/x.*?x/y/", ".xx..x..x...x...x....x....x");
+ test("s/x.*x/[$&]/", "--x........x--xx");
+ test("s/x.*x/[$&]/", "--x........x------");
+ test("s/.$/a/m", "bb\nbbb\nbbbb\nbbbbb\nbbbbbb\nbbbbbbbbbbbb");
+ test("s/.$/a/", "123");
+ test("s/.$/a/", "bb\nbbb\nbbbb\nbbbbb\nbbbbbb\nbb");
+ test("s/^./a/", "bb\nbbb\nbbbb\nbbbbb\nbbbbbb\nbb");
+ test("s/$/a/", "bbb");
+ test("s/^/a/", "bbb");
+ test("s/^/a/", "");
+ test("s{.*}{N}", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
+ test("s/.{0,7}/y/", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
+ test("s/x/$&/", "xxx");
+ }
+ }
+}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import jalview.datamodel.AlignmentAnnotation;
-import jalview.datamodel.AlignmentI;
-import jalview.datamodel.SequenceI;
-import jalview.io.AppletFormatAdapter;
import java.io.IOException;
import java.util.ArrayList;
import org.junit.Before;
import org.junit.Test;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Annotation;
+import jalview.datamodel.SequenceI;
+import jalview.io.AppletFormatAdapter;
+
public class AlignmentAnnotationUtilsTest
{
// 4 sequences x 13 positions
return result;
}
+ /**
+ * Load the test alignment and generate annotations on it
+ *
+ * @throws IOException
+ */
@Before
public void setUp() throws IOException
{
AlignmentAnnotation[] anns = new AlignmentAnnotation[SEQ_ANN_COUNT];
for (int i = 0; i < anns.length; i++)
{
- anns[i] = new AlignmentAnnotation("Label" + i, null, 0d);
+ /*
+ * Use the constructor for a positional annotation (with an Annotation
+ * array)
+ */
+ anns[i] = new AlignmentAnnotation("Label" + i, "Desc " + i,
+ new Annotation[]
+ {});
anns[i].setCalcId("CalcId" + i);
anns[i].visible = true;
alignment.addAnnotation(anns[i]);
anns[9].graph = AlignmentAnnotation.LINE_GRAPH;
anns[9].graphGroup = GROUP_4;
+ /*
+ * Generate annotations[] arrays to match aligned columns
+ */
+ // adjustForAlignment(anns);
+
List<SequenceI> selected = selectSequences(0, 3);
AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
AlignmentAnnotationUtils.asList(anns),
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
"GGGTCAGGCAGT\n";
// @formatter:on
- public static Sequence ts=new Sequence("short","ASDASDASDASDASDASDASDASDASDASDASDASDASD");
+ // public static Sequence ts=new
+ // Sequence("short","ASDASDASDASDASDASDASDASDASDASDASDASDASD");
+ public static Sequence ts = new Sequence("short",
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm");
@Test
- public void testExpandFlanks()
+ public void testExpandContext()
{
AlignmentI al = new Alignment(new Sequence[] {});
- for (int i=4;i<14;i+=3)
+ for (int i = 4; i < 14; i += 2)
{
SequenceI s1=ts.deriveSequence().getSubSequence(i, i+7);
al.addSequence(s1);
System.out.println(new AppletFormatAdapter().formatSequences("Clustal", al, true));
for (int flnk=-1;flnk<25; flnk++)
{
- AlignmentI exp;
- System.out.println("\nFlank size: "+flnk);
- System.out.println(new AppletFormatAdapter().formatSequences("Clustal", exp=AlignmentUtils.expandContext(al, flnk), true));
- if (flnk==-1) {
- for (SequenceI sq:exp.getSequences())
+ AlignmentI exp = AlignmentUtils.expandContext(al, flnk);
+ System.out.println("\nFlank size: " + flnk);
+ System.out.println(new AppletFormatAdapter().formatSequences(
+ "Clustal", exp, true));
+ if (flnk == -1)
{
+ /*
+ * Full expansion to complete sequences
+ */
+ for (SequenceI sq : exp.getSequences())
+ {
String ung = sq.getSequenceAsString().replaceAll("-+", "");
- assertTrue("Flanking sequence not the same as original dataset sequence.\n"+ung+"\n"+sq.getDatasetSequence().getSequenceAsString(),ung.equalsIgnoreCase(sq.getDatasetSequence().getSequenceAsString()));
+ final String errorMsg = "Flanking sequence not the same as original dataset sequence.\n"
+ + ung
+ + "\n"
+ + sq.getDatasetSequence().getSequenceAsString();
+ assertTrue(errorMsg, ung.equalsIgnoreCase(sq.getDatasetSequence()
+ .getSequenceAsString()));
+ }
}
+ else if (flnk == 24)
+ {
+ /*
+ * Last sequence is fully expanded, others have leading gaps to match
+ */
+ assertTrue(exp.getSequenceAt(4).getSequenceAsString()
+ .startsWith("abc"));
+ assertTrue(exp.getSequenceAt(3).getSequenceAsString()
+ .startsWith("--abc"));
+ assertTrue(exp.getSequenceAt(2).getSequenceAsString()
+ .startsWith("----abc"));
+ assertTrue(exp.getSequenceAt(1).getSequenceAsString()
+ .startsWith("------abc"));
+ assertTrue(exp.getSequenceAt(0).getSequenceAsString()
+ .startsWith("--------abc"));
}
}
- }
+ }
+
+ /**
+ * Test that annotations are correctly adjusted by expandContext
+ */
+ @Test
+ public void testExpandContext_annotation()
+ {
+ AlignmentI al = new Alignment(new Sequence[]
+ {});
+ SequenceI ds = new Sequence("Seq1", "ABCDEFGHI");
+ // subsequence DEF:
+ SequenceI seq1 = ds.deriveSequence().getSubSequence(3, 6);
+ al.addSequence(seq1);
+
+ /*
+ * Annotate DEF with 4/5/6 respectively
+ */
+ Annotation[] anns = new Annotation[]
+ { new Annotation(4), new Annotation(5), new Annotation(6) };
+ AlignmentAnnotation ann = new AlignmentAnnotation("SS",
+ "secondary structure", anns);
+ seq1.addAlignmentAnnotation(ann);
+
+ /*
+ * The annotations array should match aligned positions
+ */
+ assertEquals(3, ann.annotations.length);
+ assertEquals(4, ann.annotations[0].value, 0.001);
+ assertEquals(5, ann.annotations[1].value, 0.001);
+ assertEquals(6, ann.annotations[2].value, 0.001);
+
+ /*
+ * Check annotation to sequence position mappings before expanding the
+ * sequence; these are set up in Sequence.addAlignmentAnnotation ->
+ * Annotation.setSequenceRef -> createSequenceMappings
+ */
+ assertNull(ann.getAnnotationForPosition(1));
+ assertNull(ann.getAnnotationForPosition(2));
+ assertNull(ann.getAnnotationForPosition(3));
+ assertEquals(4, ann.getAnnotationForPosition(4).value, 0.001);
+ assertEquals(5, ann.getAnnotationForPosition(5).value, 0.001);
+ assertEquals(6, ann.getAnnotationForPosition(6).value, 0.001);
+ assertNull(ann.getAnnotationForPosition(7));
+ assertNull(ann.getAnnotationForPosition(8));
+ assertNull(ann.getAnnotationForPosition(9));
+
+ /*
+ * Expand the subsequence to the full sequence abcDEFghi
+ */
+ AlignmentI expanded = AlignmentUtils.expandContext(al, -1);
+ assertEquals("abcDEFghi", expanded.getSequenceAt(0)
+ .getSequenceAsString());
+
+ /*
+ * Confirm the alignment and sequence have the same SS annotation,
+ * referencing the expanded sequence
+ */
+ ann = expanded.getSequenceAt(0).getAnnotation()[0];
+ assertSame(ann, expanded.getAlignmentAnnotation()[0]);
+ assertSame(expanded.getSequenceAt(0), ann.sequenceRef);
+
+ /*
+ * The annotations array should have null values except for annotated
+ * positions
+ */
+ assertNull(ann.annotations[0]);
+ assertNull(ann.annotations[1]);
+ assertNull(ann.annotations[2]);
+ assertEquals(4, ann.annotations[3].value, 0.001);
+ assertEquals(5, ann.annotations[4].value, 0.001);
+ assertEquals(6, ann.annotations[5].value, 0.001);
+ assertNull(ann.annotations[6]);
+ assertNull(ann.annotations[7]);
+ assertNull(ann.annotations[8]);
+
+ /*
+ * sequence position mappings should be unchanged
+ */
+ assertNull(ann.getAnnotationForPosition(1));
+ assertNull(ann.getAnnotationForPosition(2));
+ assertNull(ann.getAnnotationForPosition(3));
+ assertEquals(4, ann.getAnnotationForPosition(4).value, 0.001);
+ assertEquals(5, ann.getAnnotationForPosition(5).value, 0.001);
+ assertEquals(6, ann.getAnnotationForPosition(6).value, 0.001);
+ assertNull(ann.getAnnotationForPosition(7));
+ assertNull(ann.getAnnotationForPosition(8));
+ assertNull(ann.getAnnotationForPosition(9));
+ }
/**
* Test method that returns a map of lists of sequences by sequence name.
--- /dev/null
+package jalview.analysis;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+
+public class ParsePropertiesTest
+{
+
+ private Alignment al;
+
+ private ParseProperties pp;
+
+ /**
+ * Construct an alignment with 4 sequences with varying description format
+ */
+ @Before
+ public void setUp()
+ {
+ SequenceI[] seqs = new SequenceI[]
+ { new Sequence("sq1", "THISISAPLACEHOLDER"),
+ new Sequence("sq2", "THISISAPLACEHOLDER"),
+ new Sequence("sq3", "THISISAPLACEHOLDER"),
+ new Sequence("sq4", "THISISAPLACEHOLDER") };
+ seqs[0].setDescription("1 mydescription1");
+ seqs[1].setDescription("mydescription2");
+ seqs[2].setDescription("2. 0.1 mydescription+3");
+ seqs[3].setDescription("3 0.01 mydescription4");
+ al = new Alignment(seqs);
+
+ pp = new ParseProperties(al);
+
+ }
+
+ /**
+ * Test with a description pattern that matches any string ending in one or
+ * more 'number characters' (0-9+.), i.e. greedily matches any trailing
+ * numeric part of the string
+ */
+ @Test
+ public void testGetScoresFromDescription()
+ {
+ String regex = ".*([-0-9.+]+)";
+ final int count = pp.getScoresFromDescription("my Score",
+ "my Score Description", regex, true);
+ System.out.println("Matched " + count + " for " + regex);
+ assertEquals(4, count);
+
+ /*
+ * Verify values 1/2/3/4 have been parsed from sequence descriptions
+ */
+ AlignmentAnnotation[] anns = al.getSequenceAt(0).getAnnotation();
+ assertEquals(1, anns.length);
+ assertEquals(1d, anns[0].getScore(), 0.001d);
+ assertEquals("my Score Description", anns[0].description);
+ assertEquals("my Score", anns[0].label);
+ anns = al.getSequenceAt(1).getAnnotation();
+ assertEquals(1, anns.length);
+ assertEquals(2d, anns[0].getScore(), 0.001d);
+ assertEquals("my Score Description", anns[0].description);
+ assertEquals("my Score", anns[0].label);
+ anns = al.getSequenceAt(2).getAnnotation();
+ assertEquals(1, anns.length);
+ assertEquals(3d, anns[0].getScore(), 0.001d);
+ anns = al.getSequenceAt(3).getAnnotation();
+ assertEquals(1, anns.length);
+ assertEquals(4d, anns[0].getScore(), 0.001d);
+ }
+
+ /**
+ * Test with a description pattern that matches any string (or none), followed
+ * by a 'number character' (0-9+.), followed by at least one separator
+ * character, followed by at least one 'number character', then any trailing
+ * characters.
+ */
+ @Test
+ public void testGetScoresFromDescription_twoScores()
+ {
+ String regex = ".*([-0-9.+]+).+([-0-9.+]+).*";
+ final int count = pp.getScoresFromDescription("my Score",
+ "my Score Description", regex, true);
+ System.out.println("Matched " + count + " for " + regex);
+ assertEquals(3, count);
+
+ /*
+ * Seq1 has two score values parsed out
+ */
+ AlignmentAnnotation[] anns = al.getSequenceAt(0).getAnnotation();
+ assertEquals(2, anns.length);
+ assertEquals(1d, anns[0].getScore(), 0.001d);
+ assertEquals("my Score Description", anns[0].description);
+ assertEquals("my Score", anns[0].label);
+ assertEquals(1d, anns[1].getScore(), 0.001d);
+ assertEquals("my Score Description (column 1)", anns[1].description);
+ assertEquals("my Score_1", anns[1].label);
+
+ /*
+ * Seq2 has no score parsed out (is this right?)
+ */
+ assertNull(al.getSequenceAt(1).getAnnotation());
+
+ /*
+ * Seq3 has two score values parsed out
+ */
+ // TODO parsed values (1.0 and 3.0) look wrong v description
+ // would expect 2.0 and 0.1
+ // undesired 'greedy' behaviour of regex?
+ anns = al.getSequenceAt(2).getAnnotation();
+ assertEquals(2, anns.length);
+ assertEquals(1d, anns[0].getScore(), 0.001d);
+ assertEquals("my Score Description", anns[0].description);
+ assertEquals("my Score", anns[0].label);
+ assertEquals(3d, anns[1].getScore(), 0.001d);
+ assertEquals("my Score Description (column 1)", anns[1].description);
+ assertEquals("my Score_1", anns[1].label);
+
+ /*
+ * Seq3 has two score values parsed out
+ */
+ // TODO parsed values (1.0 and 4.0) look wrong v description
+ // would expect 3 and 0.01
+ anns = al.getSequenceAt(3).getAnnotation();
+ assertEquals(2, anns.length);
+ assertEquals(1d, anns[0].getScore(), 0.001d);
+ assertEquals("my Score Description", anns[0].description);
+ assertEquals("my Score", anns[0].label);
+ assertEquals(4d, anns[1].getScore(), 0.001d);
+ assertEquals("my Score Description (column 1)", anns[1].description);
+ assertEquals("my Score_1", anns[1].label);
+ }
+
+ /**
+ * Test with a regex that looks for numbers separated by words - as currently
+ * used in Jalview (May 2015)
+ *
+ * @see AlignFrame.extractScores_actionPerformed
+ */
+ @Test
+ public void testGetScoresFromDescription_wordBoundaries()
+ {
+ String regex = "\\W*([-+eE0-9.]+)";
+ List<SequenceI> seqs = al.getSequences();
+ seqs.get(0).setDescription("Ferredoxin");
+ seqs.get(1).setDescription(" Ferredoxin-1, chloroplast precursor");
+ seqs.get(2).setDescription("GH28E30p");
+ seqs.get(3).setDescription("At1g10960/T19D16_12");
+ final int count = pp.getScoresFromDescription("description column",
+ "score in description column ", regex, true);
+ assertEquals(3, count);
+
+ /*
+ * No score parsable from seq1 description
+ */
+ AlignmentAnnotation[] anns = al.getSequenceAt(0).getAnnotation();
+ assertNull(anns);
+
+ /*
+ * Seq2 description has a '1' in it
+ */
+ anns = al.getSequenceAt(1).getAnnotation();
+ assertEquals(1, anns.length);
+ assertEquals(1d, anns[0].getScore(), 0.001d);
+
+ /*
+ * Seq3 description has '28E30' in it
+ *
+ * Note: 1.8E308 or larger would result in 'Infinity'
+ */
+ anns = al.getSequenceAt(2).getAnnotation();
+ assertEquals(1, anns.length);
+ assertEquals(2.8E31d, anns[0].getScore(), 0.001d);
+
+ /*
+ * Seq4 description has several numbers in it
+ */
+ anns = al.getSequenceAt(3).getAnnotation();
+ assertEquals(5, anns.length);
+ assertEquals(1d, anns[0].getScore(), 0.001d);
+ assertEquals(10960d, anns[1].getScore(), 0.001d);
+ assertEquals(19d, anns[2].getScore(), 0.001d);
+ assertEquals(16d, anns[3].getScore(), 0.001d);
+ assertEquals(12d, anns[4].getScore(), 0.001d);
+ }
+}
package jalview.datamodel;
import static org.junit.Assert.assertEquals;
-import jalview.analysis.AlignSeq;
-import jalview.io.AppletFormatAdapter;
+import static org.junit.Assert.assertNull;
import org.junit.Test;
+import jalview.analysis.AlignSeq;
+import jalview.io.AppletFormatAdapter;
+
public class AlignmentAnnotationTests
{
@Test
: "Out of range");
assertEquals("Position " + p + " " + alm1 + " " + alm2, alm1, alm2);
}
- // new jalview.io.FormatAdapter().formatSequences("STOCKHOLM", n)
}
+ @Test
+ public void testAdjustForAlignment()
+ {
+ SequenceI seq = new Sequence("TestSeq", "ABCDEFG");
+ seq.createDatasetSequence();
+
+ /*
+ * Annotate positions 3/4/5 (CDE) with values 1/2/3
+ */
+ Annotation[] anns = new Annotation[]
+ { null, null, new Annotation(1), new Annotation(2), new Annotation(3) };
+ AlignmentAnnotation ann = new AlignmentAnnotation("SS",
+ "secondary structure", anns);
+ seq.addAlignmentAnnotation(ann);
+
+ /*
+ * Check annotation map before modifying aligned sequence
+ */
+ assertNull(ann.getAnnotationForPosition(1));
+ assertNull(ann.getAnnotationForPosition(2));
+ assertNull(ann.getAnnotationForPosition(6));
+ assertNull(ann.getAnnotationForPosition(7));
+ assertEquals(1, ann.getAnnotationForPosition(3).value, 0.001d);
+ assertEquals(2, ann.getAnnotationForPosition(4).value, 0.001d);
+ assertEquals(3, ann.getAnnotationForPosition(5).value, 0.001d);
+
+ /*
+ * Trim the displayed sequence to BCD and adjust annotations
+ */
+ seq.setSequence("BCD");
+ seq.setStart(2);
+ seq.setEnd(4);
+ ann.adjustForAlignment();
+
+ /*
+ * Should now have annotations for aligned positions 2, 3Q (CD) only
+ */
+ assertEquals(3, ann.annotations.length);
+ assertNull(ann.annotations[0]);
+ assertEquals(1, ann.annotations[1].value, 0.001);
+ assertEquals(2, ann.annotations[2].value, 0.001);
+ }
}
--- /dev/null
+package jalview.datamodel;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+
+import org.junit.Test;
+
+import jalview.util.MapList;
+
+/**
+ * Test class refactored from main method
+ */
+public class MappingTest
+{
+ /**
+ * trite test of the intersectVisContigs method for a simple DNA -> Protein
+ * exon map and a range of visContigs
+ */
+ @Test
+ public void testIntersectVisContigs()
+ {
+ MapList fk = new MapList(new int[]
+ { 1, 6, 8, 13, 15, 23 }, new int[]
+ { 1, 7 }, 3, 1);
+ Mapping m = new Mapping(fk);
+ Mapping m_1 = m.intersectVisContigs(new int[]
+ { fk.getFromLowest(), fk.getFromHighest() });
+ Mapping m_2 = m.intersectVisContigs(new int[]
+ { 1, 7, 11, 20 });
+
+ // assertions from output values 'as is', not checked for correctness
+ String result = Arrays.deepToString(m_1.map.getFromRanges()
+ .toArray());
+ System.out.println(result);
+ assertEquals("[[1, 6], [8, 13], [15, 23]]", result);
+
+ result = Arrays.deepToString(m_2.map.getFromRanges().toArray());
+ System.out.println(result);
+ assertEquals("[[1, 6], [11, 13], [15, 20]]", result);
+ }
+
+}
--- /dev/null
+package jalview.datamodel;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import org.junit.Test;
+
+/**
+ * Unit tests for SeqCigar
+ */
+public class SeqCigarTest
+{
+ /*
+ * refactored 'as is' from main method
+ *
+ * TODO: split into separate tests
+ */
+ @Test
+ public void testSomething() throws Exception
+ {
+ String o_seq = "asdfktryasdtqwrtsaslldddptyipqqwaslchvhttt";
+ Sequence s = new Sequence("MySeq", o_seq, 39, 80);
+ String orig_gapped = "----asdf------ktryas---dtqwrtsasll----dddptyipqqwa----slchvhttt";
+ Sequence s_gapped = new Sequence("MySeq", orig_gapped, 39, 80);
+ String ex_cs_gapped = "4I4M6I6M3I11M4I12M4I9M";
+ s_gapped.setDatasetSequence(s);
+ String sub_gapped_s = "------ktryas---dtqwrtsasll----dddptyipqqwa----slchvh";
+ Sequence s_subsequence_gapped = new Sequence("MySeq", sub_gapped_s, 43,
+ 77);
+ s_subsequence_gapped.setDatasetSequence(s);
+
+ SeqCigar c_null = new SeqCigar(s);
+ String cs_null = c_null.getCigarstring();
+ assertEquals("Failed to recover ungapped sequence cigar operations",
+ "42M", cs_null);
+ testCigar_string(s_gapped, ex_cs_gapped);
+ SeqCigar gen_sgapped = SeqCigar.parseCigar(s, ex_cs_gapped);
+ assertEquals("Failed parseCigar", ex_cs_gapped,
+ gen_sgapped.getCigarstring());
+
+ testSeqRecovery(gen_sgapped, s_gapped);
+
+ /*
+ * Test dataset resolution
+ */
+ SeqCigar sub_gapped = new SeqCigar(s_subsequence_gapped);
+ testSeqRecovery(sub_gapped, s_subsequence_gapped);
+
+ /*
+ * Test width functions
+ */
+ assertEquals("Failed getWidth", sub_gapped_s.length(),
+ sub_gapped.getWidth());
+
+ sub_gapped.getFullWidth();
+ assertFalse("hasDeletedRegions is incorrect",
+ sub_gapped.hasDeletedRegions());
+
+ // Test start-end region SeqCigar
+ SeqCigar sub_se_gp = new SeqCigar(s_subsequence_gapped, 8, 48);
+ assertEquals(
+ "SeqCigar(seq, start, end) not properly clipped alignsequence",
+ 41, sub_se_gp.getWidth());
+
+ /*
+ * TODO: can we add assertions to the sysouts that follow?
+ */
+ System.out.println("Original sequence align:\n" + sub_gapped_s
+ + "\nReconstructed window from 8 to 48\n" + "XXXXXXXX"
+ + sub_se_gp.getSequenceString('-') + "..." + "\nCigar String:"
+ + sub_se_gp.getCigarstring() + "\n");
+ SequenceI ssgp = sub_se_gp.getSeq('-');
+ System.out.println("\t " + ssgp.getSequenceAsString());
+ for (int r = 0; r < 10; r++)
+ {
+ sub_se_gp = new SeqCigar(s_subsequence_gapped, 8, 48);
+ int sl = sub_se_gp.getWidth();
+ int st = sl - 1 - r;
+ for (int rs = 0; rs < 10; rs++)
+ {
+ int e = st + rs;
+ sub_se_gp.deleteRange(st, e);
+ String ssgapedseq = sub_se_gp.getSeq('-').getSequenceAsString();
+ System.out.println(st + "," + e + "\t:" + ssgapedseq);
+ st -= 3;
+ }
+ }
+
+ SeqCigar[] set = new SeqCigar[]
+ { new SeqCigar(s), new SeqCigar(s_subsequence_gapped, 8, 48),
+ new SeqCigar(s_gapped) };
+ Alignment al = new Alignment(set);
+ for (int i = 0; i < al.getHeight(); i++)
+ {
+ System.out.println("" + al.getSequenceAt(i).getName() + "\t"
+ + al.getSequenceAt(i).getStart() + "\t"
+ + al.getSequenceAt(i).getEnd() + "\t"
+ + al.getSequenceAt(i).getSequenceAsString());
+ }
+
+ System.out.println("Gapped.");
+ set = new SeqCigar[]
+ { new SeqCigar(s), new SeqCigar(s_subsequence_gapped, 8, 48),
+ new SeqCigar(s_gapped) };
+ set[0].deleteRange(20, 25);
+ al = new Alignment(set);
+ for (int i = 0; i < al.getHeight(); i++)
+ {
+ System.out.println("" + al.getSequenceAt(i).getName() + "\t"
+ + al.getSequenceAt(i).getStart() + "\t"
+ + al.getSequenceAt(i).getEnd() + "\t"
+ + al.getSequenceAt(i).getSequenceAsString());
+ }
+
+ // if (!ssgapedseq.equals("ryas---dtqqwa----slchvh"))
+ // System.err.println("Subseqgaped\n------ktryas---dtqwrtsasll----dddptyipqqwa----slchvhryas---dtqwrtsasll--qwa----slchvh\n"+ssgapedseq+"\n"+sub_se_gp.getCigarstring());
+ }
+
+ /**
+ * non rigorous testing
+ *
+ * @param seq
+ * Sequence
+ * @param ex_cs_gapped
+ * String
+ * @return String
+ */
+ protected void testCigar_string(Sequence seq, String ex_cs_gapped)
+ {
+ SeqCigar c_sgapped = new SeqCigar(seq);
+ String cs_gapped = c_sgapped.getCigarstring();
+ assertEquals("Failed getCigarstring", ex_cs_gapped,
+ cs_gapped);
+ }
+
+ protected void testSeqRecovery(SeqCigar gen_sgapped,
+ SequenceI s_gapped)
+ {
+ // this is non-rigorous - start and end recovery is not tested.
+ SequenceI gen_sgapped_s = gen_sgapped.getSeq('-');
+ // assertEquals("Couldn't reconstruct sequence", s_gapped.getSequence(),
+ // gen_sgapped_s);
+ if (!gen_sgapped_s.getSequence().equals(s_gapped.getSequence()))
+ {
+ // TODO: investigate errors reported here, to allow full conversion to
+ // passing JUnit assertion form
+ System.err.println("Couldn't reconstruct sequence.\n"
+ + gen_sgapped_s.getSequenceAsString() + "\n"
+ + s_gapped.getSequenceAsString());
+ }
+ }
+
+}
seq.getDatasetSequence().setDatasetSequence(seq); // loop!
assertNull(seq.getSequenceFeatures());
}
+
+ /**
+ * Test the method that returns an array, indexed by sequence position, whose
+ * entries are the residue positions at the sequence position (or to the right
+ * if a gap)
+ */
+ @Test
+ public void testFindPositionMap()
+ {
+ /*
+ * Note: Javadoc for findPosition says it returns the residue position to
+ * the left of a gapped position; in fact it returns the position to the
+ * right. Also it returns a non-existent residue position for a gap beyond
+ * the sequence.
+ */
+ Sequence seq = new Sequence("TestSeq", "AB.C-D E.");
+ int[] map = seq.findPositionMap();
+ assertEquals(Arrays.toString(new int[]
+ { 1, 2, 3, 3, 4, 4, 5, 5, 6 }), Arrays.toString(map));
+ }
+
+ /**
+ * Test for getSubsequence
+ */
+ @Test
+ public void testGetSubsequence()
+ {
+ SequenceI seq = new Sequence("TestSeq", "ABCDEFG");
+ seq.createDatasetSequence();
+
+ // positions are base 0, end position is exclusive
+ SequenceI subseq = seq.getSubSequence(2, 4);
+
+ assertEquals("CD", subseq.getSequenceAsString());
+ // start/end are base 1 positions
+ assertEquals(3, subseq.getStart());
+ assertEquals(4, subseq.getEnd());
+ // subsequence shares the full dataset sequence
+ assertSame(seq.getDatasetSequence(), subseq.getDatasetSequence());
+ }
+
+ /**
+ * Test for deriveSequence applied to a sequence with a dataset
+ */
+ @Test
+ public void testDeriveSequence_existingDataset()
+ {
+ SequenceI seq = new Sequence("Seq1", "CD");
+ seq.setDatasetSequence(new Sequence("Seq1", "ABCDEF"));
+ seq.setStart(3);
+ seq.setEnd(4);
+ SequenceI derived = seq.deriveSequence();
+ assertEquals("CD", derived.getSequenceAsString());
+ assertSame(seq.getDatasetSequence(), derived.getDatasetSequence());
+ }
+
+ /**
+ * Test for deriveSequence applied to an ungapped sequence with no dataset
+ */
+ @Test
+ public void testDeriveSequence_noDatasetUngapped()
+ {
+ SequenceI seq = new Sequence("Seq1", "ABCDEF");
+ assertEquals(1, seq.getStart());
+ assertEquals(6, seq.getEnd());
+ SequenceI derived = seq.deriveSequence();
+ assertEquals("ABCDEF", derived.getSequenceAsString());
+ assertEquals("ABCDEF", derived.getDatasetSequence()
+ .getSequenceAsString());
+ }
+
+ /**
+ * Test for deriveSequence applied to a gapped sequence with no dataset
+ */
+ @Test
+ public void testDeriveSequence_noDatasetGapped()
+ {
+ SequenceI seq = new Sequence("Seq1", "AB-C.D EF");
+ assertEquals(1, seq.getStart());
+ assertEquals(6, seq.getEnd());
+ assertNull(seq.getDatasetSequence());
+ SequenceI derived = seq.deriveSequence();
+ assertEquals("AB-C.D EF", derived.getSequenceAsString());
+ assertEquals("ABCDEF", derived.getDatasetSequence()
+ .getSequenceAsString());
+ }
}
--- /dev/null
+package jalview.datamodel.xdb.embl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.StringReader;
+import java.util.Vector;
+
+import org.junit.Test;
+
+import jalview.datamodel.DBRefEntry;
+
+public class EmblFileTest
+{
+ // adapted from http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/embl/x53828/emblxml
+ private static final String TESTDATA =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
+ + "<EMBL_Services>"
+ + "<entry accession=\"X53828\" version=\"3\" lastUpdated=\"2005-04-18\" releaseCreated=\"25\" releaseLastUpdated=\"83\">"
+ + "<description>Chicken LDH-A mRNA for lactate dehydrogenase A chain (EC 1.1.1.27)</description>"
+ + "<keyword>L-lactate dehydrogenase</keyword><keyword>chutney</keyword>"
+ + "<dbreference db=\"EuropePMC\" primary=\"PMC1460223\" secondary=\"9649548\" />"
+ + "<feature name=\"CDS\"><dbreference db=\"GOA\" primary=\"P00340\" secondary=\"2.1\" /><dbreference db=\"InterPro\" primary=\"IPR001236\" />"
+ + "<qualifier name=\"note\"><value>L-lactate dehydrogenase A-chain</value><value>pickle</value></qualifier>"
+ + "<qualifier name=\"translation\"><value>MSLKDHLIHN</value><evidence>Keith</evidence></qualifier>"
+ + "<location type=\"single\" complement=\"true\">"
+ + "<locationElement type=\"range\" accession=\"X53828\" version=\"1\" complement=\"false\">"
+ + "<basePosition type=\"simple\">60</basePosition><basePosition type=\"join\">1058</basePosition>"
+ + "</locationElement></location></feature>"
+ + "<sequence type=\"mRNA\" version=\"2\">GTGACG</sequence></entry></EMBL_Services>";
+
+ @Test
+ public void testGetEmblFile()
+ {
+ Vector<EmblEntry> entries = EmblFile.getEmblFile(
+ new StringReader(TESTDATA)).getEntries();
+ assertEquals(1, entries.size());
+ EmblEntry entry = entries.get(0);
+
+ assertEquals("X53828", entry.getAccession());
+ assertEquals(
+ "Chicken LDH-A mRNA for lactate dehydrogenase A chain (EC 1.1.1.27)",
+ entry.getDesc());
+ assertEquals("2005-04-18", entry.getLastUpdated());
+
+ /*
+ * FIXME these assertions fail - values are null - why?? Adding or removing
+ * attributes in the test XML modifies behaviour. eg. inserting an attribute
+ * _before_ lastUpdated results in a null value in this field.
+ */
+ // assertEquals("25", entry.getRCreated());
+ // assertEquals("83", entry.getRLastUpdated());
+
+ assertEquals(2, entry.getKeywords().size());
+ assertEquals("L-lactate dehydrogenase", entry.getKeywords().get(0));
+ assertEquals("chutney", entry.getKeywords().get(1));
+
+ /*
+ * dbrefs
+ */
+ assertEquals(1, entry.getDbRefs().size());
+ DBRefEntry dbref = entry.getDbRefs().get(0);
+ assertEquals("EuropePMC", dbref.getSource());
+ assertEquals("PMC1460223", dbref.getAccessionId());
+ assertEquals("9649548", dbref.getVersion());
+
+ /*
+ * sequence features
+ */
+ assertEquals(1, entry.getFeatures().size());
+ EmblFeature ef = entry.getFeatures().get(0);
+ assertEquals("CDS", ef.getName());
+ assertEquals(2, ef.getDbRefs().size());
+ dbref = ef.getDbRefs().get(0);
+ assertEquals("GOA", dbref.getSource());
+ assertEquals("P00340", dbref.getAccessionId());
+ assertEquals("2.1", dbref.getVersion());
+ dbref = ef.getDbRefs().get(1);
+ assertEquals("InterPro", dbref.getSource());
+ assertEquals("IPR001236", dbref.getAccessionId());
+ assertEquals("", dbref.getVersion());
+ assertEquals(2, ef.getQualifiers().size());
+
+ // feature qualifiers
+ Qualifier q = ef.getQualifiers().get(0);
+ assertEquals("note", q.getName());
+ assertEquals(2, q.getValues().length);
+ assertEquals("L-lactate dehydrogenase A-chain", q.getValues()[0]);
+ assertEquals("pickle", q.getValues()[1]);
+ assertNull(q.getEvidence());
+ q = ef.getQualifiers().get(1);
+ assertEquals("translation", q.getName());
+ assertEquals(1, q.getValues().length);
+ assertEquals("MSLKDHLIHN", q.getValues()[0]);
+ assertEquals(1, q.getEvidence().length);
+ assertEquals("Keith", q.getEvidence()[0]);
+
+ // feature locations
+ assertEquals(1, ef.getLocations().size());
+ EmblFeatureLocations fl = ef.getLocations().get(0);
+ assertEquals("single", fl.getLocationType());
+ assertTrue(fl.isLocationComplement());
+ assertEquals(1, fl.getLocElements().size());
+ EmblFeatureLocElement le = fl.getLocElements().get(0);
+ assertEquals("range", le.getType());
+ assertEquals("X53828", le.getAccession());
+ assertEquals("1", le.getVersion());
+ assertFalse(le.isComplement());
+ assertEquals(2, le.getBasePositions().length);
+ BasePosition bp = le.getBasePositions()[0];
+ assertEquals("simple", bp.getType());
+ assertEquals("60", bp.getPos());
+ bp = le.getBasePositions()[1];
+ assertEquals("join", bp.getType());
+ assertEquals("1058", bp.getPos());
+
+ /*
+ * Sequence
+ */
+ EmblSequence seq = entry.getSequence();
+ assertEquals("mRNA", seq.getType());
+ assertEquals("2", seq.getVersion());
+ assertEquals("GTGACG", seq.getSequence());
+ }
+}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import jalview.datamodel.Alignment;
-import jalview.datamodel.AlignmentI;
-import jalview.datamodel.SequenceI;
-import jalview.gui.AlignFrame;
-import jalview.io.AppletFormatAdapter;
-import jalview.io.FileLoader;
import java.util.Vector;
+import org.junit.Before;
import org.junit.Test;
import MCview.PDBfile;
+import jalview.bin.Cache;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignFrame;
+import jalview.io.AppletFormatAdapter;
+import jalview.io.FileLoader;
+
/**
* @author jimp
*
// "./examples/DNMT1_MOUSE.pdb"
// };
+ @Before
+ public void setUp()
+ {
+ Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
+ Boolean.TRUE.toString());
+ Cache.applicationProperties.setProperty("ADD_SS_ANN",
+ Boolean.TRUE.toString());
+ }
+
@Test
public void testAlignmentLoader() throws Exception
{
RIGHT_ALIGN_IDS=false
USE_PROXY=false
WRAP_ALIGNMENT=false
-DAS_REGISTRY_URL=http\://www.dasregistry.org/das/
+#DAS_REGISTRY_URL=http\://www.dasregistry.org/das/ # retired 01/05/2015
+DAS_REGISTRY_URL=http\://www.ebi.ac.uk/das-srv/registry/das/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
-import jalview.bin.Cache;
-import jalview.datamodel.AlignmentAnnotation;
-import jalview.datamodel.AlignmentI;
-import jalview.datamodel.Annotation;
-import jalview.datamodel.SequenceGroup;
-import jalview.datamodel.SequenceI;
-import jalview.io.AppletFormatAdapter;
-import jalview.util.MessageManager;
import java.awt.BorderLayout;
import java.awt.Checkbox;
import org.junit.Before;
import org.junit.Test;
+import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
+import jalview.bin.Cache;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Annotation;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+import jalview.io.AppletFormatAdapter;
+import jalview.util.MessageManager;
+
/**
* Unit tests for AnnotationChooser
*
// pin down annotation sort order for test
Cache.applicationProperties.setProperty(Preferences.SORT_ANNOTATIONS,
SequenceAnnotationOrder.NONE.name());
+ final String True = Boolean.TRUE.toString();
Cache.applicationProperties.setProperty(
- Preferences.SHOW_AUTOCALC_ABOVE, Boolean.TRUE.toString());
+ Preferences.SHOW_AUTOCALC_ABOVE, True);
+ Cache.applicationProperties.setProperty("SHOW_QUALITY", True);
+ Cache.applicationProperties.setProperty("SHOW_CONSERVATION", True);
+ Cache.applicationProperties.setProperty("SHOW_IDENTITY", True);
AlignmentI al = new jalview.io.FormatAdapter().readFile(TEST_DATA,
AppletFormatAdapter.PASTE, "FASTA");
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Annotation;
import jalview.datamodel.SequenceI;
import jalview.io.AppletFormatAdapter;
import jalview.io.FormatAdapter;
// PDB.secondary structure on Sequence0
AlignmentAnnotation annotation = new AlignmentAnnotation(
- "secondary structure", "", 0);
+ "secondary structure", "", new Annotation[]
+ {});
annotation.setCalcId("PDB");
annotation.visible = true;
seqs.get(0).addAlignmentAnnotation(annotation);
parentPanel.getAlignment().addAnnotation(annotation);
// JMOL.secondary structure on Sequence0 - hidden
- annotation = new AlignmentAnnotation("secondary structure", "", 0);
+ annotation = new AlignmentAnnotation("secondary structure", "", new Annotation[]
+ {});
annotation.setCalcId("JMOL");
annotation.visible = false;
seqs.get(0).addAlignmentAnnotation(annotation);
parentPanel.getAlignment().addAnnotation(annotation);
// Jpred.SSP on Sequence0 - hidden
- annotation = new AlignmentAnnotation("SSP", "", 0);
+ annotation = new AlignmentAnnotation("SSP", "", new Annotation[]
+ {});
annotation.setCalcId("JPred");
annotation.visible = false;
seqs.get(0).addAlignmentAnnotation(annotation);
parentPanel.getAlignment().addAnnotation(annotation);
// PDB.Temp on Sequence1
- annotation = new AlignmentAnnotation("Temp", "", 0);
+ annotation = new AlignmentAnnotation("Temp", "", new Annotation[]
+ {});
annotation.setCalcId("PDB");
annotation.visible = true;
seqs.get(1).addAlignmentAnnotation(annotation);
// PDB.secondary structure on Sequence0
AlignmentAnnotation annotation = new AlignmentAnnotation(
- "secondary structure", "", 0);
+ "secondary structure", "", new Annotation[]
+ {});
annotation.setCalcId("PDB");
annotation.visible = true;
seqs.get(0).addAlignmentAnnotation(annotation);
parentPanel.getAlignment().addAnnotation(annotation);
// PDB.Temp on Sequence1
- annotation = new AlignmentAnnotation("Temp", "", 0);
+ annotation = new AlignmentAnnotation("Temp", "", new Annotation[]
+ {});
annotation.setCalcId("PDB");
annotation.visible = true;
seqs.get(1).addAlignmentAnnotation(annotation);
// PDB.secondary structure on Sequence0
AlignmentAnnotation annotation = new AlignmentAnnotation(
- "secondary structure", "", 0);
+ "secondary structure", "", new Annotation[]
+ {});
annotation.setCalcId("PDB");
annotation.visible = false;
seqs.get(0).addAlignmentAnnotation(annotation);
parentPanel.getAlignment().addAnnotation(annotation);
// PDB.Temp on Sequence1
- annotation = new AlignmentAnnotation("Temp", "", 0);
+ annotation = new AlignmentAnnotation("Temp", "", new Annotation[]
+ {});
annotation.setCalcId("PDB2");
annotation.visible = false;
seqs.get(1).addAlignmentAnnotation(annotation);
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import jalview.bin.Cache;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.PDBEntry;
import jalview.structure.StructureMapping;
import jalview.structure.StructureSelectionManager;
-import java.io.File;
-import java.util.Vector;
-
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
public class AnnotatedPDBFileInputTest
{
@Before
public void setup() throws Exception
{
+ Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
+ Boolean.TRUE.toString());
+ Cache.applicationProperties.setProperty("ADD_SS_ANN",
+ Boolean.TRUE.toString());
FileLoader loader = new FileLoader(false);
AlignFrame af = loader.LoadFileWaitTillLoaded(pdbStr,
FormatAdapter.FILE);
al = af.getViewport().getAlignment();
- pdbId = ((PDBEntry) al.getSequenceAt(0).getDatasetSequence().getPDBId()
- .get(0)).getId();
+ pdbId = al.getSequenceAt(0).getDatasetSequence().getPDBId()
+ .get(0).getId();
}
@Test
}
assertNotNull(sq.getPDBId());
assertEquals("Expected only one PDB ID", sq.getPDBId().size(), 1);
- for (PDBEntry pdbentry : (Vector<PDBEntry>) sq.getPDBId())
+ for (PDBEntry pdbentry : sq.getPDBId())
{
System.err.println("PDB Entry " + pdbentry.getId() + " "
+ pdbentry.getFile());
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+
+import java.io.File;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
import jalview.api.AlignmentViewPanel;
import jalview.api.ViewStyleI;
+import jalview.bin.Cache;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.schemes.AnnotationColourGradient;
import jalview.schemes.ColourSchemeI;
-import java.io.File;
-
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
public class Jalview2xmlTests
{
@Test
public void viewRefPdbAnnotation() throws Exception
{
+ Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
+ Boolean.TRUE.toString());
+ Cache.applicationProperties.setProperty("ADD_SS_ANN",
+ Boolean.TRUE.toString());
AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
"examples/exampleFile_2_7.jar", FormatAdapter.FILE);
assertTrue("Didn't read in the example file correctly.", af != null);
RIGHT_ALIGN_IDS=false
USE_PROXY=false
WRAP_ALIGNMENT=false
-DAS_REGISTRY_URL=http\://www.dasregistry.org/das/
+#DAS_REGISTRY_URL=http\://www.dasregistry.org/das/ # retired 01/05/2015
+DAS_REGISTRY_URL=http\://www.ebi.ac.uk/das-srv/registry/das/
RIGHT_ALIGN_IDS=false
USE_PROXY=false
WRAP_ALIGNMENT=false
-DAS_REGISTRY_URL=http\://www.dasregistry.org/das/
+#DAS_REGISTRY_URL=http\://www.dasregistry.org/das/ # retired 01/05/2015
+DAS_REGISTRY_URL=http\://www.ebi.ac.uk/das-srv/registry/das/
*/
package jalview.ws;
-import static org.junit.Assert.*;
-import jalview.datamodel.AlignmentI;
-import jalview.datamodel.SequenceI;
-import jalview.ws.seqfetcher.DbSourceProxy;
+import static org.junit.Assert.assertTrue;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
+import jalview.bin.Cache;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
+import jalview.ws.seqfetcher.DbSourceProxy;
+
public class PDBSequenceFetcherTest
{
@Before
public void setUp() throws Exception
{
+ // ensure 'add annotation from structure' is selected
+ Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
+ Boolean.TRUE.toString());
+ Cache.applicationProperties.setProperty("ADD_SS_ANN",
+ Boolean.TRUE.toString());
+
sf = new SequenceFetcher(false);
}
--- /dev/null
+package jalview.ws.dbsources;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.Vector;
+
+import org.junit.Test;
+
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.UniprotEntry;
+
+public class UniprotTest
+{
+ // adapted from http://www.uniprot.org/uniprot/A9CKP4.xml
+ private static final String UNIPROT_XML = "<?xml version='1.0' encoding='UTF-8'?>"
+ + "<uniprot>"
+ + "<entry dataset=\"TrEMBL\" created=\"2008-01-15\" modified=\"2015-03-04\" version=\"38\">"
+ + "<accession>A9CKP4</accession>"
+ + "<accession>A9CKP5</accession>"
+ + "<name>A9CKP4_AGRT5</name>"
+ + "<name>A9CKP4_AGRT6</name>"
+ + "<protein><recommendedName><fullName>Mitogen-activated protein kinase 13</fullName><fullName>Henry</fullName></recommendedName></protein>"
+ + "<dbReference type=\"PDB\" id=\"2FSQ\"><property type=\"method\" value=\"X-ray\"/><property type=\"resolution\" value=\"1.40\"/></dbReference>"
+ + "<dbReference type=\"PDBsum\" id=\"2FSR\"/>"
+ + "<feature type=\"signal peptide\" evidence=\"7\"><location><begin position=\"1\"/><end position=\"18\"/></location></feature>"
+ + "<feature type=\"propeptide\" description=\"Activation peptide\" id=\"PRO_0000027399\" evidence=\"9 16 17 18\"><location><begin position=\"19\"/><end position=\"20\"/></location></feature>"
+ + "<feature type=\"chain\" description=\"Granzyme B\" id=\"PRO_0000027400\"><location><begin position=\"21\"/><end position=\"247\"/></location></feature>"
+ + "<sequence length=\"10\" mass=\"27410\" checksum=\"8CB760AACF88FE6C\" modified=\"2008-01-15\" version=\"1\">MHAPL VSKDL</sequence></entry>"
+ + "</uniprot>";
+
+ /**
+ * Test the method that unmarshals XML to a Uniprot model
+ */
+ @Test
+ public void testGetUniprotEntries()
+ {
+ Uniprot u = new Uniprot();
+ Reader reader = new StringReader(UNIPROT_XML);
+ Vector<UniprotEntry> entries = u.getUniprotEntries(reader);
+ assertEquals(1, entries.size());
+ UniprotEntry entry = entries.get(0);
+ assertEquals(2, entry.getName().size());
+ assertEquals("A9CKP4_AGRT5", entry.getName().get(0));
+ assertEquals("A9CKP4_AGRT6", entry.getName().get(1));
+ assertEquals(2, entry.getAccession().size());
+ assertEquals("A9CKP4", entry.getAccession().get(0));
+ assertEquals("A9CKP5", entry.getAccession().get(1));
+
+ /*
+ * UniprotSequence drops any space characters
+ */
+ assertEquals("MHAPLVSKDL", entry.getUniprotSequence()
+ .getContent());
+
+ assertEquals(2, entry.getProtein().getName().size());
+ assertEquals("Mitogen-activated protein kinase 13", entry.getProtein()
+ .getName().get(0));
+ assertEquals("Henry", entry.getProtein().getName().get(1));
+
+ /*
+ * Check sequence features
+ */
+ Vector<SequenceFeature> features = entry.getFeature();
+ assertEquals(3, features.size());
+ SequenceFeature sf = features.get(0);
+ assertEquals("signal peptide", sf.getType());
+ assertNull(sf.getDescription());
+ assertNull(sf.getStatus());
+ assertEquals(1, sf.getPosition()); // wrong - Castor bug??
+ assertEquals(1, sf.getBegin());
+ assertEquals(18, sf.getEnd());
+ sf = features.get(1);
+ assertEquals("propeptide", sf.getType());
+ assertEquals("Activation peptide", sf.getDescription());
+ assertEquals(19, sf.getPosition()); // wrong - Castor bug??
+ assertEquals(19, sf.getBegin());
+ assertEquals(20, sf.getEnd());
+ sf = features.get(2);
+ assertEquals("chain", sf.getType());
+ assertEquals("Granzyme B", sf.getDescription());
+ assertEquals(21, sf.getPosition()); // wrong - Castor bug??
+ assertEquals(21, sf.getBegin());
+ assertEquals(247, sf.getEnd());
+
+ /*
+ * Check cross-references
+ */
+ Vector<PDBEntry> xrefs = entry.getDbReference();
+ assertEquals(2, xrefs.size());
+
+ PDBEntry xref = xrefs.get(0);
+ assertEquals("2FSQ", xref.getId());
+ assertEquals("PDB", xref.getType());
+ assertEquals(2, xref.getProperty().size());
+ assertEquals("X-ray", xref.getProperty().get("method"));
+ assertEquals("1.40", xref.getProperty().get("resolution"));
+
+ xref = xrefs.get(1);
+ assertEquals("2FSR", xref.getId());
+ assertEquals("PDBsum", xref.getType());
+ assertNull(xref.getProperty());
+ }
+
+ /**
+ * Test the method that formats the sequence name in Fasta style
+ */
+ @Test
+ public void testConstructSequenceFastaHeader()
+ {
+ Uniprot u = new Uniprot();
+ Reader reader = new StringReader(UNIPROT_XML);
+ Vector<UniprotEntry> entries = u.getUniprotEntries(reader);
+ UniprotEntry entry = entries.get(0);
+
+ // source + accession ids + names + protein names
+ String expectedName = ">UniProt/Swiss-Prot|A9CKP4|A9CKP5|A9CKP4_AGRT5|A9CKP4_AGRT6 Mitogen-activated protein kinase 13 Henry";
+ assertEquals(expectedName, Uniprot.constructSequenceFastaHeader(entry)
+ .toString());
+ }
+}
--- /dev/null
+package jalview.ws.rest;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Vector;
+
+import org.junit.Test;
+
+import jalview.bin.Cache;
+
+public class RestClientTest
+{
+ /**
+ * Refactored 'as is' from main method
+ */
+ @Test
+ public void testGetRestClient()
+ {
+ /*
+ * Load test properties file (readonly) so as not to overwrite the real one
+ */
+ Cache.loadProperties("test/src/jalview/io/testProps.jvprops");
+
+ RestClient[] clients = RestClient.getRestClients();
+ System.out.println("Got " + clients.length + " clients.");
+ int i = 0;
+ Vector<String> urls = new Vector<String>();
+ for (RestClient cl : clients)
+ {
+ System.out.println("" + (++i) + ": " + cl.service.toString());
+ urls.add(cl.service.toString());
+ }
+ RestClient.setRsbsServices(urls);
+
+ RestClient[] restClients = RestClient.getRestClients();
+ assertEquals("", clients.length, restClients.length);
+
+ /*
+ * Check the two lists hold 'equal' (albeit different) objects. Ordering
+ * should be the same as getRestClients returns the list in the same order
+ * as setRsbsServices sets it.
+ */
+ for (i = 0; i < clients.length; i++)
+ {
+ /*
+ * RestServiceDescription.equals() compares numerous fields
+ */
+ assertEquals(clients[i].getRestDescription(),
+ restClients[i].getRestDescription());
+ }
+ }
+}