1 package jalview.schemes;
3 import jalview.binding.JalviewUserColours;
7 import java.io.FileInputStream;
8 import java.io.InputStreamReader;
10 import org.exolab.castor.xml.Unmarshaller;
12 public class ColourSchemeLoader
16 * Loads a user defined colour scheme from file. The file should contain a
17 * definition of residue colours in XML format as defined in
18 * JalviewUserColours.xsd.
24 public static UserColourScheme loadColourScheme(String filePath)
26 UserColourScheme ucs = null;
27 Color[] newColours = null;
28 File file = new File(filePath);
31 InputStreamReader in = new InputStreamReader(
32 new FileInputStream(file), "UTF-8");
34 jalview.schemabinding.version2.JalviewUserColours jucs = new jalview.schemabinding.version2.JalviewUserColours();
36 org.exolab.castor.xml.Unmarshaller unmar = new org.exolab.castor.xml.Unmarshaller(
38 jucs = (jalview.schemabinding.version2.JalviewUserColours) unmar
42 * non-case-sensitive colours are for 20 amino acid codes,
44 * optionally, lower-case alternatives for all except Gap
46 newColours = new Color[24];
47 Color[] lowerCase = new Color[23];
48 boolean caseSensitive = false;
52 for (int i = 0; i < jucs.getColourCount(); i++)
54 name = jucs.getColour(i).getName();
55 if (ResidueProperties.aa3Hash.containsKey(name))
57 index = ResidueProperties.aa3Hash.get(name).intValue();
61 index = ResidueProperties.aaIndex[name.charAt(0)];
68 Color color = new Color(Integer.parseInt(jucs.getColour(i)
70 if (name.toLowerCase().equals(name))
73 lowerCase[index] = color;
77 newColours[index] = color;
82 * instantiate the colour scheme
84 ucs = new UserColourScheme(newColours);
85 ucs.setName(jucs.getSchemeName());
88 ucs.setLowerCaseColours(lowerCase);
90 } catch (Exception ex)
92 // Could be old Jalview Archive format
95 InputStreamReader in = new InputStreamReader(new FileInputStream(
98 jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours();
100 jucs = JalviewUserColours.unmarshal(in);
102 newColours = new Color[jucs.getColourCount()];
104 for (int i = 0; i < 24; i++)
106 newColours[i] = new Color(Integer.parseInt(jucs.getColour(i)
109 ucs = new UserColourScheme(newColours);
110 ucs.setName(jucs.getSchemeName());
111 } catch (Exception ex2)
113 ex2.printStackTrace();
116 if (newColours == null)
118 System.out.println("Error loading User ColourFile\n" + ex);