From: amwaterhouse Date: Wed, 26 Oct 2005 14:31:45 +0000 (+0000) Subject: vamsasDemo new branch X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=783520af519c958e10a2af29f1d4242e1ab890a3;p=jalview.git vamsasDemo new branch --- diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index e303500..b632442 100755 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -29,6 +29,7 @@ import java.awt.event.*; import java.util.*; import java.io.InputStreamReader; import java.io.BufferedReader; +import java.io.FileReader; public class AlignFrame extends GAlignFrame @@ -139,6 +140,78 @@ public class AlignFrame } + + /** + * DOCUMENT ME! + * + * @param String DOCUMENT ME! + */ + + public void parseGroupsFile(String file) + { + try + { + BufferedReader in = new BufferedReader(new FileReader(file)); + SequenceI seq = null; + String line, text, token; + UserColourScheme ucs; + int index, start, end; + StringTokenizer st; + SequenceGroup sg; + int lineNo = 0; + while ( (line = in.readLine()) != null) + { + lineNo++; + st = new StringTokenizer(line, "\t"); + if (st.countTokens() != 6) + { + System.out.println("Groups file " + file + + " is invalid. Read help file.\nLine: \n" + +lineNo +": "+line); + break; + } + + while (st.hasMoreElements()) + { + text = st.nextToken(); + token = st.nextToken(); + if (!token.equals("ID_NOT_SPECIFIED")) + { + index = viewport.alignment.findIndex(viewport.alignment.findName( + token)); + st.nextToken(); + } + else + { + index = Integer.parseInt(st.nextToken()); + } + + start = Integer.parseInt(st.nextToken()); + end = Integer.parseInt(st.nextToken()); + ucs = new UserColourScheme(st.nextToken()); + + seq = viewport.alignment.getSequenceAt(index); + start = seq.findIndex(start) - 1; + end = seq.findIndex(end) - 1; + + sg = new SequenceGroup(text, ucs, true, true, false, start, end); + sg.addSequence(seq, false); + + viewport.alignment.addGroup(sg); + + } + } + + alignPanel.repaint(); + + } + catch (Exception ex) + { + System.out.println("Error parsing groups file: " + ex); + } + } + + public void inputText_actionPerformed(ActionEvent e) { CutAndPasteTransfer cap = new CutAndPasteTransfer(true, applet); @@ -155,7 +228,7 @@ public class AlignFrame jalview.bin.JalviewLite.addFrame(frame, "Alignment output - " + e.getActionCommand(), 600, 500); - cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(), + cap.setText(new AppletFormatAdapter().formatSequences(e.getActionCommand(), viewport.getAlignment(). getSequences())); } diff --git a/src/jalview/appletgui/CutAndPasteTransfer.java b/src/jalview/appletgui/CutAndPasteTransfer.java index 4c0d3de..6627e88 100755 --- a/src/jalview/appletgui/CutAndPasteTransfer.java +++ b/src/jalview/appletgui/CutAndPasteTransfer.java @@ -74,7 +74,7 @@ public class CutAndPasteTransfer SequenceI[] sequences = null; String format = IdentifyFile.Identify(text, "Paste"); - sequences = new FormatAdapter().readFile(text, "Paste", format); + sequences = new AppletFormatAdapter().readFile(text, "Paste", format); if (sequences != null) { diff --git a/src/jalview/appletgui/FeatureRenderer.java b/src/jalview/appletgui/FeatureRenderer.java index 291ce5f..9d6503d 100755 --- a/src/jalview/appletgui/FeatureRenderer.java +++ b/src/jalview/appletgui/FeatureRenderer.java @@ -48,12 +48,12 @@ public class FeatureRenderer while (e.hasMoreElements()) { SequenceFeature sf = (SequenceFeature) e.nextElement(); - if (sf.getStart() > seq.getEnd()) + if (sf.getBegin() > seq.getEnd()) { continue; } - int fstart = seq.findIndex(sf.getStart()) - 1; + int fstart = seq.findIndex(sf.getBegin()) - 1; int fend = seq.findIndex(sf.getEnd()) - 1; if ( (fstart <= end && fend >= start)) diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 9ed48b2..dec2b0a 100755 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -302,7 +302,7 @@ public class SeqPanel while (e.hasMoreElements()) { SequenceFeature sf = (SequenceFeature) e.nextElement(); - if (sf.getStart() <= sequence.findPosition(res) && + if (sf.getBegin() <= sequence.findPosition(res) && sf.getEnd() >= sequence.findPosition(res)) { if (sbuffer.length() > 0) diff --git a/src/jalview/bin/JalviewLite.java b/src/jalview/bin/JalviewLite.java index 1e94a0d..a263ed4 100755 --- a/src/jalview/bin/JalviewLite.java +++ b/src/jalview/bin/JalviewLite.java @@ -80,7 +80,9 @@ public class JalviewLite extends Applet if (file != null) { add(launcher); - file = applet.getCodeBase() + file; + if(!file.startsWith("http://") && !file.startsWith("file://")) + file = applet.getCodeBase() + file; + launcher.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) @@ -108,7 +110,7 @@ public class JalviewLite extends Applet String format = jalview.io.IdentifyFile.Identify(args[0],"File"); - SequenceI[] sequences = new FormatAdapter().readFile(args[0], "File", format); + SequenceI[] sequences = new AppletFormatAdapter().readFile(args[0], "File", format); if ( (sequences != null) && (sequences.length > 0)) { @@ -227,7 +229,7 @@ public class JalviewLite extends Applet public void run() { SequenceI[] sequences = null; - sequences = new FormatAdapter().readFile(file, protocol, format); + sequences = new AppletFormatAdapter().readFile(file, protocol, format); if ((sequences != null) && (sequences.length > 0)) { diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index ac8f47a..309fdae 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -29,12 +29,15 @@ import java.util.*; */ public class Alignment implements AlignmentI { + protected Alignment dataset; protected Vector sequences; protected Vector groups = new Vector(); protected Vector superGroup = new Vector(); protected char gapCharacter = '-'; - protected boolean isNucleotide = true; - + protected Provenance provenance; + protected int type = NUCLEOTIDE; + public static final int PROTEIN = 0; + public static final int NUCLEOTIDE = 1; /** DOCUMENT ME!! */ public AlignmentAnnotation[] annotations; @@ -48,21 +51,12 @@ public class Alignment implements AlignmentI */ public Alignment(SequenceI[] seqs) { - int i=0, iSize = seqs.length, j, jSize; - while(isNucleotide && i - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ + public void setStatus(String status) + { + this.status = status; + } + } diff --git a/src/jalview/datamodel/SequenceI.java b/src/jalview/datamodel/SequenceI.java index b7c9197..186179b 100755 --- a/src/jalview/datamodel/SequenceI.java +++ b/src/jalview/datamodel/SequenceI.java @@ -232,4 +232,14 @@ public interface SequenceI * @return DOCUMENT ME! */ public String getPDBId(); + + public String getVamsasId(); + + public void setVamsasId(String id); + + public Vector getDBRef(); + + public void addDBRef(DBRefEntry entry); + + public void addSequenceFeature(SequenceFeature sf); } diff --git a/src/jalview/datamodel/UniprotEntry.java b/src/jalview/datamodel/UniprotEntry.java new file mode 100755 index 0000000..0bc0f0b --- /dev/null +++ b/src/jalview/datamodel/UniprotEntry.java @@ -0,0 +1,52 @@ +package jalview.datamodel; + +import java.util.Vector; + +public class UniprotEntry +{ + + UniprotSequence sequence; + String name; + String accession; + Vector features; + + public void setFeatures(Vector items) + { + features = items; + } + + public Vector getFeatures() { + return features; + } + + public void setAccession(String acc) + { + accession = acc; + } + + public String getAccession() + { + return accession; + } + + + public void setName(String na) + { + name = na; + } + public String getName() + { + return name; + } + + public UniprotSequence getUniprotSequence() + { + return sequence; + } + + public void setUniprotSequence(UniprotSequence seq) + { + sequence = seq; + } + +} diff --git a/src/jalview/datamodel/UniprotFile.java b/src/jalview/datamodel/UniprotFile.java new file mode 100755 index 0000000..c668c4b --- /dev/null +++ b/src/jalview/datamodel/UniprotFile.java @@ -0,0 +1,16 @@ +package jalview.datamodel; +import java.util.Vector; + +public class UniprotFile +{ + Vector _items; + + public void setUniprotEntries(Vector items) { + _items = items; + } + + public Vector getUniprotEntries() { + return _items; + } + +} diff --git a/src/jalview/datamodel/UniprotSequence.java b/src/jalview/datamodel/UniprotSequence.java new file mode 100755 index 0000000..9233889 --- /dev/null +++ b/src/jalview/datamodel/UniprotSequence.java @@ -0,0 +1,24 @@ +package jalview.datamodel; + +public class UniprotSequence +{ + /** + * internal content storage + */ + private java.lang.String _content = ""; + + public void setContent(String seq) + { + StringBuffer sb = new StringBuffer(); + for(int i=0; i seq.getEnd()) + + if (sf.getBegin() > seq.getEnd()) { continue; } - int fstart = seq.findIndex(sf.getStart()) - 1; + int fstart = seq.findIndex(sf.getBegin()) - 1; int fend = seq.findIndex(sf.getEnd()) - 1; if (((fstart <= end) && (fend >= start))) @@ -94,7 +135,7 @@ public class FeatureRenderer if (fstart == fend) { - g.setColor(Color.red); + g.setColor(getColour(type)); g.fillRoundRect((fstart - start) * width, y1, width, height, 4, 4); g.setColor(Color.white); @@ -118,7 +159,7 @@ public class FeatureRenderer continue; } - g.setColor(Color.blue); + g.setColor(getColour(type)); g.fillRect((i - start) * width, y1, width, height); g.setColor(Color.white); @@ -133,5 +174,89 @@ public class FeatureRenderer } } } + g.setComposite( + AlphaComposite.getInstance( + AlphaComposite.SRC_OVER,1.0f)); + } + + public Color getColour(String featureType) + { + return (Color)featureColours.get(featureType); + } + + public void setColour(String featureType, Color col) + { + featureColours.put(featureType, col); + } + + public void setTransparency(float value) + { + transparency = value; + } + + public float getTransparency() + { + return transparency; + } + + public void setFeaturePriority(Object [][] data) + { + // The feature table will display high priority + // features at the top, but theses are the ones + // we need to render last, so invert the data + featuresDisplayed = new Vector(); + for(int i=data.length-1; i>-1; i--) + { + String type = data[i][0].toString(); + setColour(type, (Color)data[i][1]); + if( ((Boolean)data[i][2]).booleanValue() ) + featuresDisplayed.addElement(type); + } + } + + Hashtable featureColours = new Hashtable(); + void initColours() + { + featureColours.put("active site", new Color(255, 75, 0)); + featureColours.put("binding site", new Color(245, 85, 0)); + featureColours.put("calcium-binding region", new Color(235, 95, 0)); + featureColours.put("chain", new Color(225, 105, 0)); + featureColours.put("coiled-coil region", new Color(215, 115, 0)); + featureColours.put("compositionally biased region", new Color(205, 125, 0)); + featureColours.put("cross-link", new Color(195, 135, 0)); + featureColours.put("disulfide bond", new Color(185, 145, 0)); + featureColours.put("DNA-binding region", new Color(175, 155, 0)); + featureColours.put("domain", new Color(165, 165, 0)); + featureColours.put("glycosylation site", new Color(155, 175, 0)); + featureColours.put("helix", new Color(145, 185, 0)); + featureColours.put("initiator methionine", new Color(135, 195, 5)); + featureColours.put("lipid moiety-binding region", new Color(125, 205, 15)); + featureColours.put("metal ion-binding site", new Color(115, 215, 25)); + featureColours.put("modified residue", new Color(105, 225, 35)); + featureColours.put("mutagenesis site", new Color(95, 235, 45)); + featureColours.put("non-consecutive residues", new Color(85, 245, 55)); + featureColours.put("non-terminal residue", new Color(75, 255, 65)); + featureColours.put("nucleotide phosphate-binding region", + new Color(65, 245, 75)); + featureColours.put("peptide", new Color(55, 235, 85)); + featureColours.put("propeptide", new Color(45, 225, 95)); + featureColours.put("region of interest", new Color(35, 215, 105)); + featureColours.put("repeat", new Color(25, 205, 115)); + featureColours.put("selenocysteine", new Color(15, 195, 125)); + featureColours.put("sequence conflict", new Color(5, 185, 135)); + featureColours.put("sequence variant", new Color(0, 175, 145)); + featureColours.put("short sequence motif", new Color(0, 165, 155)); + featureColours.put("signal peptide", new Color(0, 155, 165)); + featureColours.put("site", new Color(0, 145, 175)); + featureColours.put("splice variant", new Color(0, 135, 185)); + featureColours.put("strand", new Color(0, 125, 195)); + featureColours.put("topological domain", new Color(0, 115, 205)); + featureColours.put("transit peptide", new Color(0, 105, 215)); + featureColours.put("transmembrane region", new Color(0, 95, 225)); + featureColours.put("turn", new Color(0, 85, 235)); + featureColours.put("unsure residue", new Color(0, 75, 245)); + featureColours.put("zinc finger region", new Color(0, 65, 255)); + } + } diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java new file mode 100755 index 0000000..aa9f827 --- /dev/null +++ b/src/jalview/gui/FeatureSettings.java @@ -0,0 +1,343 @@ +package jalview.gui; + +import jalview.datamodel.*; +import javax.swing.*; +import javax.swing.event.*; +import java.awt.*; +import java.util.*; +import javax.swing.BorderFactory; +import java.awt.event.*; +import javax.swing.table.*; + +public class FeatureSettings extends JPanel +{ + Vector allFeatures; + final FeatureRenderer fr; + final AlignmentPanel ap; + Object [][] originalData; + + public FeatureSettings(AlignViewport av, final AlignmentPanel ap) + { + this.ap = ap; + fr = ap.seqPanel.seqCanvas.getFeatureRenderer(); + av.alignment.getSequences(); + final JInternalFrame frame = new JInternalFrame(); + frame.setContentPane(this); + Desktop.addInternalFrame(frame, "Sequence Feature Settings", 500, 300); + + + allFeatures = new Vector(); + Vector features; + Enumeration e; + SequenceFeature sf; + for(int i=0; i< av.alignment.getHeight(); i++) + { + features = av.alignment.getSequenceAt(i).getSequenceFeatures(); + if(features==null) + continue; + + e = features.elements(); + while(e.hasMoreElements()) + { + sf = (SequenceFeature)e.nextElement(); + if(!allFeatures.contains(sf.getType())) + { + allFeatures.addElement(sf.getType()); + } + } + } + if(allFeatures.size()<1) + { + try{ + frame.setClosed(true); + }catch(Exception ex){} + return; + } + + int fSize = allFeatures.size(); + + String type; + Object [][] data = new Object[fSize][3]; + originalData = new Object[fSize][3]; + for(int i=0; i 0)) + if ((group == null) && (av.alignment.getGroups().size() > 0)) { - group = (SequenceGroup) groups.elementAt(0); + group = (SequenceGroup) av.alignment.getGroups().elementAt(0); groupIndex = 0; } - if (group != null && !isOverview) { do @@ -701,14 +753,14 @@ public class SeqCanvas extends JComponent groupIndex++; - if (groupIndex >= groups.size()) + if (groupIndex >= av.alignment.getGroups().size()) { break; } - group = (SequenceGroup) groups.elementAt(groupIndex); + group = (SequenceGroup) av.alignment.getGroups().elementAt(groupIndex); } - while (groupIndex < groups.size()); + while (groupIndex < av.alignment.getGroups().size()); } /// Highlight search Results once all sequences have been drawn diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index a68b226..53130af 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -89,6 +89,7 @@ public class SeqPanel extends JPanel ap = p; + addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent evt) @@ -100,10 +101,12 @@ public class SeqPanel extends JPanel { if (editingSeqs) { + if(!av.isDataset()) doMouseDragged(evt); } else { + if(!av.isDataset()) doMouseDraggedDefineMode(evt); } } @@ -118,7 +121,7 @@ public class SeqPanel extends JPanel { Font font = av.getFont(); int fontSize = font.getSize(); - if (e.getWheelRotation() > 0 && fontSize < 30) + if (e.getWheelRotation() > 0 && fontSize < 51) fontSize++; else if (fontSize > 1) fontSize--; @@ -138,67 +141,70 @@ public class SeqPanel extends JPanel }); - addMouseListener(new MouseAdapter() - { - public void mouseReleased(MouseEvent evt) - { - mouseWheelPressed = false; - - if (editingSeqs) - { - doMouseReleased(evt); - } - else - { - doMouseReleasedDefineMode(evt); - } - } - - public void mousePressed(MouseEvent evt) - { - if( javax.swing.SwingUtilities.isMiddleMouseButton(evt)) - { - mouseWheelPressed = true; - return; - } + if(!av.isDataset()) + { + addMouseListener(new MouseAdapter() + { + public void mouseReleased(MouseEvent evt) + { + mouseWheelPressed = false; - if (evt.isShiftDown() || evt.isAltDown() || - evt.isControlDown()) - { - if (evt.isAltDown() || evt.isControlDown()) - { - groupEditing = true; - } + if (editingSeqs) + { + doMouseReleased(evt); + } + else + { + doMouseReleasedDefineMode(evt); + } + } - editingSeqs = true; - doMousePressed(evt); - } - else - { - doMousePressedDefineMode(evt); - } - } + public void mousePressed(MouseEvent evt) + { + if (javax.swing.SwingUtilities.isMiddleMouseButton(evt)) + { + mouseWheelPressed = true; + return; + } + + if (evt.isShiftDown() || evt.isAltDown() || + evt.isControlDown()) + { + if (evt.isAltDown() || evt.isControlDown()) + { + groupEditing = true; + } + + editingSeqs = true; + doMousePressed(evt); + } + else + { + doMousePressedDefineMode(evt); + } + } - public void mouseExited(MouseEvent evt) - { - if (editingSeqs) - { - return; - } + public void mouseExited(MouseEvent evt) + { + if (editingSeqs) + { + return; + } - doMouseExitedDefineMode(evt); - } + doMouseExitedDefineMode(evt); + } - public void mouseEntered(MouseEvent evt) - { - if (editingSeqs) - { - return; - } + public void mouseEntered(MouseEvent evt) + { + if (editingSeqs) + { + return; + } - doMouseEnteredDefineMode(evt); - } - }); + doMouseEnteredDefineMode(evt); + } + }); + } } int startWrapBlock=-1; @@ -377,31 +383,38 @@ public class SeqPanel extends JPanel if (av.showSequenceFeatures) { Vector features = sequence.getSequenceFeatures(); - Enumeration e = features.elements(); - StringBuffer sbuffer = new StringBuffer(); - - while (e.hasMoreElements()) + if(features!=null) { - SequenceFeature sf = (SequenceFeature) e.nextElement(); + StringBuffer sbuffer = new StringBuffer(""); - if ((sf.getStart() <= sequence.findPosition(res)) && - (sf.getEnd() >= sequence.findPosition(res))) + for (int i = 0; i < features.size(); i++) + { + SequenceFeature sf = (SequenceFeature) features.elementAt(i); + + if ( (sf.getBegin() <= sequence.findPosition(res)) && + (sf.getEnd() >= sequence.findPosition(res))) { - if (sbuffer.length() > 0) - { - sbuffer.append("; "); - } + if (sbuffer.length() > 6) + sbuffer.append("
"); - sbuffer.append(sf.getType() + " " + sf.getDescription()); + sbuffer.append(sf.getType()); + if (sf.getDescription() != null) + sbuffer.append(" " + sf.getDescription()); - if (sf.getStatus().length() > 0) - { - sbuffer.append(" (" + sf.getStatus() + ")"); - } + if (sf.getStatus() != null) + { + sbuffer.append(" (" + sf.getStatus() + ")"); + } } - } - this.setToolTipText(sbuffer.toString()); + } + + sbuffer.append(""); + if(sbuffer.equals("")) + setToolTipText(""); + else + setToolTipText(sbuffer.toString()); + } } } diff --git a/src/jalview/gui/SequenceRenderer.java b/src/jalview/gui/SequenceRenderer.java index 6bf4d40..b961b2c 100755 --- a/src/jalview/gui/SequenceRenderer.java +++ b/src/jalview/gui/SequenceRenderer.java @@ -116,10 +116,10 @@ public class SequenceRenderer graphics = g; - drawBoxes(seq, start, end, x1, y1, width, height); + drawBoxes(seq, start, end, x1, y1, (int) width, height); fm = g.getFontMetrics(); - drawText(seq, start, end, x1, y1, width, height); + drawText(seq, start, end, x1, y1, (int) width, height); } /** @@ -168,7 +168,14 @@ public class SequenceRenderer { if (tempColour != null) { - graphics.fillRect(x1 + (width * (curStart - start)), y1, + int xxx = x1 + (int) (av.charWidth * (curStart - start)); + if (width != av.charWidth) + { + xxx = x1 + (int) (av.charWidth * (curStart - start)) / 3; + } + + + graphics.fillRect(xxx, y1, curWidth, height); } @@ -186,7 +193,14 @@ public class SequenceRenderer i++; } - graphics.fillRect(x1 + (width * (curStart - start)), y1, curWidth, + int xxx = x1 + (int) (av.charWidth * (curStart - start)); + if (width != av.charWidth) + { + xxx = x1 + (int) (av.charWidth * (curStart - start)) / 3; + } + + + graphics.fillRect(xxx, y1, curWidth, height); } @@ -208,6 +222,7 @@ public class SequenceRenderer int charOffset = 0; char s; + // Need to find the sequence position here. String sequence = seq.getSequence(); @@ -261,8 +276,14 @@ public class SequenceRenderer } charOffset = (width - fm.charWidth(s)) / 2; - graphics.drawString(String.valueOf(s), - charOffset + x1 + (int)(width * (i - start)), (y1 + height) - pady); + + int xxx = charOffset + x1 + (int)(av.charWidth * (i - start)); + if(width != av.charWidth) + { + xxx = charOffset + x1 + (int)(av.charWidth * (i - start))/3; + } + + graphics.drawString(String.valueOf(s),xxx, (y1 + height) - pady); } } diff --git a/src/jalview/gui/SplashScreen.java b/src/jalview/gui/SplashScreen.java index 20624af..49730a0 100755 --- a/src/jalview/gui/SplashScreen.java +++ b/src/jalview/gui/SplashScreen.java @@ -127,10 +127,9 @@ public class SplashScreen extends JPanel implements Runnable int y = yoffset; - g.drawString("Jalview 2005 ", 50, y); + g.drawString("Jalview "+jalview.bin.Cache.getProperty("VERSION"), 50, y); g.setFont(new Font("Verdana", Font.BOLD, fontSize + 2)); - g.drawString("Version " + jalview.bin.Cache.getProperty("VERSION") + - "; Last updated: " + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"), + g.drawString("Last updated: " + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"), 180, y); if (jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking").equals("Checking")) diff --git a/src/jalview/io/AlignFile.java b/src/jalview/io/AlignFile.java index d22dc12..630dc6c 100755 --- a/src/jalview/io/AlignFile.java +++ b/src/jalview/io/AlignFile.java @@ -39,6 +39,8 @@ public abstract class AlignFile extends FileParse Vector headers; long start; long end; + boolean dbPrefix = false; + boolean jvSuffix = true; /** * Creates a new AlignFile object. @@ -149,4 +151,99 @@ public abstract class AlignFile extends FileParse * Print out in alignment file format the Sequences in the seqs Vector. */ public abstract String print(); + + public void addDBPrefix(boolean b) + { + dbPrefix = b; + } + + public void addJVSuffix(boolean b) + { + jvSuffix = b; + } + + /** + * A general parser for ids. Will look for dbrefs in + * Uniprot format source|id + * And also Jalview /start-end + * + * @String id Id to be parsed + */ + Sequence parseId(String id) + { + Sequence seq = new Sequence("",""); + int space = id.indexOf(" "); + if(space>-1) + { + seq.setDescription(id.substring(space+1)); + id = id.substring(0, space); + } + + // Read in any DB refs first + StringTokenizer st; + st = new StringTokenizer(id, "|"); + + while (st.countTokens()>2) + { + seq.addDBRef( new DBRefEntry( st.nextToken(), "0", st.nextToken())); + } + + if(st.hasMoreTokens()) + id = st.nextToken(); + + + // Remove /start-end from sequence + if (id.indexOf("/") > 0) + { + st = new StringTokenizer(id, "/"); + + if (st.countTokens() == 2) + { + id = st.nextToken(); + + String tmp = st.nextToken(); + + st = new StringTokenizer(tmp, "-"); + + if (st.countTokens() == 2) + { + seq.setStart( Integer.valueOf(st.nextToken()).intValue() ); + seq.setEnd( Integer.valueOf(st.nextToken()).intValue() ); + } + } + } + seq.setName(id); + return seq; + } + + /** + * Creates the output id. + * Adds prefix Uniprot format source|id + * And suffix Jalview /start-end + * + * @String id Id to be parsed + */ + String printId(SequenceI seq) + { + StringBuffer result = new StringBuffer(); + if(dbPrefix && seq.getDBRef()!=null) + { + Vector dbrefs = seq.getDBRef(); + for(int i=0; i -1) { - if (line.indexOf(" ") > -1) // - { - ///Colur it be this format? - //>54402046 0 1 137 137: - // or this?? - // 1 >L1H14 30539 343 - try - { - ids.addElement(line.substring(abracket + 1, - line.indexOf(" ", abracket + 1))); - - // remove p Value - line = line.substring(abracket + 1); - line = line.substring(line.indexOf(" ") + 1); - line = line.trim(); - line = line.substring(line.indexOf(" ") + 1); - line = line.trim(); - - int value = Integer.parseInt(line.substring(0, - line.indexOf(" "))); - starts.addElement(value + ""); - line = line.substring(line.indexOf(" ") + 1); - line = line.trim(); - value = Integer.parseInt(line.substring(0, - line.indexOf(" "))); - ends.addElement(value + ""); - } - catch (Exception ex) - { - System.err.println("Error during blockfile read."); - ex.printStackTrace(); - starts.addElement("1"); - ends.addElement("-1"); - } - } - else - { - if (line.indexOf("/") > -1) - { - ids.addElement(line.substring(abracket + 1, - line.indexOf("/"))); - line = line.substring(line.indexOf("/") + 1); - starts.addElement(line.substring(0, - line.indexOf("-"))); - ends.addElement(line.substring(line.indexOf("-") + - 1)); - } - else - { - ids.addElement(line.substring(abracket + 1)); - starts.addElement("1"); - ends.addElement("-1"); - } - } + if (line.indexOf(" ") > -1) // + { + line = line.substring(abracket + 1, + line.indexOf(" ", abracket + 1)); + } + else + line = line.substring(abracket+1); + + Sequence seq = parseId(line); + ids.addElement(seq.getName()); + starts.addElement(seq.getStart() + ""); + ends.addElement(seq.getEnd() + ""); } } while (!idsFound); @@ -217,17 +175,22 @@ public class BLCFile extends AlignFile * * @return DOCUMENT ME! */ - public static String print(SequenceI[] s) + public String print(SequenceI[] s) { StringBuffer out = new StringBuffer(); - + /** + * A general parser for ids. Will look for dbrefs in + * Uniprot format source|id + * And also Jalview /start-end + * + * @String id Id to be parsed + */ int i = 0; int max = -1; while ((i < s.length) && (s[i] != null)) { - out.append(">" + s[i].getName() + "/" + s[i].getStart() + "-" + - s[i].getEnd() + "\n"); + out.append(">" + printId(s[i]) +"\n"); if (s[i].getSequence().length() > max) { diff --git a/src/jalview/io/ClustalFile.java b/src/jalview/io/ClustalFile.java index 71e86b3..981e3c9 100755 --- a/src/jalview/io/ClustalFile.java +++ b/src/jalview/io/ClustalFile.java @@ -27,7 +27,6 @@ import jalview.util.*; public class ClustalFile extends AlignFile { - Vector ids; public ClustalFile() { @@ -47,7 +46,6 @@ public class ClustalFile public void initData() { super.initData(); - ids = new Vector(); } public void parse() @@ -121,9 +119,6 @@ public class ClustalFile //Add sequences to the hash for (i = 0; i < headers.size(); i++) { - int start = 1; - int end = -1; - if (seqhash.get(headers.elementAt(i)) != null) { if (maxLength < seqhash.get(headers.elementAt(i)).toString() @@ -133,40 +128,8 @@ public class ClustalFile .length(); } - String head = headers.elementAt(i).toString(); - - if (head.indexOf("/") > 0) - { - StringTokenizer st = new StringTokenizer(head, "/"); - - if (st.countTokens() == 2) - { - ids.addElement(st.nextToken()); - - String tmp = st.nextToken(); - st = new StringTokenizer(tmp, "-"); - - if (st.countTokens() == 2) - { - start = Integer.valueOf(st.nextToken()) - .intValue(); - end = Integer.valueOf(st.nextToken()).intValue(); - } - } - else - { - ids.addElement(headers.elementAt(i)); - } - } - else - { - ids.addElement(headers.elementAt(i)); - } - - Sequence newSeq = new Sequence(ids.elementAt(i).toString(), - seqhash.get(headers.elementAt(i). - toString()) - .toString(), start, end); + Sequence newSeq = parseId(headers.elementAt(i).toString()); + newSeq.setSequence( seqhash.get(headers.elementAt(i).toString()).toString() ); seqs.addElement(newSeq); } @@ -185,7 +148,7 @@ public class ClustalFile return print(getSeqsAsArray()); } - public static String print(SequenceI[] s) + public String print(SequenceI[] s) { StringBuffer out = new StringBuffer("CLUSTAL\n\n"); @@ -196,8 +159,7 @@ public class ClustalFile while ( (i < s.length) && (s[i] != null)) { - String tmp = s[i].getName() + "/" + s[i].getStart() + "-" + - s[i].getEnd(); + String tmp = printId(s[i]); if (s[i].getSequence().length() > max) { @@ -228,8 +190,7 @@ public class ClustalFile while ( (j < s.length) && (s[j] != null)) { - out.append(new Format("%-" + maxid + "s").form(s[j].getName() + - "/" + s[j].getStart() + "-" + s[j].getEnd()) + " "); + out.append(new Format("%-" + maxid + "s").form( printId(s[j]) + " ")); int start = i * len; int end = start + len; diff --git a/src/jalview/io/EBIFetchClient.java b/src/jalview/io/EBIFetchClient.java index eebbfc8..c1a0302 100755 --- a/src/jalview/io/EBIFetchClient.java +++ b/src/jalview/io/EBIFetchClient.java @@ -18,6 +18,8 @@ */ package jalview.io; +import java.io.*; + import org.apache.axis.AxisFault; import org.apache.axis.client.*; import org.apache.axis.encoding.XMLType; @@ -118,6 +120,45 @@ public class EBIFetchClient } } + public static void main (String [] args) + { + EBIFetchClient ebi = new EBIFetchClient(); + String[] result = ebi.fetchData("uniprot:25K89D_SARPE;G6PblobD_HUMAN", + "xml", null); + + try{ + java.io.PrintWriter out = new java.io.PrintWriter( + new java.io.FileWriter("out.xml")); + + + for(int i=0; idbref/dbref/dbref|refid1|refid2|refid3 'human-readable' style of naming (should it really exist) - if (line.substring(0, 1).equals(">")) + if (line.charAt(0)=='>') { + seq = parseId(line.substring(1)); + if (count != 0) { - if (sstart != 0) - { - seqs.addElement(new Sequence(id, seq.toString(), - sstart, send)); - } - else - { - seqs.addElement(new Sequence(id, seq.toString(), 1, - seq.length())); - } + seq.setSequence(sb.toString()); + seqs.addElement(seq); } count++; - - StringTokenizer str = new StringTokenizer(line, " "); - - id = str.nextToken(); - id = id.substring(1); - - com.stevesoft.pat.Regex dbId = new com.stevesoft.pat.Regex( - "[A-Za-z-]+/?[A-Za-z-]+\\|(\\w+)\\|(.+)"); - - // JBPNote At the moment - we don't get rid of the friendly names but this - // behaviour is probably wrong in the long run. - if (dbId.search(id)) - { - String dbid = dbId.stringMatched(1); - String idname = dbId.stringMatched(2); - - if ((idname.length() > 0) && - (idname.indexOf("_") > -1)) - { - id = idname; // use the friendly name - apparently no dbid - } - else if (dbid.length() > 1) - { - id = dbid; // ignore the friendly name - we lose uniprot accession ID otherwise - } - } - - if (id.indexOf("/") > 0) - { - StringTokenizer st = new StringTokenizer(id, "/"); - - if (st.countTokens() == 2) - { - id = st.nextToken(); - - String tmp = st.nextToken(); - - st = new StringTokenizer(tmp, "-"); - - if (st.countTokens() == 2) - { - sstart = Integer.valueOf(st.nextToken()) - .intValue(); - send = Integer.valueOf(st.nextToken()).intValue(); - } - } - } - - seq = new StringBuffer(); + sb = new StringBuffer(); } else { - seq = seq.append(line); + sb.append(line); } } } if (count > 0) { - if (!isValidProteinSequence(seq.toString().toUpperCase())) + if (!isValidProteinSequence(sb.toString().toUpperCase())) { throw new IOException("Invalid protein sequence"); } - if (sstart != 0) - { - seqs.addElement(new Sequence(id, seq.toString().toUpperCase(), - sstart, send)); - } - else - { - seqs.addElement(new Sequence(id, seq.toString().toUpperCase(), - 1, seq.length())); - } + seq.setSequence(sb.toString()); + seqs.addElement(seq); } } - /** - * DOCUMENT ME! - * - * @param s DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public static String print(SequenceI[] s) - { - return print(s, 72); - } - - /** - * DOCUMENT ME! - * - * @param s DOCUMENT ME! - * @param len DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public static String print(SequenceI[] s, int len) - { - return print(s, len, true); - } - - /** - * DOCUMENT ME! - * - * @param s DOCUMENT ME! - * @param len DOCUMENT ME! - * @param gaps DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public static String print(SequenceI[] s, int len, boolean gaps) - { - return print(s, len, gaps, true); - } /** * DOCUMENT ME! @@ -231,43 +126,34 @@ public class FastaFile extends AlignFile * * @return DOCUMENT ME! */ - public static String print(SequenceI[] s, int len, boolean gaps, - boolean displayId) + public String print(SequenceI[] s) { + int len = 72; StringBuffer out = new StringBuffer(); int i = 0; while ((i < s.length) && (s[i] != null)) { - String seq = ""; - - if (gaps) - { - seq = s[i].getSequence(); - } - else - { - seq = AlignSeq.extractGaps("-. ", s[i].getSequence()); - } + out.append(">" + printId(s[i])); + if(s[i].getDescription()!=null) + out.append(" "+s[i].getDescription()); - // used to always put this here: + "/" + s[i].getStart() + "-" + s[i].getEnd() + - out.append(">" + - ((displayId) ? s[i].getDisplayId() : s[i].getName()) + "\n"); + out.append("\n"); - int nochunks = (seq.length() / len) + 1; + int nochunks = (s[i].getLength() / len) + 1; for (int j = 0; j < nochunks; j++) { int start = j * len; int end = start + len; - if (end < seq.length()) + if (end < s[i].getLength()) { - out.append(seq.substring(start, end) + "\n"); + out.append(s[i].getSequence(start, end) + "\n"); } - else if (start < seq.length()) + else if (start < s[i].getLength()) { - out.append(seq.substring(start) + "\n"); + out.append(s[i].getSequence(start, s[i].getLength()) + "\n"); } } diff --git a/src/jalview/io/FormatAdapter.java b/src/jalview/io/FormatAdapter.java index 61c2331..64f33cd 100755 --- a/src/jalview/io/FormatAdapter.java +++ b/src/jalview/io/FormatAdapter.java @@ -29,79 +29,8 @@ import java.util.Vector; * @author $author$ * @version $Revision$ */ -public class FormatAdapter +public class FormatAdapter extends AppletFormatAdapter { - /** DOCUMENT ME!! */ - public static final Vector formats = new Vector(); - - static - { - formats.addElement("FASTA"); - formats.addElement("MSF"); - formats.addElement("PileUp"); - formats.addElement("CLUSTAL"); - formats.addElement("BLC"); - formats.addElement("PIR"); - formats.addElement("PFAM"); - } - - AlignFile afile = null; - - /** - * DOCUMENT ME! - * - * @param inFile DOCUMENT ME! - * @param type DOCUMENT ME! - * @param format DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public SequenceI[] readFile(String inFile, String type, String format) - { - try - { - if (format.equals("FASTA")) - { - afile = new FastaFile(inFile, type); - } - else if (format.equals("MSF")) - { - afile = new MSFfile(inFile, type); - } - else if (format.equals("PileUp")) - { - afile = new PileUpfile(inFile, type); - } - else if (format.equals("CLUSTAL")) - { - afile = new ClustalFile(inFile, type); - } - else if (format.equals("BLC")) - { - afile = new BLCFile(inFile, type); - } - else if (format.equals("PIR")) - { - afile = new PIRFile(inFile, type); - } - else if (format.equals("PFAM")) - { - afile = new PfamFile(inFile, type); - } - - return afile.getSeqsAsArray(); - } - catch (Exception e) - { - System.err.println("Failed to read alignment using the '" + format + - "' reader."); - e.printStackTrace(); - } - - return null; - } - - /** * DOCUMENT ME! * @@ -124,30 +53,58 @@ public class FormatAdapter if (format.equalsIgnoreCase("FASTA")) { afile = new FastaFile(); + afile.addDBPrefix( + jalview.bin.Cache.getDefault("FASTA_DBPREFIX", false)); + afile.addJVSuffix( + jalview.bin.Cache.getDefault("FASTA_JVSUFFIX", true)); } else if (format.equalsIgnoreCase("MSF")) { - afile = new MSFfile(); + afile = new MSFfile(); + afile.addDBPrefix( + jalview.bin.Cache.getDefault("MSF_DBPREFIX", false)); + afile.addJVSuffix( + jalview.bin.Cache.getDefault("MSF_JVSUFFIX", true)); } else if (format.equalsIgnoreCase("PileUp")) { afile = new PileUpfile(); + afile.addDBPrefix( + jalview.bin.Cache.getDefault("PILEUP_DBPREFIX", false)); + afile.addJVSuffix( + jalview.bin.Cache.getDefault("PILEUP_JVSUFFIX", true)); } else if (format.equalsIgnoreCase("CLUSTAL")) { afile = new ClustalFile(); + afile.addDBPrefix( + jalview.bin.Cache.getDefault("CLUSTAL_DBPREFIX", false)); + afile.addJVSuffix( + jalview.bin.Cache.getDefault("CLUSTAL_JVSUFFIX", true)); } else if (format.equalsIgnoreCase("BLC")) { afile = new BLCFile(); + afile.addDBPrefix( + jalview.bin.Cache.getDefault("BLC_DBPREFIX", false)); + afile.addJVSuffix( + jalview.bin.Cache.getDefault("BLC_JVSUFFIX", true)); } else if (format.equalsIgnoreCase("PIR")) { afile = new PIRFile(); + afile.addDBPrefix( + jalview.bin.Cache.getDefault("PIR_DBPREFIX", false)); + afile.addJVSuffix( + jalview.bin.Cache.getDefault("PIR_JVSUFFIX", true)); } else if (format.equalsIgnoreCase("PFAM")) { afile = new PfamFile(); + afile.addDBPrefix( + jalview.bin.Cache.getDefault("PFAM_DBPREFIX", false)); + afile.addJVSuffix( + jalview.bin.Cache.getDefault("PFAM_JVSUFFIX", true)); } afile.setSeqs(s); diff --git a/src/jalview/io/MSFfile.java b/src/jalview/io/MSFfile.java index 2cef0fe..179204e 100755 --- a/src/jalview/io/MSFfile.java +++ b/src/jalview/io/MSFfile.java @@ -155,30 +155,11 @@ public class MSFfile extends AlignFile maxLength = head.length(); } - if (head.indexOf("/") > 0) - { - StringTokenizer st = new StringTokenizer(head, "/"); - - if (st.countTokens() == 2) - { - head = st.nextToken(); - - String tmp = st.nextToken(); - st = new StringTokenizer(tmp, "-"); - - if (st.countTokens() == 2) - { - start = Integer.valueOf(st.nextToken()).intValue(); - end = Integer.valueOf(st.nextToken()).intValue(); - } - } - } - - // Replace ~ with a sensible gap character seq = seq.replace('~', '-'); - Sequence newSeq = new Sequence(head, seq, start, end); + Sequence newSeq = parseId(head); + newSeq.setSequence(seq); seqs.addElement(newSeq); } @@ -197,7 +178,7 @@ public class MSFfile extends AlignFile * * @return DOCUMENT ME! */ - public static int checkSum(String seq) + public int checkSum(String seq) { int check = 0; String sequence = seq.toUpperCase(); @@ -223,17 +204,6 @@ public class MSFfile extends AlignFile return check % 10000; } - /** - * DOCUMENT ME! - * - * @param s DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public static String print(SequenceI[] s) - { - return print(s, false); - } /** * DOCUMENT ME! @@ -243,9 +213,11 @@ public class MSFfile extends AlignFile * * @return DOCUMENT ME! */ - public static String print(SequenceI[] seqs, boolean is_NA) + public String print(SequenceI[] seqs) { + boolean is_NA = jalview.util.Comparison.isNucleotide(seqs); + SequenceI [] s = new SequenceI[seqs.length]; StringBuffer out = new StringBuffer("!!" + (is_NA ? "NA" : "AA") + @@ -265,7 +237,7 @@ public class MSFfile extends AlignFile { if (sb.charAt(ii) == '.') { - sb.replace(ii, ii + 1, "~"); + sb.setCharAt(ii, '~'); } else break; @@ -275,7 +247,7 @@ public class MSFfile extends AlignFile { if (sb.charAt(ii) == '.') { - sb.replace(ii, ii + 1, "~"); + sb.setCharAt(ii,'~'); } else break; @@ -317,9 +289,7 @@ public class MSFfile extends AlignFile while ((i < s.length) && (s[i] != null)) { - nameBlock[i] = new String(" Name: " + s[i].getName() - + "/" + s[i].getStart() + "-" + s[i].getEnd() - +" "); + nameBlock[i] = new String(" Name: " + printId(s[i])+" "); idBlock[i] = new String("Len: " + maxLenpad.form(s[i].getSequence().length()) + " Check: " + @@ -373,11 +343,9 @@ public class MSFfile extends AlignFile while ((j < s.length) && (s[j] != null)) { - String name = s[j].getName(); - // out.append(new Format("%-" + maxid + "s").form(name)+ " "); + String name = printId( s[j] ); - out.append(new Format("%-" + maxid + "s").form(name - + "/" + s[j].getStart() + "-" + s[j].getEnd()) + " "); + out.append(new Format("%-" + maxid + "s").form(name+" ")); for (int k = 0; k < 5; k++) diff --git a/src/jalview/io/PIRFile.java b/src/jalview/io/PIRFile.java index 65890a9..d4b818b 100755 --- a/src/jalview/io/PIRFile.java +++ b/src/jalview/io/PIRFile.java @@ -48,9 +48,6 @@ public class PIRFile { try { - String id; - String start; - String end; StringBuffer sequence; String line = null; @@ -62,31 +59,11 @@ public class PIRFile continue; } - id = "No id"; - start = "1"; - end = "-1"; - - try - { - int slashIndex = line.indexOf("/"); - if(slashIndex!=-1) - { - id = line.substring(line.indexOf(";") + 1, line.indexOf("/")); - line = line.substring(line.indexOf("/") + 1); - start = line.substring(0, line.indexOf("-")); - end = line.substring(line.indexOf("-") + 1); - } - else - { - id = line.substring(line.indexOf(";")+1); - } - } - catch (Exception ex) - { }// Default id, start and end unchanged + Sequence newSeq = parseId(line.substring(line.indexOf(";") + 1)); sequence = new StringBuffer(); - line = nextLine(); // this is the title line + newSeq.setDescription(nextLine()); // this is the title line boolean starFound = false; @@ -108,9 +85,7 @@ public class PIRFile { sequence.setLength(sequence.length() - 1); - Sequence newSeq = new Sequence(id, sequence.toString(), - Integer.parseInt(start), - Integer.parseInt(end)); + newSeq.setSequence(sequence.toString()); seqs.addElement(newSeq); } } @@ -126,41 +101,27 @@ public class PIRFile return print(getSeqsAsArray()); } - public static String print(SequenceI[] s) - { - return print(s, 72, true); - } - - public static String print(SequenceI[] s, int len) - { - return print(s, len, true); - } - - public static String print(SequenceI[] s, int len, boolean gaps) + public String print(SequenceI[] s) { + boolean is_NA = jalview.util.Comparison.isNucleotide(s); + int len = 72; StringBuffer out = new StringBuffer(); int i = 0; while ( (i < s.length) && (s[i] != null)) { - String seq = ""; + String seq = s[i].getSequence(); + seq = seq + "*"; - if (gaps) - { - seq = s[i].getSequence() + "*"; - } + out.append(">P1;" + printId(s[i]) + "\n"); + + if(s[i].getDescription()!=null) + out.append(s[i].getDescription()+"\n"); else { - seq = AlignSeq.extractGaps(s[i].getSequence(), "-"); - seq = AlignSeq.extractGaps(seq, "."); - seq = AlignSeq.extractGaps(seq, " "); - seq = seq + "*"; + out.append(s[i].getName()+" "+ (s[i].getEnd() - s[i].getStart() + 1)); + out.append( is_NA ? " bases\n" : " residues\n"); } - - out.append(">P1;" + s[i].getName() + "/" + s[i].getStart() + "-" + - s[i].getEnd() + "\n"); - out.append(" Dummy title\n"); - int nochunks = (seq.length() / len) + 1; for (int j = 0; j < nochunks; j++) diff --git a/src/jalview/io/PfamFile.java b/src/jalview/io/PfamFile.java index 9a6ca54..ec52bac 100755 --- a/src/jalview/io/PfamFile.java +++ b/src/jalview/io/PfamFile.java @@ -27,7 +27,6 @@ import jalview.util.*; public class PfamFile extends AlignFile { - Vector ids; public PfamFile() { @@ -47,7 +46,6 @@ public class PfamFile public void initData() { super.initData(); - ids = new Vector(); } public void parse() @@ -113,45 +111,11 @@ public class PfamFile .length(); } - String head = headers.elementAt(i).toString(); - int start = 1; - int end = -1; - if (head.indexOf("/") > 0) - { - StringTokenizer st = new StringTokenizer(head, "/"); - - if (st.countTokens() == 2) - { - ids.addElement(st.nextToken()); - - String tmp = st.nextToken(); - st = new StringTokenizer(tmp, "-"); - - if (st.countTokens() == 2) - { - start = Integer.valueOf(st.nextToken()).intValue(); - end = Integer.valueOf(st.nextToken()).intValue(); - } - } - else - { - ids.addElement(headers.elementAt(i)); - } - } - else - { - ids.addElement(headers.elementAt(i)); - } - - Sequence newSeq = null; - - newSeq = new Sequence(ids.elementAt(i).toString(), - seqhash.get(headers.elementAt(i).toString()) - .toString(), start, end); + Sequence newSeq = parseId(headers.elementAt(i).toString()); + newSeq.setSequence( seqhash.get(headers.elementAt(i).toString()).toString()); seqs.addElement(newSeq); - if (!isValidProteinSequence(newSeq.getSequence())) { throw new IOException( @@ -166,7 +130,7 @@ public class PfamFile } } - public static String print(SequenceI[] s) + public String print(SequenceI[] s) { StringBuffer out = new StringBuffer(""); @@ -177,8 +141,7 @@ public class PfamFile while ( (i < s.length) && (s[i] != null)) { - String tmp = s[i].getName() + "/" + s[i].getStart() + "-" + - s[i].getEnd(); + String tmp = printId(s[i]); if (s[i].getSequence().length() > max) { @@ -202,8 +165,7 @@ public class PfamFile while ( (j < s.length) && (s[j] != null)) { - out.append(new Format("%-" + maxid + "s").form(s[j].getName() + - "/" + s[j].getStart() + "-" + s[j].getEnd()) + " "); + out.append(new Format("%-" + maxid + "s").form( printId(s[j])+" ")); out.append(s[j].getSequence() + "\n"); j++; diff --git a/src/jalview/io/PileUpfile.java b/src/jalview/io/PileUpfile.java index 8c8a3ea..c945fd5 100755 --- a/src/jalview/io/PileUpfile.java +++ b/src/jalview/io/PileUpfile.java @@ -30,170 +30,53 @@ package jalview.io; * **/ import java.io.*; -import java.util.*; import jalview.datamodel.*; import jalview.util.*; -public class PileUpfile - extends AlignFile +public class PileUpfile extends MSFfile { - public PileUpfile() - { - } - - public PileUpfile(String inStr) - { - super(inStr); - } - public PileUpfile(String inFile, String type) - throws IOException - { - super(inFile, type); - } - - public void parse() - { - int i = 0; - boolean seqFlag = false; - String key = new String(); - Vector headers = new Vector(); - Hashtable seqhash = new Hashtable(); - String line; - - try + /** + * Creates a new MSFfile object. + */ + public PileUpfile() { - while ( (line = nextLine()) != null) - { - StringTokenizer str = new StringTokenizer(line); - - while (str.hasMoreTokens()) - { - String inStr = str.nextToken(); - - //If line has header information add to the headers vector - if (inStr.indexOf("Name:") != -1) - { - key = str.nextToken(); - headers.addElement(key); - } - - //if line has // set SeqFlag to 1 so we know sequences are coming - if (inStr.indexOf("//") != -1) - { - seqFlag = true; - } - - //Process lines as sequence lines if seqFlag is set - if ( (inStr.indexOf("//") == -1) && (seqFlag == true)) - { - //seqeunce id is the first field - key = inStr; - - StringBuffer tempseq; - - //Get sequence from hash if it exists - if (seqhash.containsKey(key)) - { - tempseq = (StringBuffer) seqhash.get(key); - } - else - { - tempseq = new StringBuffer(); - seqhash.put(key, tempseq); - } - - //loop through the rest of the words - while (str.hasMoreTokens()) - { - //append the word to the sequence - tempseq.append(str.nextToken()); - } - } - } - } } - catch (IOException e) + /** + * Creates a new MSFfile object. + * + * @param inStr DOCUMENT ME! + */ + public PileUpfile(String inStr) { - System.err.println("Exception parsing PileUpfile " + e); - e.printStackTrace(); + super(inStr); } - this.noSeqs = headers.size(); - - //Add sequences to the hash - for (i = 0; i < headers.size(); i++) + /** + * Creates a new MSFfile object. + * + * @param inFile DOCUMENT ME! + * @param type DOCUMENT ME! + * + * @throws IOException DOCUMENT ME! + */ + public PileUpfile(String inFile, String type) throws IOException { - if (seqhash.get(headers.elementAt(i)) != null) - { - String head = headers.elementAt(i).toString(); - String seq = seqhash.get(head).toString(); - - int start = 1; - int end = -1; - - if (maxLength < head.length()) - { - maxLength = head.length(); - } - - if (head.indexOf("/") > 0) - { - StringTokenizer st = new StringTokenizer(head, "/"); - - if (st.countTokens() == 2) - { - head = st.nextToken(); - - String tmp = st.nextToken(); - st = new StringTokenizer(tmp, "-"); - - if (st.countTokens() == 2) - { - start = Integer.valueOf(st.nextToken()).intValue(); - end = Integer.valueOf(st.nextToken()).intValue(); - } - } - } - - Sequence newSeq = new Sequence(head, seq, start, end); - - seqs.addElement(newSeq); - } - else - { - System.err.println( - "PileUpfile Parser: Can't find sequence for " + - headers.elementAt(i)); - } + super(inFile, type); } - } - - public static int checkSum(String seq) + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public String print() { - - int check = 0; - - String sequence = seq.toUpperCase(); - - for (int i = 0; i < sequence.length(); i++) - { - if (i < sequence.length()) - { - int value = sequence.charAt(i); - if (value != -1) - { - check += (i % 57 + 1) * value; - } - } - - } - - return check % 10000; + return print(getSeqsAsArray()); } - public static String print(SequenceI[] s) + + public String print(SequenceI[] s) { StringBuffer out = new StringBuffer("PileUp\n\n"); @@ -217,8 +100,7 @@ public class PileUpfile while ( (i < s.length) && (s[i] != null)) { String seq = s[i].getSequence(); - out.append(" Name: " + s[i].getName() + - "/" + s[i].getStart() + "-" + s[i].getEnd() + + out.append(" Name: " + printId(s[i]) + " oo Len: " + s[i].getSequence().length() + " Check: " + checksums[i] + " Weight: 1.00\n"); @@ -259,11 +141,9 @@ public class PileUpfile while ( (j < s.length) && (s[j] != null)) { - String name = s[j].getName(); - // out.append(new Format("%-" + maxid + "s").form(name) + " "); + String name = printId(s[j]); - out.append(new Format("%-" + maxid + "s").form(name - + "/" + s[j].getStart() + "-" + s[j].getEnd()) + " "); + out.append(new Format("%-" + maxid + "s").form(name + " ")); for (int k = 0; k < 5; k++) { @@ -309,9 +189,4 @@ public class PileUpfile return out.toString(); } - - public String print() - { - return print(getSeqsAsArray()); - } } diff --git a/src/jalview/io/SequenceFeatureFetcher.java b/src/jalview/io/SequenceFeatureFetcher.java index 94713ea..520ba03 100755 --- a/src/jalview/io/SequenceFeatureFetcher.java +++ b/src/jalview/io/SequenceFeatureFetcher.java @@ -26,6 +26,12 @@ import java.io.*; import java.util.*; +import org.exolab.castor.mapping.Mapping; + +import org.exolab.castor.xml.*; +import jalview.analysis.AlignSeq; + + /** * DOCUMENT ME! @@ -35,527 +41,207 @@ import java.util.*; */ public class SequenceFeatureFetcher implements Runnable { - AlignmentI align; - AlignmentPanel ap; - ArrayList unknownSequences; - CutAndPasteTransfer output = new CutAndPasteTransfer(); - StringBuffer sbuffer = new StringBuffer(); - - /** - * Creates a new SequenceFeatureFetcher object. - * - * @param align DOCUMENT ME! - * @param ap DOCUMENT ME! - */ - public SequenceFeatureFetcher(AlignmentI align, AlignmentPanel ap) + + AlignmentI align; + AlignmentPanel ap; + ArrayList unknownSequences; + CutAndPasteTransfer output = new CutAndPasteTransfer(); + StringBuffer sbuffer = new StringBuffer(); + + Vector localCache = new Vector(); + + Vector getUniprotEntries(File file) + { + + UniprotFile uni = new UniprotFile(); + try { - unknownSequences = new ArrayList(); - this.align = align; - this.ap = ap; + // 1. Load the mapping information from the file + Mapping map = new Mapping(uni.getClass().getClassLoader()); + java.net.URL url = uni.getClass().getResource("/uniprot_mapping.xml"); + map.loadMapping(url); + + // 2. Unmarshal the data + Unmarshaller unmar = new Unmarshaller(); + unmar.setIgnoreExtraElements(true); + unmar.setMapping(map); + uni = (UniprotFile) unmar.unmarshal(new FileReader(file)); + localCache.addAll( uni.getUniprotEntries() ); + + // 3. marshal the data with the total price back and print the XML in the console + // Marshaller marshaller = new Marshaller( + // new FileWriter(jalview.bin.Cache.getProperty("UNIPROT_CACHE")) + // ); + // marshaller.setMapping(map); + // marshaller.marshal(uni); - Thread thread = new Thread(this); - thread.start(); } - - /** - * DOCUMENT ME! - */ - public void run() + catch (Exception e) { - RandomAccessFile out = null; + System.out.println("Error getUniprotEntries() "+e); + // e.printStackTrace(); + // if(!updateLocalCache) + // file.delete(); - try - { - String cache = System.getProperty("user.home") + - "/.jalview.uniprot.xml"; - - File test = new File(cache); - - if (!test.exists()) - { - out = new RandomAccessFile(cache, "rw"); - out.writeBytes("\n"); - out.writeBytes("\n"); - } - else - { - out = new RandomAccessFile(cache, "rw"); - - // open exisiting cache and remove from the end - long lastLine = 0; - String data; - - while ((data = out.readLine()) != null) - { - if (data.indexOf("") > -1) - { - lastLine = out.getFilePointer(); - } - } - - out.seek(lastLine); - } - - int seqIndex = 0; - Vector sequences = align.getSequences(); - - while (seqIndex < sequences.size()) - { - ArrayList ids = new ArrayList(); - - for (int i = 0; (seqIndex < sequences.size()) && (i < 50); - seqIndex++, i++) - { - SequenceI sequence = (SequenceI) sequences.get(seqIndex); - ids.add(sequence.getName()); - } - - tryLocalCacheFirst(ids, align); - - if (ids.size() > 0) - { - StringBuffer remainingIds = new StringBuffer("uniprot:"); - - for (int i = 0; i < ids.size(); i++) - remainingIds.append(ids.get(i) + ";"); - - EBIFetchClient ebi = new EBIFetchClient(); - String[] result = ebi.fetchData(remainingIds.toString(), - "xml", null); - - if (result != null) - { - ReadUniprotFile(result, out, align); - } - } - } - - if (out != null) - { - out.writeBytes("\n"); - out.close(); - } - } - catch (Exception ex) - { - ex.printStackTrace(); - } + } + return uni.getUniprotEntries(); + } + + /** + * Creates a new SequenceFeatureFetcher object. + * + * @param align DOCUMENT ME! + * @param ap DOCUMENT ME! + */ + public SequenceFeatureFetcher(AlignmentI align, AlignmentPanel ap) + { + unknownSequences = new ArrayList(); + this.align = align; + this.ap = ap; + + Thread thread = new Thread(this); + thread.start(); + } + + /** + * DOCUMENT ME! + */ + public void run() + { + try + { + int seqIndex = 0; + Vector sequences = align.getSequences(); - findMissingIds(align); + while (seqIndex < sequences.size()) + { + Vector ids = new Vector(); - if (sbuffer.length() > 0) + for (int i = 0; (seqIndex < sequences.size()) && (i < 50); + seqIndex++, i++) { - output.setText( - "Your sequences have been matched to Uniprot. Some of the ids have been\n" + - "altered, most likely the start/end residue will have been updated.\n" + - "Save your alignment to maintain the updated id.\n\n" + - sbuffer.toString()); - Desktop.addInternalFrame(output, "Sequence names updated ", 600, 300); + SequenceI sequence = (SequenceI) sequences.get(seqIndex); + ids.add(sequence.getName()); + unknownSequences.add(sequence.getName()); } - if (unknownSequences.size() > 0) + /////////////////////////////////// + ///READ FROM EBI + if (ids.size() > 0) { - //ignore for now!!!!!!!!!! - // WSWUBlastClient blastClient = new WSWUBlastClient(align, unknownSequences); + StringBuffer remainingIds = new StringBuffer("uniprot:"); + for (int i = 0; i < ids.size(); i++) + { + remainingIds.append(ids.get(i) + ";"); + } + EBIFetchClient ebi = new EBIFetchClient(); + File file = ebi.fetchDataAsFile(remainingIds.toString(), + "xml", null); + + + if (file != null) + { + ReadUniprotFile(file, align, ids); + } } - - jalview.gui.PaintRefresher.Refresh(null, align); + } } - - /** - * DOCUMENT ME! - * - * @param result DOCUMENT ME! - * @param out DOCUMENT ME! - * @param align DOCUMENT ME! - */ - void ReadUniprotFile(String[] result, RandomAccessFile out, AlignmentI align) + catch (Exception ex) { - SequenceI sequence = null; - Vector features = null; - String type; - String description; - String status; - String start; - String end; - String pdb = null; - - for (int r = 0; r < result.length; r++) - { - if ((sequence == null) && (result[r].indexOf("") > -1)) - { - long filePointer = 0; - - if (out != null) - { - try - { - filePointer = out.getFilePointer(); - out.writeBytes("\n"); - } - catch (Exception ex) - { - } - } - - String seqName = parseElement(result[r], "", out); - sequence = align.findName(seqName); - - if (sequence == null) - { - sequence = align.findName(seqName.substring(0, - seqName.indexOf('_'))); - - if (sequence != null) - { - sbuffer.append("changing " + sequence.getName() + - " to " + seqName + "\n"); - sequence.setName(seqName); - } - } - - if (sequence == null) - { - sbuffer.append("UNIPROT updated suggestion is " + - result[r] + "\n"); - sequence = align.findName(result[r]); - - // this entry has been suggested by ebi. - // doesn't match id in alignment file - try - { - out.setLength(filePointer); - } - catch (Exception ex) - { - } - - // now skip to next entry - while (result[r].indexOf("") == -1) - r++; - } - - features = new Vector(); - type = ""; - start = "0"; - end = "0"; - description = ""; - status = ""; - pdb = ""; - } - - if (sequence == null) - { - continue; - } - - if (result[r].indexOf(" -1) - { - pdb = parseValue(result[r], "value=", out); - sequence.setPDBId(pdb); - } - - if (result[r].indexOf("feature type") > -1) - { - type = parseValue(result[r], "type=", out); - description = parseValue(result[r], "description=", null); - status = parseValue(result[r], "status=", null); - - while (result[r].indexOf("position") == -1) - { - r++; // - } - - // r++; - if (result[r].indexOf("begin") > -1) - { - start = parseValue(result[r], "position=", out); - end = parseValue(result[++r], "position=", out); - } - else - { - start = parseValue(result[r], "position=", out); - end = parseValue(result[r], "position=", null); - } - - int sstart = Integer.parseInt(start); - int eend = Integer.parseInt(end); - - if (out != null) - { - try - { - out.writeBytes("\n"); - } - catch (Exception ex) - { - } - } - - SequenceFeature sf = new SequenceFeature(type, sstart, eend, - description, status); - features.add(sf); - } - - if (result[r].indexOf("") == -1) - { - seqString.append(result[r]); - - if (out != null) - { - try - { - out.writeBytes(result[r] + "\n"); - } - catch (Exception ex) - { - } - } - } - - if (out != null) - { - try - { - out.writeBytes(result[r] + "\n"); - } - catch (Exception ex) - { - } - } - - StringBuffer nonGapped = new StringBuffer(); - - for (int i = 0; i < sequence.getSequence().length(); i++) - { - if (!jalview.util.Comparison.isGap(sequence.getCharAt(i))) - { - nonGapped.append(sequence.getCharAt(i)); - } - } - - int absStart = seqString.toString().indexOf(nonGapped.toString()); - - if (absStart == -1) - { - unknownSequences.add(sequence.getName()); - features = null; - sbuffer.append(sequence.getName() + - " SEQUENCE NOT %100 MATCH \n"); - - continue; - } - - int absEnd = absStart + nonGapped.toString().length(); - absStart += 1; - - if ((absStart != sequence.getStart()) || - (absEnd != sequence.getEnd())) - { - sbuffer.append("Updated: " + sequence.getName() + " " + - sequence.getStart() + "/" + sequence.getEnd() + - " to " + absStart + "/" + absEnd + "\n"); - } - - sequence.setStart(absStart); - sequence.setEnd(absEnd); - } - - if (result[r].indexOf("") > -1) - { - if (features != null) - { - sequence.setSequenceFeatures(features); - } - - features = null; - sequence = null; - - if (out != null) - { - try - { - out.writeBytes("\n"); - } - catch (Exception ex) - { - } - } - } - } + ex.printStackTrace(); } - /** - * DOCUMENT ME! - * - * @param align DOCUMENT ME! - */ - void findMissingIds(AlignmentI align) + if (sbuffer.length() > 0) { - String data; - ArrayList cachedIds = new ArrayList(); - - try - { - if(jalview.bin.Cache.getProperty("UNIPROT_CACHE")==null) - return; - - BufferedReader in = new BufferedReader(new FileReader( - jalview.bin.Cache.getProperty("UNIPROT_CACHE"))); - - while ((data = in.readLine()) != null) - { - if (data.indexOf("name") > -1) - { - String name = parseElement(data, "", null); - cachedIds.add(name); - } - } - } - catch (Exception ex) - { - ex.printStackTrace(); - } - - for (int i = 0; i < align.getHeight(); i++) - if (!cachedIds.contains(align.getSequenceAt(i).getName())) - { - unknownSequences.add(align.getSequenceAt(i).getName()); - } + output.setText( + "Your sequences have been matched to Uniprot. Some of the ids have been\n" + + "altered, most likely the start/end residue will have been updated.\n" + + "Save your alignment to maintain the updated id.\n\n" + + sbuffer.toString()); + Desktop.addInternalFrame(output, "Sequence names updated ", 600, 300); } - /** - * DOCUMENT ME! - * - * @param ids DOCUMENT ME! - * @param align DOCUMENT ME! - */ - void tryLocalCacheFirst(ArrayList ids, AlignmentI align) + if (unknownSequences.size() > 0) { - ArrayList cacheData = new ArrayList(); - - try - { - if(jalview.bin.Cache.getProperty("UNIPROT_CACHE")==null) - return; - - BufferedReader in = new BufferedReader(new FileReader( - jalview.bin.Cache.getProperty("UNIPROT_CACHE"))); - - // read through cache file, if the cache has sequences we're looking for - // add the lines to a new String array, Readthis new array and - // make sure we remove the ids from the list to retrieve from EBI - String data; - - while ((data = in.readLine()) != null) - { - if (data.indexOf("name") > -1) - { - String name = parseElement(data, "", null); - - if (ids.contains(name)) - { - cacheData.add(""); - cacheData.add(data); - - while (data.indexOf("") == -1) - { - data = in.readLine(); - cacheData.add(data); - } - - cacheData.add(data); - - ids.remove(name); - } - } - } - } - catch (Exception ex) - { - ex.printStackTrace(); - } - - String[] localData = new String[cacheData.size()]; - cacheData.toArray(localData); - - if ((localData != null) && (localData.length > 0)) - { - ReadUniprotFile(localData, null, align); - } + new WSWUBlastClient(ap, align, unknownSequences); } + else + ((Alignment)align).featuresAdded = true; - /** - * DOCUMENT ME! - * - * @param line DOCUMENT ME! - * @param tag DOCUMENT ME! - * @param out DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - String parseValue(String line, String tag, RandomAccessFile out) - { - if (out != null) - { - try - { - out.writeBytes(line + "\n"); - } - catch (Exception ex) - { - } - } - int index = line.indexOf(tag) + tag.length() + 1; + ap.repaint(); + } - if (index == tag.length()) - { - return ""; - } + /** + * DOCUMENT ME! + * + * @param result DOCUMENT ME! + * @param out DOCUMENT ME! + * @param align DOCUMENT ME! + */ + void ReadUniprotFile(File file, AlignmentI align, Vector ids) + { + if(!file.exists()) + return; - return line.substring(index, line.indexOf("\"", index + 1)); - } + SequenceI sequence = null; + // String pdb = null; - /** - * DOCUMENT ME! - * - * @param line DOCUMENT ME! - * @param tag DOCUMENT ME! - * @param out DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - String parseElement(String line, String tag, RandomAccessFile out) - { - if (out != null) - { - try - { - out.writeBytes(line + "\n"); - } - catch (Exception ex) - { - } - } - - int index = line.indexOf(tag) + tag.length(); + Vector entries = getUniprotEntries(file); - return line.substring(index, line.indexOf("0) + { + for(int db=0; db0) + { + AlignmentAnnotations[] an = alignment.getAlignmentAnnotations(); + + for (int j = 0; j < an.length; j++) + { + boolean topaliBreakpoint = false; + + AnnotationElement[] ae = an[j].getAnnotationElement(); + jalview.datamodel.Annotation[] anot = new jalview.datamodel.Annotation[jal. + getWidth()]; + + try{ + + for (int aa = 0; aa < ae.length; aa++) + { + String dc = ae[aa].getDisplayCharacter()==null ? "dc" : ae[aa].getDisplayCharacter(); + String desc = ae[aa].getDescription()==null ? "desc" : ae[aa].getDescription(); + String ss = ae[aa].getSecondaryStructure()==null ? "ss" : ae[aa].getSecondaryStructure(); + float value = ae[aa].getValue(); + + if(an[j].getGraph()) + { + dc = value+""; + desc = value + ""; + } + anot[ae[aa].getPosition()-1] = new jalview.datamodel. + Annotation(dc,desc,ss.charAt(0),value); + + if(desc.equals("TOPALi Partition Breakpoint")) + topaliBreakpoint = true; + + } + }catch(Exception ex) + { + ex.printStackTrace(); + System.out.println("problem parsing annotations\n"+ex);} + + jalview.datamodel.AlignmentAnnotation jaa = null; + + if (an[j].getGraph()) + { + jaa = new jalview.datamodel.AlignmentAnnotation(an[j].getLabel(), + an[j].getDescription(), anot, 0, 0, 1); + } + else + { + String label = an[j].getLabel(); + if(topaliBreakpoint) + label = "TOPALi Partition Breakpoint"; + jaa = new jalview.datamodel.AlignmentAnnotation(label, + an[j].getDescription(), anot); + } + + jal.addAnnotation(jaa); + } + } + ///////////////////////////////// + + AlignFrame alignFrame = new AlignFrame(jal); + jalview.gui.Desktop.addInternalFrame(alignFrame, "VAMSAS LOAD", + AlignFrame.NEW_WINDOW_WIDTH, + AlignFrame.NEW_WINDOW_HEIGHT); + + //LOAD TREES + /////////////////////////////////////// + if (alignment.getTreeCount() > 0) + { + for (int t = 0; t < alignment.getTreeCount(); t++) + { + Tree tree = alignment.getTree(t); + + alignFrame.ShowNewickTree( + new jalview.io.NewickFile(tree.getNewick(0).getContent()), + tree.getNewick(0).getTitle(), + 600, 500, + t * 20 + 50, t * 20 + 50); + } + } + + + in.close(); + jin.close(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + + } + + + + Provenance getVamsasProvenance(jalview.datamodel.Provenance jprov) + { + jalview.datamodel.ProvenanceEntry [] entries = null; + + + Provenance prov = new Provenance(); + org.exolab.castor.types.Date date = new org.exolab.castor.types.Date( + new java.util.Date()); + Entry provEntry; + + if(jprov!=null) + { + entries = jprov.getEntries(); + for (int i = 0; i < entries.length; i++) + { + provEntry = new Entry(); + try + { + date = new org.exolab.castor.types.Date(entries[i].getDate()); + } + catch (Exception ex) + { + ex.printStackTrace(); + + date = new org.exolab.castor.types.Date(entries[i].getDate()); + } + provEntry.setDate(date); + provEntry.setUser(entries[i].getUser()); + provEntry.setAction(entries[i].getAction()); + prov.addEntry(provEntry); + } + } + else + { + provEntry = new Entry(); + provEntry.setDate(date); + provEntry.setUser(System.getProperty("user.name")); + provEntry.setAction("Jalview"); + prov.addEntry(provEntry); + } + + return prov; + } + + jalview.datamodel.Provenance getJalviewProvenance(Provenance prov) + { + + jalview.datamodel.Provenance jprov = new jalview.datamodel.Provenance(); + for (int i = 0; i < prov.getEntryCount(); i++) + { + jprov.addEntry( + prov.getEntry(i).getUser(), + prov.getEntry(i).getAction(), + prov.getEntry(i).getDate().toDate(), + prov.getEntry(i).getId() + ); + } + + return jprov; + } + + Provenance dummyProvenance() + { + Provenance prov = new Provenance(); + Entry entry = new Entry(); + entry.setAction("Jalview"); + entry.setDate(new org.exolab.castor.types.Date(new java.util.Date())); + entry.setUser(System.getProperty("user.name")); + prov.addEntry(entry); + return prov; + } + +} diff --git a/src/jalview/io/WSWUBlastClient.java b/src/jalview/io/WSWUBlastClient.java index c221d07..2e3ccfa 100755 --- a/src/jalview/io/WSWUBlastClient.java +++ b/src/jalview/io/WSWUBlastClient.java @@ -39,17 +39,22 @@ import javax.xml.namespace.QName; */ public class WSWUBlastClient { + AlignmentPanel ap; + AlignmentI al; CutAndPasteTransfer output = new CutAndPasteTransfer(); int jobsRunning = 0; + Hashtable suggestedIds = new Hashtable(); /** * Creates a new WSWUBlastClient object. * * @param al DOCUMENT ME! * @param ids DOCUMENT ME! */ - public WSWUBlastClient(AlignmentI al, ArrayList ids) + public WSWUBlastClient(AlignmentPanel ap, AlignmentI al, ArrayList ids) { + this.ap = ap; + this.al = al; output.setText( "To display sequence features an exact Uniprot id with 100% sequence identity match must be entered." + "\nIn order to display these features, try changing the names of your sequences to the ids suggested below."); @@ -61,6 +66,7 @@ public class WSWUBlastClient SequenceI sequence = al.findName(ids.get(i).toString()); StringBuffer nonGapped = new StringBuffer(); + for (int n = 0; n < sequence.getSequence().length(); n++) { if (!jalview.util.Comparison.isGap(sequence.getCharAt(n))) @@ -79,6 +85,7 @@ public class WSWUBlastClient thread.start(); } + /** * DOCUMENT ME! * @@ -97,32 +104,41 @@ public class WSWUBlastClient { data = st.nextToken(); - if (data.indexOf("database=\"uniprot\" id=") > -1) + if (data.indexOf(">UNIPROT") > -1) { - int index = data.indexOf("database=\"uniprot\" id=") + 23; - id2 = data.substring(index, data.indexOf("\"", index)); + int index = data.indexOf(">UNIPROT") + 9; + id2 = data.substring(index, data.indexOf(" ", index)); - while (data.indexOf("") == -1) + boolean identitiesFound = false; + while (!identitiesFound) { data = st.nextToken(); - if (data.indexOf("") > -1) + if (data.indexOf("Identities") > -1) { - int value = Integer.parseInt(data.substring(data.indexOf( - "") + 10, - data.indexOf(""))); + identitiesFound = true; + + int value = Integer.parseInt(data.substring(data.indexOf( + "(") + 1, + data.indexOf("%"))); if (value >= maxFound) { maxFound = value; buffer.append(" " + id2 + " " + value + "%; "); + suggestedIds.put(id1, id2); } } } } } - output.setText(output.getText() + buffer.toString()); + output.appendText(buffer.toString()); + } + + void updateIds() + { + } class ImageTwirler extends Thread @@ -163,6 +179,36 @@ public class WSWUBlastClient { } } + + if (jobsRunning == 0) + { + int reply = JOptionPane.showConfirmDialog( + Desktop.desktop, "Automatically update suggested ids?", + "Auto replace sequence ids", JOptionPane.YES_NO_OPTION); + + if (reply == JOptionPane.YES_OPTION) + { + Enumeration keys = suggestedIds.keys(); + while(keys.hasMoreElements()) + { + String oldid = keys.nextElement().toString(); + SequenceI sequence = al.findName(oldid); + sequence.setName( suggestedIds.get(oldid).toString() ); + + sequence = al.getDataset().findName(oldid); + Vector entries = sequence.getDBRef(); + DBRefEntry entry = (DBRefEntry) entries.elementAt(0); + sequence.addDBRef(new jalview.datamodel.DBRefEntry("UNIPROT", + "0", + entry.getAccessionId())); + + sequence.setName(suggestedIds.get(oldid).toString()); + + System.out.println("replace "+oldid+" with "+suggestedIds.get(oldid)); + } + } + ap.repaint(); + } } } @@ -175,6 +221,7 @@ public class WSWUBlastClient BlastThread(String id, String sequence) { + System.out.println("blasting for: "+id); this.sequence = sequence; seqid = id; } @@ -192,22 +239,21 @@ public class WSWUBlastClient "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast")); call.setOperationName(new QName("WSWUBlast", "polljob")); - String result = (String) call.invoke(new Object[] + Object object = (String) call.invoke(new Object[] { jobid, "xml" }); - if ((result.indexOf("JOB PENDING") == -1) && - (result.indexOf("JOB RUNNING") == -1)) + if(object instanceof String) { - parseResult(seqid, result); - jobComplete = true; - jobsRunning--; + parseResult(seqid, (String)object); + jobComplete = true; + jobsRunning--; } Thread.sleep(5000); - // System.out.println("WSWuBlastClient: I'm alive "+seqid+" "+jobid); // log.debug + System.out.println("WSWuBlastClient: I'm alive "+seqid+" "+jobid); // log.debug } catch (Exception ex) { @@ -224,8 +270,8 @@ public class WSWUBlastClient params.put("matrix", "pam10"); params.put("program", "blastp"); params.put("alignments", "5"); - params.put("outformat", "xml"); - params.put("searchtype", "1"); + params.put("type", "xml"); + params.put("async", "true"); byte[] seqbytes = sequence.getBytes(); @@ -236,14 +282,21 @@ public class WSWUBlastClient "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast")); call.setOperationName(new QName("WSWUBlast", "doWUBlast")); - String result = (String) call.invoke(new Object[] + Object object = call.invoke(new Object[] { params, seqbytes }); - jobid = result; - System.out.println( - "http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast JobId '" + - jobid + "'"); + + if(object instanceof byte[]) + jobid = new String( (byte[])object); + + else + { + jobComplete = true; + jobsRunning--; + parseResult(seqid, (String)object); + } + } catch (Exception exp) { diff --git a/src/jalview/jbappletgui/GAlignFrame.java b/src/jalview/jbappletgui/GAlignFrame.java index 7775b65..5123317 100755 --- a/src/jalview/jbappletgui/GAlignFrame.java +++ b/src/jalview/jbappletgui/GAlignFrame.java @@ -107,8 +107,8 @@ public class GAlignFrame extends Frame { MenuItem item; // dynamically fill save as menu with available formats - for (int i = 0; i < jalview.io.FormatAdapter.formats.size(); i++) { - item = new MenuItem((String) jalview.io.FormatAdapter.formats.elementAt( + for (int i = 0; i < jalview.io.AppletFormatAdapter.formats.size(); i++) { + item = new MenuItem((String) jalview.io.AppletFormatAdapter.formats.elementAt( i)); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { @@ -116,7 +116,7 @@ public class GAlignFrame extends Frame { } }); - item = new MenuItem((String) jalview.io.FormatAdapter.formats.elementAt( + item = new MenuItem((String) jalview.io.AppletFormatAdapter.formats.elementAt( i)); item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index ddb2bcd..de46e5a 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -113,6 +113,10 @@ public class GAlignFrame JMenu jMenu2 = new JMenu(); JMenuItem padGapsMenuitem = new JMenuItem(); protected ButtonGroup colours = new ButtonGroup(); + JMenuItem vamsasStore = new JMenuItem(); + protected JCheckBoxMenuItem showTranslation = new JCheckBoxMenuItem(); + protected JTabbedPane tabbedPane = new JTabbedPane(); + protected JMenuItem featureSettings = new JMenuItem(); public GAlignFrame() { @@ -906,6 +910,40 @@ public class GAlignFrame padGapsMenuitem_actionPerformed(e); } }); + vamsasStore.setText("VAMSAS store"); + vamsasStore.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + vamsasStore_actionPerformed(e); + } + }); + showTranslation.setText("Translate cDNA"); + showTranslation.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + showTranslation_actionPerformed(e); + } + }); + + tabbedPane.addChangeListener(new ChangeListener() + { + public void stateChanged(ChangeEvent ece) + { + + tabSelected(); + } + }); +// featureSettings.setEnabled(false); + featureSettings.setText("Feature Settings..."); + featureSettings.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + featureSettings_actionPerformed(e); + } + }); alignFrameMenuBar.add(fileMenu); alignFrameMenuBar.add(editMenu); alignFrameMenuBar.add(searchMenu); @@ -913,6 +951,7 @@ public class GAlignFrame alignFrameMenuBar.add(colourMenu); alignFrameMenuBar.add(calculateMenu); alignFrameMenuBar.add(webService); + fileMenu.add(vamsasStore); fileMenu.add(saveAlignmentMenu); fileMenu.add(jMenu2); fileMenu.add(outputTextboxMenu); @@ -953,7 +992,9 @@ public class GAlignFrame viewMenu.add(colourTextMenuItem); viewMenu.add(renderGapsMenuItem); viewMenu.add(annotationPanelMenuItem); + viewMenu.addSeparator(); viewMenu.add(sequenceFeatures); + viewMenu.add(featureSettings); viewMenu.addSeparator(); viewMenu.add(overviewMenuItem); colourMenu.add(applyToAllGroups); @@ -981,9 +1022,12 @@ public class GAlignFrame calculateMenu.addSeparator(); calculateMenu.add(pairwiseAlignmentMenuItem); calculateMenu.add(PCAMenuItem); + calculateMenu.addSeparator(); + calculateMenu.add(showTranslation); webServiceNoServices=new JMenuItem(""); webService.add(webServiceNoServices); this.getContentPane().add(statusBar, BorderLayout.SOUTH); + this.getContentPane().add(tabbedPane, java.awt.BorderLayout.CENTER); jMenu1.add(pasteNew); jMenu1.add(pasteThis); sort.add(sortIDMenuItem); @@ -1285,4 +1329,29 @@ public class GAlignFrame protected void ClustalRealign_actionPerformed(ActionEvent e) { } + + public void vamsasStore_actionPerformed(ActionEvent e) + { + + } + + public void vamsasLoad_actionPerformed(ActionEvent e) + { + + } + + public void showTranslation_actionPerformed(ActionEvent e) + { + + } + + public void tabSelected() + { + + } + + public void featureSettings_actionPerformed(ActionEvent e) + { + + } } diff --git a/src/jalview/jbgui/GDesktop.java b/src/jalview/jbgui/GDesktop.java index 65ef8dc..68a7c92 100755 --- a/src/jalview/jbgui/GDesktop.java +++ b/src/jalview/jbgui/GDesktop.java @@ -48,8 +48,9 @@ public class GDesktop extends JFrame JMenuItem saveState = new JMenuItem(); JMenuItem loadState = new JMenuItem(); JMenu jMenu1 = new JMenu(); + JMenuItem vamsasLoad = new JMenuItem(); - /** + /** * Creates a new GDesktop object. */ public GDesktop() @@ -158,7 +159,15 @@ public class GDesktop extends JFrame }); jMenu1.setMnemonic('I'); jMenu1.setText("Input Alignment"); - DesktopMenubar.add(FileMenu); + vamsasLoad.setText("Vamsas"); + vamsasLoad.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + vamsasLoad_actionPerformed(e); + } + }); + DesktopMenubar.add(FileMenu); DesktopMenubar.add(toolsMenu); DesktopMenubar.add(HelpMenu); DesktopMenubar.add(windowMenu); @@ -175,7 +184,8 @@ public class GDesktop extends JFrame jMenu1.add(inputLocalFileMenuItem); jMenu1.add(inputURLMenuItem); jMenu1.add(inputTextboxMenuItem); - } + jMenu1.add(vamsasLoad); + } /** * DOCUMENT ME! @@ -273,4 +283,9 @@ public class GDesktop extends JFrame public void loadJalviewAlign_actionPerformed(ActionEvent e) { } + + public void vamsasLoad_actionPerformed(ActionEvent e) + { + + } } diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index 50c4cf5..1896e06 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -79,6 +79,7 @@ public class GPreferences extends JPanel protected JCheckBox useProxy = new JCheckBox(); JPanel jPanel1 = new JPanel(); TitledBorder titledBorder1 = new TitledBorder("Proxy Server"); + TitledBorder titledBorder2 = new TitledBorder("File Output"); GridBagLayout gridBagLayout2 = new GridBagLayout(); GridBagLayout gridBagLayout1 = new GridBagLayout(); GridBagLayout gridBagLayout3 = new GridBagLayout(); @@ -90,6 +91,28 @@ public class GPreferences extends JPanel JPanel exportTab = new JPanel(); JLabel epsLabel = new JLabel(); protected JComboBox epsRendering = new JComboBox(); + JLabel jLabel1 = new JLabel(); + JLabel jLabel2 = new JLabel(); + protected JCheckBox pileupdb = new JCheckBox(); + protected JCheckBox fastadb = new JCheckBox(); + protected JCheckBox blcjv = new JCheckBox(); + protected JCheckBox pileupjv = new JCheckBox(); + protected JCheckBox msfdb = new JCheckBox(); + protected JCheckBox pfamdb = new JCheckBox(); + protected JCheckBox clustaljv = new JCheckBox(); + protected JCheckBox msfjv = new JCheckBox(); + protected JCheckBox blcdb = new JCheckBox(); + protected JCheckBox clustaldb = new JCheckBox(); + protected JCheckBox fastajv = new JCheckBox(); + protected JCheckBox pfamjv = new JCheckBox(); + JLabel jLabel10 = new JLabel(); + JLabel jLabel11 = new JLabel(); + FlowLayout flowLayout1 = new FlowLayout(); + protected JCheckBox pirdb = new JCheckBox(); + protected JCheckBox pirjv = new JCheckBox(); + JPanel jPanel11 = new JPanel(); + GridLayout gridLayout3 = new GridLayout(); + Font verdana11 = new java.awt.Font("Verdana", Font.PLAIN, 11); /** * Creates a new GPreferences object. */ @@ -130,36 +153,36 @@ public class GPreferences extends JPanel } }); quality.setEnabled(false); - quality.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + quality.setFont(verdana11); quality.setHorizontalAlignment(SwingConstants.RIGHT); quality.setHorizontalTextPosition(SwingConstants.LEFT); quality.setSelected(true); quality.setText("Quality"); visualTab.setBorder(new TitledBorder("Open new alignment")); visualTab.setLayout(null); - fullID.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + fullID.setFont(verdana11); fullID.setHorizontalAlignment(SwingConstants.RIGHT); fullID.setHorizontalTextPosition(SwingConstants.LEFT); fullID.setMargin(new Insets(4, 2, 2, 0)); fullID.setText("Full Sequence ID"); - fullScreen.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + fullScreen.setFont(verdana11); fullScreen.setHorizontalAlignment(SwingConstants.RIGHT); fullScreen.setHorizontalTextPosition(SwingConstants.LEFT); fullScreen.setMargin(new Insets(2, 2, 2, 0)); fullScreen.setText("Maximise Window"); conservation.setEnabled(false); - conservation.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + conservation.setFont(verdana11); conservation.setHorizontalAlignment(SwingConstants.RIGHT); conservation.setHorizontalTextPosition(SwingConstants.LEFT); conservation.setSelected(true); conservation.setText("Conservation"); identity.setEnabled(false); - identity.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + identity.setFont(verdana11); identity.setHorizontalAlignment(SwingConstants.RIGHT); identity.setHorizontalTextPosition(SwingConstants.LEFT); identity.setSelected(true); identity.setText("Consensus"); - annotations.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + annotations.setFont(verdana11); annotations.setHorizontalAlignment(SwingConstants.RIGHT); annotations.setHorizontalTextPosition(SwingConstants.LEFT); annotations.setMargin(new Insets(2, 4, 2, 0)); @@ -172,31 +195,31 @@ public class GPreferences extends JPanel annotations_actionPerformed(e); } }); - gapLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + gapLabel.setFont(verdana11); gapLabel.setHorizontalAlignment(SwingConstants.RIGHT); gapLabel.setText("Gap Symbol "); - colour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + colour.setFont(verdana11); colour.setBounds(new Rectangle(148, 171, 154, 21)); - colourLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + colourLabel.setFont(verdana11); colourLabel.setHorizontalAlignment(SwingConstants.RIGHT); colourLabel.setText("Colour "); - fontLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + fontLabel.setFont(verdana11); fontLabel.setHorizontalAlignment(SwingConstants.RIGHT); fontLabel.setText("Font "); - fontSizeCB.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + fontSizeCB.setFont(verdana11); fontSizeCB.setBounds(new Rectangle(317, 111, 49, 21)); - fontStyleCB.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + fontStyleCB.setFont(verdana11); fontStyleCB.setBounds(new Rectangle(365, 111, 70, 21)); - fontNameCB.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + fontNameCB.setFont(verdana11); fontNameCB.setBounds(new Rectangle(148, 111, 169, 21)); - gapSymbolCB.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + gapSymbolCB.setFont(verdana11); gapSymbolCB.setBounds(new Rectangle(148, 141, 67, 21)); startupCheckbox.setText("Open file"); - startupCheckbox.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + startupCheckbox.setFont(verdana11); startupCheckbox.setHorizontalAlignment(SwingConstants.RIGHT); startupCheckbox.setHorizontalTextPosition(SwingConstants.LEFT); startupCheckbox.setSelected(true); - startupFileTextfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + startupFileTextfield.setFont(verdana11); startupFileTextfield.setBounds(new Rectangle(148, 232, 302, 20)); startupFileTextfield.addMouseListener(new MouseAdapter() { @@ -212,16 +235,16 @@ public class GPreferences extends JPanel connectTab.setLayout(gridBagLayout3); serverLabel.setText("Address"); serverLabel.setHorizontalAlignment(SwingConstants.RIGHT); - serverLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); - proxyServerTB.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); - proxyPortTB.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); - portLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + serverLabel.setFont(verdana11); + proxyServerTB.setFont(verdana11); + proxyPortTB.setFont(verdana11); + portLabel.setFont(verdana11); portLabel.setHorizontalAlignment(SwingConstants.RIGHT); portLabel.setText("Port"); browserLabel.setFont(new java.awt.Font("SansSerif", 0, 11)); browserLabel.setHorizontalAlignment(SwingConstants.TRAILING); browserLabel.setText("Default Browser (Unix)"); - defaultBrowser.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + defaultBrowser.setFont(verdana11); defaultBrowser.setText(""); newLink.setText("New"); newLink.addActionListener(new java.awt.event.ActionListener() { @@ -268,7 +291,7 @@ public class GPreferences extends JPanel linkNameList.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11)); linkNameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); linkPanel2.setLayout(borderLayout3); - linkURLList.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + linkURLList.setFont(verdana11); linkURLList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); defaultBrowser.addMouseListener(new MouseAdapter() @@ -281,7 +304,7 @@ public class GPreferences extends JPanel } } }); - useProxy.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + useProxy.setFont(verdana11); useProxy.setHorizontalAlignment(SwingConstants.RIGHT); useProxy.setHorizontalTextPosition(SwingConstants.LEADING); useProxy.setText("Use a proxy server"); @@ -294,9 +317,9 @@ public class GPreferences extends JPanel }); jPanel1.setBorder(titledBorder1); jPanel1.setLayout(gridBagLayout1); - sortby.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + sortby.setFont(verdana11); sortby.setBounds(new Rectangle(148, 200, 302, 21)); - sortLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + sortLabel.setFont(verdana11); sortLabel.setHorizontalAlignment(SwingConstants.RIGHT); sortLabel.setText("Sort by "); jPanel2.setBounds(new Rectangle(7, 17, 138, 242)); @@ -304,12 +327,75 @@ public class GPreferences extends JPanel gridLayout2.setRows(8); jPanel3.setBounds(new Rectangle(147, 46, 274, 26)); exportTab.setLayout(null); - epsLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + epsLabel.setFont(verdana11); epsLabel.setHorizontalAlignment(SwingConstants.RIGHT); epsLabel.setText("EPS Rendering Style"); - epsLabel.setBounds(new Rectangle(3, 47, 134, 21)); - epsRendering.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); - epsRendering.setBounds(new Rectangle(145, 47, 286, 21)); + epsLabel.setBounds(new Rectangle(9, 31, 140, 24)); + epsRendering.setFont(verdana11); + epsRendering.setBounds(new Rectangle(154, 34, 187, 21)); + jLabel1.setFont(verdana11); + jLabel1.setHorizontalAlignment(SwingConstants.CENTER); + jLabel1.setText("/start-end suffix"); + jLabel2.setFont(verdana11); + jLabel2.setHorizontalAlignment(SwingConstants.RIGHT); + jLabel2.setHorizontalTextPosition(SwingConstants.RIGHT); + jLabel2.setText("Database ref prefix"); + jLabel1.setFont(verdana11); + jLabel2.setFont(verdana11); + fastajv.setFont(verdana11); + fastajv.setHorizontalAlignment(SwingConstants.CENTER); + jLabel10.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11)); + jLabel10.setHorizontalAlignment(SwingConstants.RIGHT); + jLabel10.setText("(Uniprot|P02055)"); + jLabel11.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11)); + jLabel11.setHorizontalAlignment(SwingConstants.CENTER); + jLabel11.setText("(/15-380)"); + clustaldb.setFont(verdana11); + clustaldb.setHorizontalAlignment(SwingConstants.RIGHT); + clustaldb.setHorizontalTextPosition(SwingConstants.LEFT); + clustaldb.setText("Clustal "); + blcdb.setFont(verdana11); + blcdb.setHorizontalAlignment(SwingConstants.RIGHT); + blcdb.setHorizontalTextPosition(SwingConstants.LEFT); + blcdb.setText("BLC "); + fastadb.setFont(verdana11); + fastadb.setHorizontalAlignment(SwingConstants.RIGHT); + fastadb.setHorizontalTextPosition(SwingConstants.LEFT); + fastadb.setText("Fasta "); + msfdb.setFont(verdana11); + msfdb.setHorizontalTextPosition(SwingConstants.LEFT); + msfdb.setHorizontalAlignment(SwingConstants.RIGHT); + msfdb.setText("MSF "); + pfamdb.setFont(verdana11); + pfamdb.setHorizontalAlignment(SwingConstants.RIGHT); + pfamdb.setHorizontalTextPosition(SwingConstants.LEFT); + pfamdb.setText("PFAM "); + pileupdb.setFont(verdana11); + pileupdb.setHorizontalAlignment(SwingConstants.RIGHT); + pileupdb.setHorizontalTextPosition(SwingConstants.LEFT); + pileupdb.setText("Pileup "); + msfjv.setFont(verdana11); + msfjv.setHorizontalAlignment(SwingConstants.CENTER); + pirdb.setFont(verdana11); + pirdb.setHorizontalAlignment(SwingConstants.RIGHT); + pirdb.setHorizontalTextPosition(SwingConstants.LEFT); + pirdb.setText("PIR "); + jPanel11.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + jPanel11.setBorder(titledBorder2); + jPanel11.setBounds(new Rectangle(18, 72, 325, 182)); + jPanel11.setLayout(gridLayout3); + gridLayout3.setColumns(2); + gridLayout3.setRows(9); + blcjv.setFont(verdana11); + blcjv.setHorizontalAlignment(SwingConstants.CENTER); + clustaljv.setFont(verdana11); + clustaljv.setHorizontalAlignment(SwingConstants.CENTER); + pfamjv.setFont(verdana11); + pfamjv.setHorizontalAlignment(SwingConstants.CENTER); + pileupjv.setFont(verdana11); + pileupjv.setHorizontalAlignment(SwingConstants.CENTER); + pirjv.setFont(verdana11); + pirjv.setHorizontalAlignment(SwingConstants.CENTER); jPanel2.add(fullScreen); jPanel2.add(annotations); jPanel2.add(fullID); @@ -370,8 +456,6 @@ public class GPreferences extends JPanel , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(15, 0, 0, 15), 307, 1)); - exportTab.add(epsLabel); - exportTab.add(epsRendering); jPanel1.add(useProxy, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0 , GridBagConstraints.WEST, @@ -383,8 +467,29 @@ public class GPreferences extends JPanel gapSymbolCB.setRenderer(dlcr); tabbedPane.add(visualTab, "Visual"); - tabbedPane.add(connectTab, "Connections"); - tabbedPane.add(exportTab, "Export"); + tabbedPane.add(connectTab,"Connections"); + tabbedPane.add(exportTab, "File"); + jPanel11.add(jLabel2); + jPanel11.add(jLabel1); + jPanel11.add(jLabel10); + jPanel11.add(jLabel11); + jPanel11.add(blcdb); + jPanel11.add(blcjv); + jPanel11.add(clustaldb); + jPanel11.add(clustaljv); + jPanel11.add(fastadb); + jPanel11.add(fastajv); + jPanel11.add(msfdb); + jPanel11.add(msfjv); + jPanel11.add(pfamdb); + jPanel11.add(pfamjv); + jPanel11.add(pileupdb); + jPanel11.add(pileupjv); + jPanel11.add(pirdb); + jPanel11.add(pirjv); + exportTab.add(epsLabel); + exportTab.add(epsRendering); + exportTab.add(jPanel11); } /** diff --git a/src/jalview/schemes/ResidueProperties.java b/src/jalview/schemes/ResidueProperties.java index fbaab81..25707ea 100755 --- a/src/jalview/schemes/ResidueProperties.java +++ b/src/jalview/schemes/ResidueProperties.java @@ -1233,7 +1233,7 @@ public class ResidueProperties String key = (String) e.nextElement(); Vector tmp = (Vector) codonHash.get(key); - if (tmp.contains(codon)) + if (tmp.contains(codon.toUpperCase())) { return key; } diff --git a/src/jalview/util/Comparison.java b/src/jalview/util/Comparison.java index 9a86696..e48c0ca 100755 --- a/src/jalview/util/Comparison.java +++ b/src/jalview/util/Comparison.java @@ -29,215 +29,246 @@ import jalview.datamodel.*; */ public class Comparison { - /** DOCUMENT ME!! */ - public static String GapChars = " .-"; - - /** - * DOCUMENT ME! - * - * @param ii DOCUMENT ME! - * @param jj DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public static float compare(SequenceI ii, SequenceI jj) + /** DOCUMENT ME!! */ + public static String GapChars = " .-"; + + /** + * DOCUMENT ME! + * + * @param ii DOCUMENT ME! + * @param jj DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public static float compare(SequenceI ii, SequenceI jj) + { + return Comparison.compare(ii, jj, 0, ii.getLength() - 1); + } + + /** + * this was supposed to be an ungapped pid calculation + * @param ii SequenceI + * @param jj SequenceI + * @param start int + * @param end int + * @return float + */ + public static float compare(SequenceI ii, SequenceI jj, int start, int end) + { + String si = ii.getSequence(); + String sj = jj.getSequence(); + + int ilen = si.length() - 1; + int jlen = sj.length() - 1; + + while (jalview.util.Comparison.isGap(si.charAt(start + ilen))) { - return Comparison.compare(ii, jj, 0, ii.getLength() - 1); + ilen--; } - /** - * this was supposed to be an ungapped pid calculation - * @param ii SequenceI - * @param jj SequenceI - * @param start int - * @param end int - * @return float - */ - public static float compare(SequenceI ii, SequenceI jj, int start, int end) + while (jalview.util.Comparison.isGap(sj.charAt(start + jlen))) { - String si = ii.getSequence(); - String sj = jj.getSequence(); + jlen--; + } - int ilen = si.length() - 1; - int jlen = sj.length() - 1; + int count = 0; + int match = 0; + float pid = -1; - while (jalview.util.Comparison.isGap(si.charAt(start + ilen))) - { - ilen--; - } - - while (jalview.util.Comparison.isGap(sj.charAt(start + jlen))) + if (ilen > jlen) + { + for (int j = 0; j < jlen; j++) + { + if (si.substring(start + j, start + j + 1).equals(sj.substring(start + + j, start + j + 1))) { - jlen--; + match++; } - int count = 0; - int match = 0; - float pid = -1; + count++; + } - if (ilen > jlen) - { - for (int j = 0; j < jlen; j++) - { - if (si.substring(start + j, start + j + 1).equals(sj.substring(start + - j, start + j + 1))) - { - match++; - } - - count++; - } - - pid = (float) match / (float) ilen * 100; - } - else + pid = (float) match / (float) ilen * 100; + } + else + { + for (int j = 0; j < jlen; j++) + { + if (si.substring(start + j, start + j + 1).equals(sj.substring(start + + j, start + j + 1))) { - for (int j = 0; j < jlen; j++) - { - if (si.substring(start + j, start + j + 1).equals(sj.substring(start + - j, start + j + 1))) - { - match++; - } - - count++; - } - - pid = (float) match / (float) jlen * 100; + match++; } - return pid; + count++; + } + + pid = (float) match / (float) jlen * 100; } - /** - * this is a gapped PID calculation - * - * @param s1 SequenceI - * @param s2 SequenceI - * @return float - */ - public static float PID(SequenceI s1, SequenceI s2) + return pid; + } + + /** + * this is a gapped PID calculation + * + * @param s1 SequenceI + * @param s2 SequenceI + * @return float + */ + public static float PID(SequenceI s1, SequenceI s2) + { + int len; + + if (s1.getSequence().length() > s2.getSequence().length()) { - int len; + len = s1.getSequence().length(); + } + else + { + len = s2.getSequence().length(); + } - if (s1.getSequence().length() > s2.getSequence().length()) - { - len = s1.getSequence().length(); - } - else + int bad = 0; + + for (int i = 0; i < len; i++) + { + char chr1; + char chr2; + + if (i < s1.getSequence().length()) + { + chr1 = Character.toUpperCase(s1.getSequence().charAt(i)); + } + else + { + chr1 = '.'; + } + + if (i < s2.getSequence().length()) + { + chr2 = Character.toUpperCase(s2.getSequence().charAt(i)); + } + else + { + chr2 = '.'; + } + + if (! (jalview.util.Comparison.isGap(chr1)) && + ! (jalview.util.Comparison.isGap(chr2))) + { + if (chr1 != chr2) { - len = s2.getSequence().length(); + bad++; } + } + } - int bad = 0; + return ( (float) 100 * (len - bad)) / len; + } - for (int i = 0; i < len; i++) - { - char chr1; - char chr2; - - if (i < s1.getSequence().length()) - { - chr1 = Character.toUpperCase(s1.getSequence().charAt(i)); - } - else - { - chr1 = '.'; - } - - if (i < s2.getSequence().length()) - { - chr2 = Character.toUpperCase(s2.getSequence().charAt(i)); - } - else - { - chr2 = '.'; - } - - if (!(jalview.util.Comparison.isGap(chr1)) && - !(jalview.util.Comparison.isGap(chr2))) - { - if (chr1 != chr2) - { - bad++; - } - } - } + // Another pid with region specification + public static float PID(SequenceI s1, SequenceI s2, int start, int end) + { + int len; - return ((float) 100 * (len - bad)) / len; + if (s1.getSequence().length() > s2.getSequence().length()) + { + len = s1.getSequence().length(); + } + else + { + len = s2.getSequence().length(); } - // Another pid with region specification - public static float PID(SequenceI s1, SequenceI s2, int start, int end) + if (end < len) { - int len; + len = end; + } - if (s1.getSequence().length() > s2.getSequence().length()) - { - len = s1.getSequence().length(); - } - else - { - len = s2.getSequence().length(); - } + if (len < start) + { + start = len - 1; // we just use a single residue for the difference + } - if (end < len) - { - len = end; - } + int bad = 0; - if (len < start) + for (int i = start; i < len; i++) + { + char chr1; + char chr2; + + if (i < s1.getSequence().length()) + { + chr1 = Character.toUpperCase(s1.getSequence().charAt(i)); + } + else + { + chr1 = '.'; + } + + if (i < s2.getSequence().length()) + { + chr2 = Character.toUpperCase(s2.getSequence().charAt(i)); + } + else + { + chr2 = '.'; + } + + if (! (jalview.util.Comparison.isGap(chr1)) && + ! (jalview.util.Comparison.isGap(chr2))) + { + if (chr1 != chr2) { - start = len - 1; // we just use a single residue for the difference + bad++; } + } + } - int bad = 0; - - for (int i = start; i < len; i++) + return ( (float) 100 * (len - bad)) / len; + } + + /** + * DOCUMENT ME! + * + * @param c DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public static boolean isGap(char c) + { + return (c == '-' || c == '.' || c == ' ') ? true : false; + } + + public static boolean isNucleotide(SequenceI [] seqs) + { + int i = 0, iSize = seqs.length, j, jSize; + float nt = 0, aa = 0; + char c; + while (i < iSize) + { + jSize = seqs[i].getLength(); + for (j = 0; j < jSize; j++) + { + c = seqs[i].getCharAt(j); + if ('a' <= c && c <= 'z') + c -= ('a' - 'A'); + + if (c == 'A' || c == 'G' || c == 'C' || c == 'T' || c == 'U') + nt++; + else if (!jalview.util.Comparison.isGap( seqs[i].getCharAt(j))) { - char chr1; - char chr2; - - if (i < s1.getSequence().length()) - { - chr1 = Character.toUpperCase(s1.getSequence().charAt(i)); - } - else - { - chr1 = '.'; - } - - if (i < s2.getSequence().length()) - { - chr2 = Character.toUpperCase(s2.getSequence().charAt(i)); - } - else - { - chr2 = '.'; - } - - if (!(jalview.util.Comparison.isGap(chr1)) && - !(jalview.util.Comparison.isGap(chr2))) - { - if (chr1 != chr2) - { - bad++; - } - } + aa++; } - - return ((float) 100 * (len - bad)) / len; + } + i++; } - /** - * DOCUMENT ME! - * - * @param c DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public static boolean isGap(char c) - { - return ( c=='-' || c=='.' || c==' ' ) ? true : false; - } + if ( (nt / (nt + aa)) > 0.85f) + return true; + else + return false; + + } } diff --git a/src/jalview/ws/JPredClient.java b/src/jalview/ws/JPredClient.java index fdf0cec..4cb8aee 100755 --- a/src/jalview/ws/JPredClient.java +++ b/src/jalview/ws/JPredClient.java @@ -173,7 +173,8 @@ public class JPredClient msf[0].getSequence())); this.msa = new vamsas.objects.simple.Msfalignment(); - msa.setMsf(jalview.io.PileUpfile.print(msf)); + jalview.io.PileUpfile pileup = new jalview.io.PileUpfile(); + msa.setMsf(pileup.print(msf)); } public void run() diff --git a/src/vamsas/objects/simple/Object.java b/src/vamsas/objects/simple/Object.java index ae1b515..d8cc069 100755 --- a/src/vamsas/objects/simple/Object.java +++ b/src/vamsas/objects/simple/Object.java @@ -37,7 +37,7 @@ public abstract class Object implements java.io.Serializable { return false; } - Object other = (Object) obj; + //Object other = (Object) obj; if (obj == null) { return false;