From: janengelhardt Date: Mon, 23 May 2011 10:16:35 +0000 (+0200) Subject: Start merging of Laurens Code X-Git-Tag: Jalview_2_9~576^2~44 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=323a457c9d0643be2406b6661246e8e988c0d0f6 Start merging of Laurens Code Change-Id: Ic7501daa6075363a8f725ba2c6784cedefa27207 --- diff --git a/.classpath b/.classpath index bb761d8..ec1077a 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,7 @@ + @@ -39,5 +40,6 @@ + diff --git a/.project b/.project index a4ddc99..fd3d93f 100644 --- a/.project +++ b/.project @@ -25,6 +25,16 @@ + + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/Jalview build.xml [Builder] (1).launch + + + org.eclipse.jem.workbench.JavaEMFNature diff --git a/src/jalview/analysis/Rna.java b/src/jalview/analysis/Rna.java new file mode 100644 index 0000000..69a228b --- /dev/null +++ b/src/jalview/analysis/Rna.java @@ -0,0 +1,169 @@ +/* Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) + * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + */ + +/* Author: Lauren Michelle Lui + * Methods are based on RALEE methods http://personalpages.manchester.ac.uk/staff/sam.griffiths-jones/software/ralee/ + * */ + +package jalview.analysis; + +import java.util.Hashtable; +import java.util.Vector; + +import jalview.datamodel.SequenceFeature; + +public class Rna +{ + /** + * Based off of RALEE code ralee-get-base-pairs. Keeps track of open bracket + * positions in "stack" vector. When a close bracket is reached, pair this + * with the last element in the "stack" vector and store in "pairs" vector. + * Remove last element in the "stack" vector. Continue in this manner until + * the whole string is processed. + * + * @param line + * Secondary structure line of an RNA Stockholm file + * @return Array of SequenceFeature; type = RNA helix, begin is open base + * pair, end is close base pair + */ + public static SequenceFeature[] GetBasePairs(String line) + { + + Vector stack = new Vector(); + Vector pairs = new Vector(); + + int i = 0; + while (i < line.length()) + { + char base = line.charAt(i); + + if ((base == '<') || (base == '(') || (base == '{') || (base == '[')) + { + stack.addElement(i); + } + else if ((base == '>') || (base == ')') || (base == '}') + || (base == ']')) + { + + Object temp = stack.lastElement(); + stack.remove(stack.size() - 1); + pairs.addElement(temp); + pairs.addElement(i); + } + + i++; + } + + int numpairs = pairs.size() / 2; + SequenceFeature[] outPairs = new SequenceFeature[numpairs]; + + // Convert pairs to array + for (int p = 0; p < pairs.size(); p += 2) + { + int begin = Integer.parseInt(pairs.elementAt(p).toString()); + int end = Integer.parseInt(pairs.elementAt(p + 1).toString()); + + outPairs[p / 2] = new SequenceFeature("RNA helix", "", "", begin, + end, ""); + } + + return outPairs; + } + + /** + * Figures out which helix each position belongs to and stores the helix + * number in the 'featureGroup' member of a SequenceFeature Based off of RALEE + * code ralee-helix-map. + * + * @param pairs + * Array of SequenceFeature (output from Rna.GetBasePairs) + */ + public static void HelixMap(SequenceFeature[] pairs) + { + + int helix = 0; // Number of helices/current helix + int lastopen = 0; // Position of last open bracket reviewed + int lastclose = 9999999; // Position of last close bracket reviewed + int i = pairs.length; // Number of pairs + + int open; // Position of an open bracket under review + int close; // Position of a close bracket under review + int j; // Counter + + Hashtable helices = new Hashtable(); // Keep track of helix number for each + // position + + // Go through each base pair and assign positions a helix + for (i = 0; i < pairs.length; i++) + { + + open = pairs[i].getBegin(); + close = pairs[i].getEnd(); + + // System.out.println("open " + open + " close " + close); + // System.out.println("lastclose " + lastclose + " lastopen " + lastopen); + + // we're moving from right to left based on closing pair + /* + * catch things like <<..>>..<<..>> | + */ + if (open > lastclose) + { + helix++; + } + + /* + * catch things like <<..<<..>>..<<..>>>> | + */ + j = pairs.length - 1; + while (j >= 0) + { + int popen = pairs[j].getBegin(); + + // System.out.println("j " + j + " popen " + popen + " lastopen " + // +lastopen + " open " + open); + if ((popen < lastopen) && (popen > open)) + { + if (helices.containsValue(popen) + && (((Integer) helices.get(popen)) == helix)) + { + continue; + } + else + { + helix++; + break; + } + } + + j -= 1; + } + + // Put positions and helix information into the hashtable + helices.put(open, helix); + helices.put(close, helix); + + // Record helix as featuregroup + pairs[i].setFeatureGroup(Integer.toString(helix)); + pairs[i].setFeatureGroup(Integer.toString(helix)); + + lastopen = open; + lastclose = close; + + } + } +} diff --git a/src/jalview/appletgui/AppletJmol.java b/src/jalview/appletgui/AppletJmol.java index 0ff2467..d8b58fd 100644 --- a/src/jalview/appletgui/AppletJmol.java +++ b/src/jalview/appletgui/AppletJmol.java @@ -71,6 +71,8 @@ public class AppletJmol extends EmbmenuFrame implements MenuItem turn = new MenuItem("Turn Propensity"); MenuItem buried = new MenuItem("Buried Index"); + + MenuItem purinepyrimidine = new MenuItem("Purine/Pyrimidine"); MenuItem user = new MenuItem("User Defined Colours"); @@ -187,6 +189,7 @@ public class AppletJmol extends EmbmenuFrame implements strand.addActionListener(this); turn.addActionListener(this); buried.addActionListener(this); + purinepyrimidine.addActionListener(this); user.addActionListener(this); jmolHelp.addActionListener(this); @@ -201,6 +204,7 @@ public class AppletJmol extends EmbmenuFrame implements coloursMenu.add(strand); coloursMenu.add(turn); coloursMenu.add(buried); + coloursMenu.add(purinepyrimidine); coloursMenu.add(user); coloursMenu.add(jmolColour); helpMenu.add(jmolHelp); @@ -444,6 +448,10 @@ public class AppletJmol extends EmbmenuFrame implements setEnabled(buried); jmb.setJalviewColourScheme(new BuriedColourScheme()); } + else if(evt.getSource() == purinepyrimidine) + { + jmb.setJalviewColourScheme(new PurinePyrimidineColourScheme()); + } else if (evt.getSource() == user) { setEnabled(user); diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index 236e8ee..c4268e2 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -17,6 +17,8 @@ */ package jalview.datamodel; +import jalview.analysis.Rna; + import java.util.Enumeration; import java.util.Hashtable; @@ -47,6 +49,31 @@ public class AlignmentAnnotation /** DOCUMENT ME!! */ public Annotation[] annotations; + /** + * RNA secondary structure contact positions + */ + public SequenceFeature[] _rnasecstr = null; + + /** + * Updates the _rnasecstr field Determines the positions that base pair and + * the positions of helices based on secondary structure from a Stockholm file + * + * @param RNAannot + */ + private void _updateRnaSecStr(String RNAannot) + { + _rnasecstr = Rna.GetBasePairs(RNAannot); + Rna.HelixMap(_rnasecstr); + + if (_rnasecstr != null && _rnasecstr.length > 0) + { + // show all the RNA secondary structure annotation symbols. + showAllColLabels = true; + scaleColLabel = true; + } + // System.out.println("featuregroup " + _rnasecstr[0].getFeatureGroup()); + } + public java.util.Hashtable sequenceMapping; /** DOCUMENT ME!! */ @@ -167,9 +194,16 @@ public class AlignmentAnnotation validateRangeAndDisplay(); } + /** + * Checks if annotation labels represent secondary structures + * + */ void areLabelsSecondaryStructure() { boolean nonSSLabel = false; + boolean isrna = false; + StringBuffer rnastring = new StringBuffer(); + char firstChar = 0; for (int i = 0; i < annotations.length; i++) { @@ -182,9 +216,22 @@ public class AlignmentAnnotation { hasIcons |= true; } + else + // Check for RNA secondary structure + { + if (annotations[i].secondaryStructure == 'S') + { + hasIcons |= true; + isrna |= true; + } + } - if (annotations[i].displayCharacter == null) + // System.out.println("displaychar " + annotations[i].displayCharacter); + + if (annotations[i].displayCharacter == null + || annotations[i].displayCharacter.length() == 0) { + rnastring.append('.'); continue; } if (annotations[i].displayCharacter.length() == 1) @@ -205,6 +252,7 @@ public class AlignmentAnnotation firstChar != ' ' && firstChar != 'H' && firstChar != 'E' + && firstChar != 'S' && firstChar != '-' && firstChar < jalview.schemes.ResidueProperties.aaIndex.length) { @@ -219,6 +267,10 @@ public class AlignmentAnnotation } } } + else + { + rnastring.append(annotations[i].displayCharacter.charAt(1)); + } if (annotations[i].displayCharacter.length() > 0) { @@ -241,6 +293,13 @@ public class AlignmentAnnotation } } + else + { + if (isrna) + { + _updateRnaSecStr(rnastring.toString()); + } + } annotationId = this.hashCode() + ""; } diff --git a/src/jalview/datamodel/DBRefSource.java b/src/jalview/datamodel/DBRefSource.java index e060b54..d605f8e 100755 --- a/src/jalview/datamodel/DBRefSource.java +++ b/src/jalview/datamodel/DBRefSource.java @@ -61,6 +61,11 @@ public class DBRefSource * PFAM ID */ public static String PFAM = "PFAM"; + + /** + * RFAM ID + */ + public static String RFAM = "RFAM"; /** * GeneDB ID @@ -86,7 +91,7 @@ public class DBRefSource { PDB }; public static final String[] DOMAINDBS = - { PFAM }; + { PFAM, RFAM }; /** * set of unique DBRefSource property constants. These could be used to @@ -115,7 +120,7 @@ public class DBRefSource public static final Object DNACODINGSEQDB = "XONCODING"; /** - * DB returns several sequences associated with a protein domain + * DB returns several sequences associated with a protein/nucleotide domain */ public static final Object DOMAINDB = "DOMAIN"; diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 06272c3..fc2fe24 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -65,6 +65,7 @@ import jalview.schemes.HelixColourScheme; import jalview.schemes.HydrophobicColourScheme; import jalview.schemes.NucleotideColourScheme; import jalview.schemes.PIDColourScheme; +import jalview.schemes.PurinePyrimidineColourScheme; import jalview.schemes.ResidueProperties; import jalview.schemes.StrandColourScheme; import jalview.schemes.TaylorColourScheme; @@ -2964,10 +2965,25 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, changeColour(new NucleotideColourScheme()); } + public void purinePyrimidineColour_actionPerformed(ActionEvent e) + { + changeColour(new PurinePyrimidineColourScheme()); + } + /* + public void covariationColour_actionPerformed(ActionEvent e) + { + changeColour(new CovariationColourScheme(viewport.alignment.getAlignmentAnnotation()[0])); + } + */ public void annotationColour_actionPerformed(ActionEvent e) { new AnnotationColourChooser(viewport, alignPanel); } + + public void rnahelicesColour_actionPerformed(ActionEvent e) + { + new RNAHelicesColourChooser(viewport, alignPanel); + } /** * DOCUMENT ME! diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 8a93f79..60d3e06 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -26,6 +26,8 @@ import java.util.Hashtable; import javax.swing.*; +import com.stevesoft.pat.Regex; + import jalview.analysis.AAFrequency; import jalview.datamodel.*; import jalview.schemes.ColourSchemeI; @@ -43,6 +45,11 @@ public class AnnotationPanel extends JPanel implements MouseListener, final String SHEET = "Sheet"; + /** + * For RNA secondary structure "stems" aka helices + */ + final String STEM = "RNA Helix"; + final String LABEL = "Label"; final String REMOVE = "Remove Annotation"; @@ -53,6 +60,8 @@ public class AnnotationPanel extends JPanel implements MouseListener, final Color SHEET_COLOUR = Color.green.darker().darker(); + final Color STEM_COLOUR = Color.blue.darker(); + /** DOCUMENT ME!! */ AlignViewport av; @@ -303,6 +312,13 @@ public class AnnotationPanel extends JPanel implements MouseListener, symbol = "\u03B2"; } + // Added by LML to color stems + else if (evt.getActionCommand().equals(STEM)) + { + type = 'S'; + symbol = "\u03C3"; + } + if (!aa[activeRow].hasIcons) { aa[activeRow].hasIcons = true; @@ -357,14 +373,15 @@ public class AnnotationPanel extends JPanel implements MouseListener, continue; String tlabel = null; if (anot[index] != null) - { + { // LML added stem code if (label2.equals(HELIX) || label2.equals(SHEET) - || label2.equals(LABEL)) + || label2.equals(STEM) || label2.equals(LABEL)) { tlabel = anot[index].description; if (tlabel == null || tlabel.length() < 1) { - if (label2.equals(HELIX) || label2.equals(SHEET)) + if (label2.equals(HELIX) || label2.equals(SHEET) + || label2.equals(STEM)) { tlabel = "" + anot[index].secondaryStructure; } @@ -443,6 +460,9 @@ public class AnnotationPanel extends JPanel implements MouseListener, item = new JMenuItem(SHEET); item.addActionListener(this); pop.add(item); + item = new JMenuItem(STEM); + item.addActionListener(this); + pop.add(item); item = new JMenuItem(LABEL); item.addActionListener(this); pop.add(item); @@ -1045,6 +1065,38 @@ public class AnnotationPanel extends JPanel implements MouseListener, break; + case 'S': // Stem case for RNA secondary structure + g.setColor(STEM_COLOUR); // row.annotations[column].colour for By + // RNA Helices colouring + // System.out.println("last SSX displayx" + + // row.annotations[column-1].displayCharacter +"x"); + Regex closeparen = new Regex("(\\))"); + + //If a closing base pair half of the stem, display a backward arrow + if (closeparen + .search(row.annotations[column - 1].displayCharacter))// row.annotations[column-1].displayCharacter)) + { + g.fillPolygon(new int[] + { lastSSX + 5, lastSSX + 5, lastSSX }, + new int[] + { y + iconOffset, y + 14 + iconOffset, + y + 8 + iconOffset }, 3); + g.fillRect(lastSSX + 2, y + 4 + iconOffset, + (x * av.charWidth) - lastSSX - 2, 7); + } + else //display a forward arrow + { + g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth) + - lastSSX - 4, 7); + g.fillPolygon(new int[] + { (x * av.charWidth) - 5, (x * av.charWidth) - 5, + (x * av.charWidth) }, + new int[] + { y + iconOffset, y + 14 + iconOffset, + y + 8 + iconOffset }, 3); + } + break; + default: g.setColor(Color.gray); g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth) diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index 5c5e3e8..1ea255e 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -1053,7 +1053,12 @@ public class AppJmol extends GStructureViewer implements Runnable, buriedColour.setSelected(true); jmb.setJalviewColourScheme(new BuriedColourScheme()); } - + + public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent) + { + setJalviewColourScheme(new PurinePyrimidineColourScheme()); + } + public void userColour_actionPerformed(ActionEvent actionEvent) { userColour.setSelected(true); diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 9797694..45aed9c 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -951,7 +951,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements } // TODO: update this text for each release or centrally store it for lite // and application - message.append("\nAuthors: Jim Procter, Jan Engelhardt, Lauren Lui, Andrew Waterhouse, Michele Clamp, James Cuff, Steve Searle,\n David Martin & Geoff Barton." + message.append("\nAuthors: Jim Procter, Jan Engelhardt2, Lauren Lui, Andrew Waterhouse, Michele Clamp, James Cuff, Steve Searle,\n David Martin & Geoff Barton." + "\nDevelopment managed by The Barton Group, University of Dundee, Scotland, UK.\n" + "\nFor help, see the FAQ at www.jalview.org and/or join the jalview-discuss@jalview.org mailing list\n" + "\nIf you use Jalview, please cite:" diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 477136f..e85da7a 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -69,6 +69,10 @@ public class PopupMenu extends JPopupMenu protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem(); protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem(); + + protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem(); + + //protected JRadioButtonMenuItem covariationColour = new JRadioButtonMenuItem(); JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem(); @@ -183,6 +187,8 @@ public class PopupMenu extends JPopupMenu colours.add(userDefinedColour); colours.add(PIDColour); colours.add(BLOSUM62Colour); + colours.add(purinePyrimidineColour); + //colours.add(covariationColour); for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++) { @@ -367,6 +373,14 @@ public class PopupMenu extends JPopupMenu { clustalColour.setSelected(true); } + else if (sg.cs instanceof PurinePyrimidineColourScheme) + { + purinePyrimidineColour.setSelected(true); + } + /* else if (sg.cs instanceof CovariationColourScheme) + { + covariationColour.setSelected(true); + }*/ else { noColourmenuItem.setSelected(true); @@ -995,6 +1009,8 @@ public class PopupMenu extends JPopupMenu colourMenu.add(turnColour); colourMenu.add(buriedColour); colourMenu.add(nucleotideMenuItem); + colourMenu.add(purinePyrimidineColour); + //colourMenu.add(covariationColour); colourMenu.add(userDefinedColour); if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null) @@ -1146,6 +1162,23 @@ public class PopupMenu extends JPopupMenu BLOSUM62Colour_actionPerformed(); } }); + purinePyrimidineColour.setText("Purine/Pyrimidine"); + purinePyrimidineColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + purinePyrimidineColour_actionPerformed(); + } + }); + /* + covariationColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + covariationColour_actionPerformed(); + } + });*/ + conservationMenuItem.setText("Conservation"); conservationMenuItem .addActionListener(new java.awt.event.ActionListener() @@ -1284,7 +1317,19 @@ public class PopupMenu extends JPopupMenu getGroup().cs = new NucleotideColourScheme(); refresh(); } - + + protected void purinePyrimidineColour_actionPerformed() + { + getGroup().cs = new PurinePyrimidineColourScheme(); + refresh(); + } + /* + protected void covariationColour_actionPerformed() + { + getGroup().cs = new CovariationColourScheme(sequence.getAnnotation()[0]); + refresh(); + } +*/ /** * DOCUMENT ME! * diff --git a/src/jalview/gui/RNAHelicesColourChooser.java b/src/jalview/gui/RNAHelicesColourChooser.java new file mode 100644 index 0000000..3354735 --- /dev/null +++ b/src/jalview/gui/RNAHelicesColourChooser.java @@ -0,0 +1,149 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) + * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + */ +package jalview.gui; + +import java.util.*; +import java.awt.event.*; + +import jalview.datamodel.*; +import jalview.schemes.*; + +/** + * Helps generate the colors for RNA secondary structure. Future: add option to + * change colors based on covariation. + * + * @author Lauren Michelle Lui + * + */ +public class RNAHelicesColourChooser +{ + + AlignViewport av; + + AlignmentPanel ap; + + ColourSchemeI oldcs; + + Hashtable oldgroupColours; + + jalview.datamodel.AlignmentAnnotation currentAnnotation; + + boolean adjusting = false; + + public RNAHelicesColourChooser(AlignViewport av, final AlignmentPanel ap) + { + oldcs = av.getGlobalColourScheme(); + if (av.alignment.getGroups() != null) + { + oldgroupColours = new Hashtable(); + Vector allGroups = ap.av.alignment.getGroups(); + SequenceGroup sg; + for (int g = 0; g < allGroups.size(); g++) + { + sg = (SequenceGroup) allGroups.get(g); + if (sg.cs != null) + { + oldgroupColours.put(sg, sg.cs); + } + } + } + this.av = av; + this.ap = ap; + + if (oldcs instanceof RNAHelicesColour) + { + RNAHelicesColour rhc = (RNAHelicesColour) oldcs; + + } + + adjusting = true; + Vector list = new Vector(); + int index = 1; + for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++) + { + String label = av.alignment.getAlignmentAnnotation()[i].label; + if (!list.contains(label)) + list.addElement(label); + else + list.addElement(label + "_" + (index++)); + } + + adjusting = false; + + changeColour(); + + } + + void changeColour() + { + // Check if combobox is still adjusting + if (adjusting) + { + return; + } + + currentAnnotation = av.alignment.getAlignmentAnnotation()[0];// annotations.getSelectedIndex()]; + + RNAHelicesColour rhc = null; + + rhc = new RNAHelicesColour(currentAnnotation); + + av.setGlobalColourScheme(rhc); + + if (av.alignment.getGroups() != null) + { + Vector allGroups = ap.av.alignment.getGroups(); + SequenceGroup sg; + for (int g = 0; g < allGroups.size(); g++) + { + sg = (SequenceGroup) allGroups.get(g); + + if (sg.cs == null) + { + continue; + } + + sg.cs = new RNAHelicesColour(currentAnnotation); + + } + } + + ap.paintAlignment(false); + } + + void reset() + { + av.setGlobalColourScheme(oldcs); + if (av.alignment.getGroups() != null) + { + Vector allGroups = ap.av.alignment.getGroups(); + SequenceGroup sg; + for (int g = 0; g < allGroups.size(); g++) + { + sg = (SequenceGroup) allGroups.get(g); + sg.cs = (ColourSchemeI) oldgroupColours.get(sg); + } + } + } + + public void annotations_actionPerformed(ActionEvent e) + { + changeColour(); + } + +} diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index db4b49d..f24ecbc 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -67,7 +67,7 @@ public class AppletFormatAdapter */ public static final String[] READABLE_EXTENSIONS = new String[] { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa", "jar", - "sto" }; // , + "sto", "stk" }; // , // ".blast" // }; diff --git a/src/jalview/io/StockholmFile.java b/src/jalview/io/StockholmFile.java index e81c31a..2e0fea7 100644 --- a/src/jalview/io/StockholmFile.java +++ b/src/jalview/io/StockholmFile.java @@ -25,6 +25,7 @@ import java.util.*; import com.stevesoft.pat.*; import jalview.datamodel.*; +import jalview.analysis.Rna; // import org.apache.log4j.*; @@ -82,6 +83,9 @@ public class StockholmFile extends AlignFile Hashtable seqs = new Hashtable(); Regex p, r, rend, s, x; + // Temporary line for processing RNA annotation + // String RNAannot = ""; + // ------------------ Parsing File ---------------------- // First, we have to check that this file has STOCKHOLM format, i.e. the // first line must match @@ -105,11 +109,20 @@ public class StockholmFile extends AlignFile r = new Regex("#=(G[FSRC]?)\\s+(.*)"); // Finds any annotation line x = new Regex("(\\S+)\\s+(\\S+)"); // split id from sequence + // Convert all bracket types to parentheses (necessary for passing to VARNA) + Regex openparen = new Regex("(<|\\[)", "("); + Regex closeparen = new Regex("(>|\\])", ")"); + + // Detect if file is RNA by looking for bracket types + Regex detectbrackets = new Regex("(<|>|\\[|\\]|\\(|\\))"); + rend.optimize(); p.optimize(); s.optimize(); r.optimize(); x.optimize(); + openparen.optimize(); + closeparen.optimize(); while ((line = nextLine()) != null) { @@ -477,6 +490,19 @@ public class StockholmFile extends AlignFile private AlignmentAnnotation parseAnnotationRow(Vector annotation, String label, String annots) { + String convert1, convert2 = null; + + // Convert all bracket types to parentheses + Regex openparen = new Regex("(<|\\[)", "("); + Regex closeparen = new Regex("(>|\\])", ")"); + + // Detect if file is RNA by looking for bracket types + Regex detectbrackets = new Regex("(<|>|\\[|\\]|\\(|\\))"); + + convert1 = openparen.replaceAll(annots); + convert2 = closeparen.replaceAll(convert1); + annots = convert2; + String type = (label.indexOf("_cons") == label.length() - 5) ? label .substring(0, label.length() - 5) : label; boolean ss = false; @@ -495,8 +521,17 @@ public class StockholmFile extends AlignFile // be written out if (ss) { - ann.secondaryStructure = jalview.schemes.ResidueProperties - .getDssp3state(pos).charAt(0); + if (detectbrackets.search(pos)) + { + ann.secondaryStructure = jalview.schemes.ResidueProperties + .getRNASecStrucState(pos).charAt(0); + } + else + { + ann.secondaryStructure = jalview.schemes.ResidueProperties + .getDssp3state(pos).charAt(0); + } + if (ann.secondaryStructure == pos.charAt(0) || pos.charAt(0) == 'C') { ann.displayCharacter = ""; // null; // " "; @@ -580,4 +615,38 @@ public class StockholmFile extends AlignFile + id); return id; } + /** + * //ssline is complete secondary structure line private AlignmentAnnotation + * addHelices(Vector annotation, String label, String ssline) { + * + * // decide on secondary structure or not. Annotation[] els = new + * Annotation[ssline.length()]; for (int i = 0; i < ssline.length(); i++) { + * String pos = ssline.substring(i, i + 1); Annotation ann; ann = new + * Annotation(pos, "", ' ', 0f); // 0f is 'valid' null - will not + * + * ann.secondaryStructure = + * jalview.schemes.ResidueProperties.getRNAssState(pos).charAt(0); + * + * ann.displayCharacter = "x" + ann.displayCharacter; + * + * System.out.println(ann.displayCharacter); + * + * els[i] = ann; } AlignmentAnnotation helicesAnnot = null; Enumeration e = + * annotation.elements(); while (e.hasMoreElements()) { helicesAnnot = + * (AlignmentAnnotation) e.nextElement(); if (helicesAnnot.label.equals(type)) + * break; helicesAnnot = null; } if (helicesAnnot == null) { helicesAnnot = + * new AlignmentAnnotation(type, type, els); + * annotation.addElement(helicesAnnot); } else { Annotation[] anns = new + * Annotation[helicesAnnot.annotations.length + els.length]; + * System.arraycopy(helicesAnnot.annotations, 0, anns, 0, + * helicesAnnot.annotations.length); System.arraycopy(els, 0, anns, + * helicesAnnot.annotations.length, els.length); helicesAnnot.annotations = + * anns; } + * + * helicesAnnot.features = Rna.GetBasePairs(ssline); + * Rna.HelixMap(helicesAnnot.features); + * + * + * return helicesAnnot; } + */ } diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 9260b23..7eb4693 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -113,6 +113,13 @@ public class GAlignFrame extends JInternalFrame protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem nucleotideColour = new JRadioButtonMenuItem(); + + protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem(); + + // protected JRadioButtonMenuItem covariationColour = new + // JRadioButtonMenuItem(); + JMenuItem njTreeBlosumMenuItem = new JMenuItem(); JMenuItem avDistanceTreeBlosumMenuItem = new JMenuItem(); @@ -149,8 +156,6 @@ public class GAlignFrame extends JInternalFrame public JCheckBoxMenuItem showSeqFeaturesHeight = new JCheckBoxMenuItem(); - protected JRadioButtonMenuItem nucleotideColour = new JRadioButtonMenuItem(); - JMenuItem deleteGroups = new JMenuItem(); JMenuItem delete = new JMenuItem(); @@ -217,6 +222,8 @@ public class GAlignFrame extends JInternalFrame JMenuItem annotationColour = new JMenuItem(); + JMenuItem rnahelicesColour = new JMenuItem(); + JMenuItem associatedData = new JMenuItem(); protected JCheckBoxMenuItem autoCalculate = new JCheckBoxMenuItem(); @@ -413,6 +420,8 @@ public class GAlignFrame extends JInternalFrame colours.add(PIDColour); colours.add(BLOSUM62Colour); colours.add(nucleotideColour); + colours.add(purinePyrimidineColour); + // colours.add(covariationColour); setColourSelected(jalview.bin.Cache .getDefault("DEFAULT_COLOUR", "None")); @@ -483,6 +492,16 @@ public class GAlignFrame extends JInternalFrame break; + case ColourSchemeProperty.PURINEPYRIMIDINE: + purinePyrimidineColour.setSelected(true); + + break; + /* + * case ColourSchemeProperty.COVARIATION: + * covariationColour.setSelected(true); + * + * break; + */ case ColourSchemeProperty.USER_DEFINED: userDefinedColour.setSelected(true); @@ -846,6 +865,31 @@ public class GAlignFrame extends JInternalFrame BLOSUM62Colour_actionPerformed(e); } }); + nucleotideColour.setText("Nucleotide"); + nucleotideColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + nucleotideColour_actionPerformed(e); + } + }); + + purinePyrimidineColour.setText("Purine/Pyrimidine"); + purinePyrimidineColour + .addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + purinePyrimidineColour_actionPerformed(e); + } + }); + /* + * covariationColour.setText("Covariation"); + * covariationColour.addActionListener(new java.awt.event.ActionListener() { + * public void actionPerformed(ActionEvent e) { + * covariationColour_actionPerformed(e); } }); + */ + avDistanceTreeBlosumMenuItem.setText("Average Distance Using BLOSUM62"); avDistanceTreeBlosumMenuItem .addActionListener(new java.awt.event.ActionListener() @@ -1385,6 +1429,16 @@ public class GAlignFrame extends JInternalFrame annotationColour_actionPerformed(e); } }); + + rnahelicesColour.setText("By RNA helices"); + rnahelicesColour.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + rnahelicesColour_actionPerformed(e); + } + }); + associatedData.setText("Load Features / Annotations"); associatedData.addActionListener(new ActionListener() { @@ -1733,6 +1787,8 @@ public class GAlignFrame extends JInternalFrame colourMenu.add(turnColour); colourMenu.add(buriedColour); colourMenu.add(nucleotideColour); + colourMenu.add(purinePyrimidineColour); + // colourMenu.add(covariationColour); colourMenu.add(userDefinedColour); colourMenu.addSeparator(); colourMenu.add(conservationMenuItem); @@ -1740,6 +1796,7 @@ public class GAlignFrame extends JInternalFrame colourMenu.add(abovePIDThreshold); colourMenu.add(modifyPID); colourMenu.add(annotationColour); + colourMenu.add(rnahelicesColour); calculateMenu.add(sort); calculateMenu.add(calculateTree); calculateMenu.addSeparator(); @@ -2104,6 +2161,14 @@ public class GAlignFrame extends JInternalFrame { } + protected void purinePyrimidineColour_actionPerformed(ActionEvent e) + { + } + + /* + * protected void covariationColour_actionPerformed(ActionEvent e) { } + */ + protected void noColourmenuItem_actionPerformed(ActionEvent e) { } @@ -2256,6 +2321,11 @@ public class GAlignFrame extends JInternalFrame } + public void rnahelicesColour_actionPerformed(ActionEvent e) + { + + } + public void associatedData_actionPerformed(ActionEvent e) { diff --git a/src/jalview/jbgui/GStructureViewer.java b/src/jalview/jbgui/GStructureViewer.java index 8116d82..42ae81d 100644 --- a/src/jalview/jbgui/GStructureViewer.java +++ b/src/jalview/jbgui/GStructureViewer.java @@ -164,6 +164,15 @@ public class GStructureViewer extends JInternalFrame buriedColour_actionPerformed(actionEvent); } }); + purinePyrimidineColour.setText("Purine/Pyrimidine"); + purinePyrimidineColour.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent actionEvent) + { + purinePyrimidineColour_actionPerformed(actionEvent); + } + }); + userColour.setText("User Defined ..."); userColour.addActionListener(new ActionListener() { @@ -224,6 +233,7 @@ public class GStructureViewer extends JInternalFrame colourMenu.add(strandColour); colourMenu.add(turnColour); colourMenu.add(buriedColour); + colourMenu.add(purinePyrimidineColour); colourMenu.add(userColour); colourMenu.add(jmolColour); colourMenu.add(backGround); @@ -300,6 +310,9 @@ public class GStructureViewer extends JInternalFrame protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem(); protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem(); + + protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem userColour = new JRadioButtonMenuItem(); @@ -380,6 +393,11 @@ public class GStructureViewer extends JInternalFrame { } + + public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent) + { + + } public void userColour_actionPerformed(ActionEvent actionEvent) { diff --git a/src/jalview/schemes/ColourSchemeProperty.java b/src/jalview/schemes/ColourSchemeProperty.java index f50ac0a..45dd6d1 100755 --- a/src/jalview/schemes/ColourSchemeProperty.java +++ b/src/jalview/schemes/ColourSchemeProperty.java @@ -153,6 +153,14 @@ public class ColourSchemeProperty { ret = NONE; } + else if (name.equalsIgnoreCase("Purine/Pyrimidine")) + { + ret = PURINEPYRIMIDINE; + } + // else if (name.equalsIgnoreCase("Covariation")) + // { + // ret = COVARIATION; + // } return ret; } @@ -214,6 +222,13 @@ public class ColourSchemeProperty { index = NUCLEOTIDE; } + else if (cs instanceof PurinePyrimidineColourScheme) + { + index = PURINEPYRIMIDINE; + } + /* + * else if (cs instanceof CovariationColourScheme) { index = COVARIATION; } + */ else if (cs instanceof UserColourScheme) { if ((((UserColourScheme) cs).getName() != null) @@ -296,6 +311,16 @@ public class ColourSchemeProperty break; + case PURINEPYRIMIDINE: + ret = "Purine/Pyrimidine"; + + break; + + /* + * case COVARIATION: ret = "Covariation"; + * + * break; + */ case USER_DEFINED: ret = "User Defined"; @@ -447,6 +472,16 @@ public class ColourSchemeProperty break; + case PURINEPYRIMIDINE: + cs = new PurinePyrimidineColourScheme(); + + break; + + // case COVARIATION: + // cs = new CovariationColourScheme(annotation); + + // break; + case USER_DEFINED: Color[] col = new Color[24]; for (int i = 0; i < 24; i++) diff --git a/src/jalview/schemes/CovariationColourScheme.java b/src/jalview/schemes/CovariationColourScheme.java new file mode 100644 index 0000000..fe533ed --- /dev/null +++ b/src/jalview/schemes/CovariationColourScheme.java @@ -0,0 +1,121 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) + * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + */ +package jalview.schemes; + +import java.awt.*; +import java.util.Hashtable; + +import jalview.datamodel.AlignmentAnnotation; + +/** + * Became RNAHelicesColour.java. Placeholder for true covariation color scheme + * + * @author Lauren Michelle Lui + * @version 2.5 + */ +public class CovariationColourScheme extends ResidueColourScheme +{ + public Hashtable helixcolorhash = new Hashtable(); + + public Hashtable positionsToHelix = new Hashtable(); + + int numHelix = 0; + + public AlignmentAnnotation annotation; + + /** + * Creates a new CovariationColourScheme object. + */ + public CovariationColourScheme(AlignmentAnnotation annotation) + { + this.annotation = annotation; + + for (int x = 0; x < this.annotation._rnasecstr.length; x++) + { + // System.out.println(this.annotation._rnasecstr[x] + " Begin" + + // this.annotation._rnasecstr[x].getBegin()); + // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup()); + // pairs.put(this.annotation._rnasecstr[x].getBegin(), + // this.annotation._rnasecstr[x].getEnd()); + + positionsToHelix.put(this.annotation._rnasecstr[x].getBegin(), + this.annotation._rnasecstr[x].getFeatureGroup()); + positionsToHelix.put(this.annotation._rnasecstr[x].getEnd(), + this.annotation._rnasecstr[x].getFeatureGroup()); + + if (Integer.parseInt(this.annotation._rnasecstr[x].getFeatureGroup()) > numHelix) + { + numHelix = Integer.parseInt(this.annotation._rnasecstr[x] + .getFeatureGroup()); + } + + } + + for (int j = 0; j <= numHelix; j++) + { + helixcolorhash.put(Integer.toString(j), jalview.util.ColorUtils + .generateRandomColor(Color.white)); + } + + } + + /** + * DOCUMENT ME! + * + * @param n + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Color findColour(char c) + { + // System.out.println("called"); log.debug + // Generate a random pastel color + + return ResidueProperties.purinepyrimidine[ResidueProperties.purinepyrimidineIndex[c]];// jalview.util.ColorUtils.generateRandomColor(Color.white); + } + + /** + * DOCUMENT ME! + * + * @param n + * DOCUMENT ME! + * @param j + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Color findColour(char c, int j) + { + Color currentColour = Color.white; + String currentHelix = null; + // System.out.println(c + " " + j); + currentHelix = (String) positionsToHelix.get(j); + // System.out.println(positionsToHelix.get(j)); + + if (currentHelix != null) + { + currentColour = (Color) helixcolorhash.get(currentHelix); + } + + // System.out.println(c + " " + j + " helix " + currentHelix + " " + + // currentColour); + return currentColour; + } + +} diff --git a/src/jalview/schemes/PurinePyrimidineColourScheme.java b/src/jalview/schemes/PurinePyrimidineColourScheme.java new file mode 100644 index 0000000..7b0a622 --- /dev/null +++ b/src/jalview/schemes/PurinePyrimidineColourScheme.java @@ -0,0 +1,86 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) + * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + */ +package jalview.schemes; + +import java.awt.*; + +/** + * Class is based off of NucleotideColourScheme + * + * @author Lauren Michelle Lui + */ +public class PurinePyrimidineColourScheme extends ResidueColourScheme +{ + /** + * Creates a new PurinePyrimidineColourScheme object. + */ + public PurinePyrimidineColourScheme() + { + super(ResidueProperties.purinepyrimidine, 0); + } + + /** + * Finds the corresponding color for the type of character inputed + * + * @param c + * Character in sequence + * + * @return Color from purinepyrimidineIndex in + * jalview.schemes.ResidueProperties + */ + public Color findColour(char c) + { + return colors[ResidueProperties.purinepyrimidineIndex[c]]; + } + + /** + * Returns color based on conservation + * + * @param c + * Character in sequence + * @param j + * Threshold + * + * @return Color in RGB + */ + public Color findColour(char c, int j) + { + Color currentColour; + if ((threshold == 0) || aboveThreshold(c, j)) + { + try + { + currentColour = colors[ResidueProperties.purinepyrimidineIndex[c]]; + } catch (Exception ex) + { + return Color.white; + } + } + else + { + return Color.white; + } + + if (conservationColouring) + { + currentColour = applyConservation(currentColour, j); + } + + return currentColour; + } +} diff --git a/src/jalview/schemes/RNAHelicesColour.java b/src/jalview/schemes/RNAHelicesColour.java new file mode 100644 index 0000000..26e4be2 --- /dev/null +++ b/src/jalview/schemes/RNAHelicesColour.java @@ -0,0 +1,136 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) + * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + */ +package jalview.schemes; + +import java.awt.*; +import java.util.Hashtable; + +import jalview.datamodel.AlignmentAnnotation; + +/** + * Looks at the information computed from an RNA Stockholm format file on the + * secondary structure of the alignment. Extracts the information on the + * positions of the helices present and assigns colors. + * + * @author Lauren Michelle Lui + * @version 2.5 + */ +public class RNAHelicesColour extends ResidueColourScheme +{ + + /** + * Stores random colors generated for the number of helices + */ + public Hashtable helixcolorhash = new Hashtable(); + + /** + * Maps sequence positions to the RNA helix they belong to. Key: position, + * Value: helix + */ + public Hashtable positionsToHelix = new Hashtable(); + + /** + * Number of helices in the RNA secondary structure + */ + int numHelix = 0; + + public AlignmentAnnotation annotation; + + /** + * Creates a new RNAHelicesColour object. + */ + public RNAHelicesColour(AlignmentAnnotation annotation) + { + this.annotation = annotation; + + // Figure out number of helices + // Length of rnasecstr is the number of pairs of positions that base pair + // with each other in the secondary structure + for (int x = 0; x < this.annotation._rnasecstr.length; x++) + { + + /* + * System.out.println(this.annotation._rnasecstr[x] + " Begin" + + * this.annotation._rnasecstr[x].getBegin()); + */ + // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup()); + + positionsToHelix.put(this.annotation._rnasecstr[x].getBegin(), + this.annotation._rnasecstr[x].getFeatureGroup()); + positionsToHelix.put(this.annotation._rnasecstr[x].getEnd(), + this.annotation._rnasecstr[x].getFeatureGroup()); + + if (Integer.parseInt(this.annotation._rnasecstr[x].getFeatureGroup()) > numHelix) + { + numHelix = Integer.parseInt(this.annotation._rnasecstr[x] + .getFeatureGroup()); + } + + } + + // Generate random colors and store + for (int j = 0; j <= numHelix; j++) + { + helixcolorhash.put(Integer.toString(j), jalview.util.ColorUtils + .generateRandomColor(Color.white)); + } + + } + + /** + * Returns default color base on purinepyrimidineIndex in + * jalview.schemes.ResidueProperties (Allows coloring in sequence logo) + * + * @param c + * Character in sequence + * + * @return color in RGB + */ + public Color findColour(char c) + { + return ResidueProperties.purinepyrimidine[ResidueProperties.purinepyrimidineIndex[c]]; + // random colors for all positions + // jalview.util.ColorUtils.generateRandomColor(Color.white); If you want + } + + /** + * Returns color based on helices + * + * @param c + * Character in sequence + * @param j + * Threshold + * + * @return Color in RGB + */ + public Color findColour(char c, int j) + { + Color currentColour = Color.white; + String currentHelix = null; + currentHelix = (String) positionsToHelix.get(j); + + if (currentHelix != null) + { + currentColour = (Color) helixcolorhash.get(currentHelix); + } + + // System.out.println(c + " " + j + " helix " + currentHelix + " " + + // currentColour); + return currentColour; + } +} diff --git a/src/jalview/schemes/ResidueProperties.java b/src/jalview/schemes/ResidueProperties.java index 9115681..4110c74 100755 --- a/src/jalview/schemes/ResidueProperties.java +++ b/src/jalview/schemes/ResidueProperties.java @@ -30,6 +30,8 @@ public class ResidueProperties public static final int[] nucleotideIndex; + public static final int[] purinepyrimidineIndex; + public static final Hashtable aa3Hash = new Hashtable(); public static final Hashtable aa2Triplet = new Hashtable(); @@ -144,6 +146,54 @@ public class ResidueProperties nucleotideName.put("y", "Unknown Pyrimidine"); nucleotideName.put("N", "Unknown"); nucleotideName.put("n", "Unknown"); + nucleotideName.put("W", "Weak nucleotide (A or T)"); + nucleotideName.put("w", "Weak nucleotide (A or T)"); + nucleotideName.put("S", "Strong nucleotide (G or C)"); + nucleotideName.put("s", "Strong nucleotide (G or C)"); + nucleotideName.put("M", "Amino (A or C)"); + nucleotideName.put("m", "Amino (A or C)"); + nucleotideName.put("K", "Keto (G or T)"); + nucleotideName.put("k", "Keto (G or T)"); + nucleotideName.put("B", "Not A (G or C or T)"); + nucleotideName.put("b", "Not A (G or C or T)"); + nucleotideName.put("H", "Not G (A or C or T)"); + nucleotideName.put("h", "Not G (A or C or T)"); + nucleotideName.put("D", "Not C (A or G or T)"); + nucleotideName.put("d", "Not C (A or G or T)"); + nucleotideName.put("V", "Not T (A or G or C"); + nucleotideName.put("v", "Not T (A or G or C"); + + } + + static + { + purinepyrimidineIndex = new int[255]; + for (int i = 0; i < 255; i++) + { + purinepyrimidineIndex[i] = 3; // non-nucleotide symbols are all non-gap + // gaps. + } + + purinepyrimidineIndex['A'] = 0; + purinepyrimidineIndex['a'] = 0; + purinepyrimidineIndex['C'] = 1; + purinepyrimidineIndex['c'] = 1; + purinepyrimidineIndex['G'] = 0; + purinepyrimidineIndex['g'] = 0; + purinepyrimidineIndex['T'] = 1; + purinepyrimidineIndex['t'] = 1; + purinepyrimidineIndex['U'] = 1; + purinepyrimidineIndex['u'] = 1; + purinepyrimidineIndex['I'] = 2; + purinepyrimidineIndex['i'] = 2; + purinepyrimidineIndex['X'] = 2; + purinepyrimidineIndex['x'] = 2; + purinepyrimidineIndex['R'] = 0; + purinepyrimidineIndex['r'] = 0; + purinepyrimidineIndex['Y'] = 1; + purinepyrimidineIndex['y'] = 1; + purinepyrimidineIndex['N'] = 2; + purinepyrimidineIndex['n'] = 2; } static @@ -280,14 +330,22 @@ public class ResidueProperties new Color(235, 65, 60), // G new Color(60, 136, 238), // T new Color(60, 136, 238), // U - Color.white, // I - Color.white, // X + Color.white, // I (inosine) + Color.white, // X (xanthine) Color.white, // R Color.white, // Y Color.white, // N Color.white, // Gap }; + // Added for PurinePyrimidineColourScheme + public static final Color[] purinepyrimidine = + { new Color(255, 131, 250), // A, G, R purines purplish/orchid + new Color(64, 224, 208), // C,U, T, Y pyrimidines turquoise + Color.white, // all other nucleotides + Color.white // Gap + }; + // Zappo public static final Color[] zappo = { Color.pink, // A @@ -1258,6 +1316,46 @@ public class ResidueProperties return ss.toString(); } + /** + * Used by getRNASecStrucState + * + */ + public static Hashtable toRNAssState; + static + { + toRNAssState = new Hashtable(); + toRNAssState.put(")", "S"); + toRNAssState.put("(", "S"); + } + + /** + * translate to RNA secondary structure representation + * + * @param ssstring + * @return ssstring as a RNA-state secondary structure assignment. + */ + public static String getRNASecStrucState(String ssstring) + { + if (ssstring == null) + { + return null; + } + StringBuffer ss = new StringBuffer(); + for (int i = 0; i < ssstring.length(); i++) + { + String ssc = ssstring.substring(i, i + 1); + if (toRNAssState.containsKey(ssc)) + { + ss.append((String) toRNAssState.get(ssc)); + } + else + { + ss.append(" "); + } + } + return ss.toString(); + } + // main method generates perl representation of residue property hash // / cut here public static void main(String[] args) diff --git a/src/jalview/util/ColorUtils.java b/src/jalview/util/ColorUtils.java new file mode 100644 index 0000000..5aa3bee --- /dev/null +++ b/src/jalview/util/ColorUtils.java @@ -0,0 +1,60 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) + * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + */ + +/** + * author: Lauren Michelle Lui + */ + +package jalview.util; + +import java.awt.Color; +import java.util.Random; + +public class ColorUtils +{ + + /** + * Generates a random color, will mix with input color. Code taken from + * http://stackoverflow + * .com/questions/43044/algorithm-to-randomly-generate-an-aesthetically + * -pleasing-color-palette + * + * @param mix + * @return Random color in RGB + */ + public static final Color generateRandomColor(Color mix) + { + Random random = new Random(); + int red = random.nextInt(256); + int green = random.nextInt(256); + int blue = random.nextInt(256); + + // mix the color + if (mix != null) + { + red = (red + mix.getRed()) / 2; + green = (green + mix.getGreen()) / 2; + blue = (blue + mix.getBlue()) / 2; + } + + Color color = new Color(red, green, blue); + return color; + + } + +} diff --git a/src/jalview/ws/SequenceFetcher.java b/src/jalview/ws/SequenceFetcher.java index fa58a2c..7625153 100644 --- a/src/jalview/ws/SequenceFetcher.java +++ b/src/jalview/ws/SequenceFetcher.java @@ -61,6 +61,8 @@ public class SequenceFetcher extends ASequenceFetcher // alignment is // 'default' for // PFAM + addDBRefSourceImpl(jalview.ws.dbsources.RfamFull.class); + addDBRefSourceImpl(jalview.ws.dbsources.RfamSeed.class); registerDasSequenceSources(); } diff --git a/src/jalview/ws/dbsources/Pfam.java b/src/jalview/ws/dbsources/Pfam.java index 1b2a0c4..1ae72fb 100644 --- a/src/jalview/ws/dbsources/Pfam.java +++ b/src/jalview/ws/dbsources/Pfam.java @@ -37,7 +37,7 @@ import jalview.ws.seqfetcher.DbSourceProxyImpl; * @author JimP * */ -abstract public class Pfam extends DbSourceProxyImpl implements +abstract public class Pfam extends Xfam implements DbSourceProxy { @@ -95,17 +95,19 @@ abstract public class Pfam extends DbSourceProxyImpl implements * * @see jalview.ws.DbSourceProxy#getDbVersion() */ - public String getDbVersion() + @Override +public String getDbVersion() { // TODO Auto-generated method stub return null; } - /** + /**Returns base URL for selected Pfam alignment type * * @return PFAM URL stub for this DbSource */ - protected abstract String getPFAMURL(); + @Override +protected abstract String getXFAMURL(); /* * (non-Javadoc) @@ -151,4 +153,9 @@ abstract public class Pfam extends DbSourceProxyImpl implements /* * public String getDbName() { return "PFAM"; // getDbSource(); } */ + + + public String getXfamSource() { return jalview.datamodel.DBRefSource.PFAM; } + + } diff --git a/src/jalview/ws/dbsources/PfamFull.java b/src/jalview/ws/dbsources/PfamFull.java index a32068b..7748eac 100644 --- a/src/jalview/ws/dbsources/PfamFull.java +++ b/src/jalview/ws/dbsources/PfamFull.java @@ -35,7 +35,7 @@ public class PfamFull extends Pfam implements DbSourceProxy * * @see jalview.ws.dbsources.Pfam#getPFAMURL() */ - protected String getPFAMURL() + protected String getXFAMURL() { return "http://pfam.sanger.ac.uk/family/alignment/download/format?alnType=full&format=stockholm&order=t&case=l&gaps=default&entry="; } @@ -60,4 +60,8 @@ public class PfamFull extends Pfam implements DbSourceProxy return "PF03760"; } +public String getDbVersion() { + return null; +} + } diff --git a/src/jalview/ws/dbsources/PfamSeed.java b/src/jalview/ws/dbsources/PfamSeed.java index 3e1eced..8004678 100644 --- a/src/jalview/ws/dbsources/PfamSeed.java +++ b/src/jalview/ws/dbsources/PfamSeed.java @@ -37,7 +37,7 @@ public class PfamSeed extends Pfam implements DbSourceProxy * * @see jalview.ws.dbsources.Pfam#getPFAMURL() */ - protected String getPFAMURL() + protected String getXFAMURL() { return "http://pfam.sanger.ac.uk/family/alignment/download/format?alnType=seed&format=stockholm&order=t&case=l&gaps=default&entry="; }