Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.schemes

File ColourSchemeProperty.java

 

Coverage histogram

../../img/srcFileCovDistChart8.png
19% of files have more coverage

Code metrics

12
20
4
1
155
55
11
0.55
5
4
2.75

Classes

Class Line # Actions
ColourSchemeProperty 40 20 11 9
0.7575%
 

Contributing tests

This file is covered by 98 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.schemes;
22   
23    import jalview.datamodel.AnnotatedCollectionI;
24    import jalview.util.ColorUtils;
25   
26    import java.awt.Color;
27   
28    /**
29    * ColourSchemeProperty binds names to hardwired colourschemes and tries to deal
30    * intelligently with mapping unknown names to user defined colourschemes (that
31    * exist or can be created from the string representation of the colourscheme
32    * name - either a hex RGB triplet or a named colour under java.awt.color ). The
33    * values of the colourscheme constants is important for callers of
34    * getColourName(int i), since it can be used to enumerate the set of built in
35    * colours. The FIRST_COLOUR and LAST_COLOUR symbols are provided for this.
36    *
37    * @author $author$
38    * @version $Revision$
39    */
 
40    public class ColourSchemeProperty
41    {
42   
43    /**
44    * Returns a colour scheme for the given name, with which the given data may
45    * be coloured. The name is not case-sensitive, and may be one of
46    * <ul>
47    * <li>any currently registered colour scheme; Jalview by default
48    * provides</li>
49    * <ul>
50    * <li>Clustal</li>
51    * <li>Blosum62</li>
52    * <li>% Identity</li>
53    * <li>Hydrophobic</li>
54    * <li>Zappo</li>
55    * <li>Taylor</li>
56    * <li>Helix Propensity</li>
57    * <li>Strand Propensity</li>
58    * <li>Turn Propensity</li>
59    * <li>Buried Index</li>
60    * <li>Nucleotide</li>
61    * <li>Purine/Pyrimidine</li>
62    * <li>T-Coffee Scores</li>
63    * <li>RNA Helices</li>
64    * </ul>
65    * <li>the name of a programmatically added colour scheme</li>
66    * <li>an AWT colour name e.g. red</li>
67    * <li>an AWT hex rgb colour e.g. ff2288</li>
68    * <li>residue colours list e.g. D,E=red;K,R,H=0022FF;c=yellow</li>
69    * </ul>
70    *
71    * If none of these formats is matched, the string is converted to a colour
72    * using a hashing algorithm. For name "None", returns null.
73    *
74    * @param forData
75    * @param name
76    * @return
77    */
 
78  371 toggle public static ColourSchemeI getColourScheme(AnnotatedCollectionI forData,
79    String name)
80    {
81  371 if (ResidueColourScheme.NONE.equalsIgnoreCase(name))
82    {
83  318 return null;
84   
85    }
86   
87    /*
88    * if this is the name of a registered colour scheme, just
89    * create a new instance of it
90    */
91  53 ColourSchemeI scheme = ColourSchemes.getInstance().getColourScheme(name,
92    forData, null);
93  53 if (scheme != null)
94    {
95  51 return scheme;
96    }
97   
98    /*
99    * try to parse the string as a residues colour scheme
100    * e.g. A=red;T,G=blue etc
101    * else parse the name as a colour specification
102    * e.g. "red" or "ff00ed",
103    * or failing that hash the name to a colour
104    */
105  2 UserColourScheme ucs = new UserColourScheme(name);
106  2 return ucs;
107    }
108   
109    public static Color rnaHelices[] = null;
110   
 
111  3 toggle public static void initRnaHelicesShading(int n)
112    {
113  3 int j = 0;
114  3 if (rnaHelices == null)
115    {
116  3 rnaHelices = new Color[n + 1];
117    }
118  0 else if (rnaHelices != null && rnaHelices.length <= n)
119    {
120  0 Color[] t = new Color[n + 1];
121  0 System.arraycopy(rnaHelices, 0, t, 0, rnaHelices.length);
122  0 j = rnaHelices.length;
123  0 rnaHelices = t;
124    }
125    else
126    {
127  0 return;
128    }
129    // Generate random colors and store
130  6 for (; j <= n; j++)
131    {
132  3 rnaHelices[j] = ColorUtils.generateRandomColor(Color.white);
133    }
134    }
135   
136    /**
137    * delete the existing cached RNA helices colours
138    */
 
139  9 toggle public static void resetRnaHelicesShading()
140    {
141  9 rnaHelices = null;
142    }
143   
144    /**
145    * Returns the name of the colour scheme (or "None" if it is null)
146    *
147    * @param cs
148    * @return
149    */
 
150  55 toggle public static String getColourName(ColourSchemeI cs)
151    {
152  55 return cs == null ? ResidueColourScheme.NONE : cs.getSchemeName();
153    }
154   
155    }