Clover icon

jalviewX

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

File ColourSchemeLoader.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
56% of files have more coverage

Code metrics

14
42
1
1
145
89
10
0.24
42
1
10

Classes

Class Line # Actions
ColourSchemeLoader 32 42 10 57
0.00%
 

Contributing tests

No tests hitting this source file were found.

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.binding.JalviewUserColours;
24   
25    import java.awt.Color;
26    import java.io.File;
27    import java.io.FileInputStream;
28    import java.io.InputStreamReader;
29   
30    import org.exolab.castor.xml.Unmarshaller;
31   
 
32    public class ColourSchemeLoader
33    {
34   
35    /**
36    * Loads a user defined colour scheme from file. The file should contain a
37    * definition of residue colours in XML format as defined in
38    * JalviewUserColours.xsd.
39    *
40    * @param filePath
41    *
42    * @return
43    */
 
44  0 toggle public static UserColourScheme loadColourScheme(String filePath)
45    {
46  0 UserColourScheme ucs = null;
47  0 Color[] newColours = null;
48  0 File file = new File(filePath);
49  0 try
50    {
51  0 InputStreamReader in = new InputStreamReader(
52    new FileInputStream(file), "UTF-8");
53   
54  0 jalview.schemabinding.version2.JalviewUserColours jucs = new jalview.schemabinding.version2.JalviewUserColours();
55   
56  0 org.exolab.castor.xml.Unmarshaller unmar = new org.exolab.castor.xml.Unmarshaller(
57    jucs);
58  0 jucs = (jalview.schemabinding.version2.JalviewUserColours) unmar
59    .unmarshal(in);
60   
61    /*
62    * non-case-sensitive colours are for 20 amino acid codes,
63    * B, Z, X and Gap
64    * optionally, lower-case alternatives for all except Gap
65    */
66  0 newColours = new Color[24];
67  0 Color[] lowerCase = new Color[23];
68  0 boolean caseSensitive = false;
69   
70  0 String name;
71  0 int index;
72  0 for (int i = 0; i < jucs.getColourCount(); i++)
73    {
74  0 name = jucs.getColour(i).getName();
75  0 if (ResidueProperties.aa3Hash.containsKey(name))
76    {
77  0 index = ResidueProperties.aa3Hash.get(name).intValue();
78    }
79    else
80    {
81  0 index = ResidueProperties.aaIndex[name.charAt(0)];
82    }
83  0 if (index == -1)
84    {
85  0 continue;
86    }
87   
88  0 Color color = new Color(
89    Integer.parseInt(jucs.getColour(i).getRGB(), 16));
90  0 if (name.toLowerCase().equals(name))
91    {
92  0 caseSensitive = true;
93  0 lowerCase[index] = color;
94    }
95    else
96    {
97  0 newColours[index] = color;
98    }
99    }
100   
101    /*
102    * instantiate the colour scheme
103    */
104  0 ucs = new UserColourScheme(newColours);
105  0 ucs.setName(jucs.getSchemeName());
106  0 if (caseSensitive)
107    {
108  0 ucs.setLowerCaseColours(lowerCase);
109    }
110    } catch (Exception ex)
111    {
112    // Could be old Jalview Archive format
113  0 try
114    {
115  0 InputStreamReader in = new InputStreamReader(
116    new FileInputStream(file), "UTF-8");
117   
118  0 jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours();
119   
120  0 jucs = JalviewUserColours.unmarshal(in);
121   
122  0 newColours = new Color[jucs.getColourCount()];
123   
124  0 for (int i = 0; i < 24; i++)
125    {
126  0 newColours[i] = new Color(
127    Integer.parseInt(jucs.getColour(i).getRGB(), 16));
128    }
129  0 ucs = new UserColourScheme(newColours);
130  0 ucs.setName(jucs.getSchemeName());
131    } catch (Exception ex2)
132    {
133  0 ex2.printStackTrace();
134    }
135   
136  0 if (newColours == null)
137    {
138  0 System.out.println("Error loading User ColourFile\n" + ex);
139    }
140    }
141   
142  0 return ucs;
143    }
144   
145    }