Clover icon

Coverage Report

  1. Project Clover database Fri Dec 6 2024 13:47:14 GMT
  2. Package jalview.ext.varna

File VarnaCommands.java

 

Coverage histogram

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

Code metrics

28
47
2
1
166
107
21
0.45
23.5
2
10.5

Classes

Class Line # Actions
VarnaCommands 40 47 21
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.ext.varna;
22   
23    import jalview.api.SequenceRenderer;
24    import jalview.datamodel.AlignmentI;
25    import jalview.datamodel.SequenceI;
26    import jalview.renderer.seqfeatures.FeatureColourFinder;
27    import jalview.structure.StructureMapping;
28    import jalview.structure.StructureSelectionManager;
29   
30    import java.awt.Color;
31    import java.util.ArrayList;
32   
33    /**
34    * Routines for generating Jmol commands for Jalview/Jmol binding another
35    * cruisecontrol test.
36    *
37    * @author JimP
38    *
39    */
 
40    public class VarnaCommands
41    {
42   
43    /**
44    * Jmol utility which constructs the commands to colour chains by the given
45    * alignment
46    *
47    */
 
48  0 toggle public static String[] getColourBySequenceCommand(
49    StructureSelectionManager ssm, String[] files,
50    SequenceI[][] sequence, SequenceRenderer sr,
51    FeatureColourFinder finder, AlignmentI alignment)
52    {
53  0 ArrayList<String> str = new ArrayList<String>();
54  0 StringBuffer command = new StringBuffer();
55   
56  0 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
57    {
58  0 StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
59   
60  0 if (mapping == null || mapping.length < 1)
61    {
62  0 continue;
63    }
64   
65  0 int lastPos = -1;
66  0 for (int s = 0; s < sequence[pdbfnum].length; s++)
67    {
68  0 for (int sp, m = 0; m < mapping.length; m++)
69    {
70  0 if (mapping[m].getSequence() == sequence[pdbfnum][s]
71    && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1)
72    {
73  0 SequenceI asp = alignment.getSequenceAt(sp);
74  0 for (int r = 0; r < asp.getLength(); r++)
75    {
76    // no mapping to gaps in sequence
77  0 if (jalview.util.Comparison.isGap(asp.getCharAt(r)))
78    {
79  0 continue;
80    }
81  0 int pos = mapping[m].getPDBResNum(asp.findPosition(r));
82   
83  0 if (pos < 1 || pos == lastPos)
84    {
85  0 continue;
86    }
87   
88  0 lastPos = pos;
89   
90  0 Color col = sr.getResidueColour(sequence[pdbfnum][s], r,
91    finder);
92   
93  0 String newSelcom = (mapping[m].getChain() != " "
94    ? ":" + mapping[m].getChain()
95    : "") + "/" + (pdbfnum + 1) + ".1" + ";color["
96    + col.getRed() + "," + col.getGreen() + ","
97    + col.getBlue() + "]";
98  0 if (command.length() > newSelcom.length() && command
99    .substring(command.length() - newSelcom.length())
100    .equals(newSelcom))
101    {
102  0 command = VarnaCommands.condenseCommand(command, pos);
103  0 continue;
104    }
105    // TODO: deal with case when buffer is too large for Jmol to parse
106    // - execute command and flush
107   
108  0 command.append(";");
109  0 if (command.length() > 51200)
110    {
111    // add another chunk
112  0 str.add(command.toString());
113  0 command.setLength(0);
114    }
115  0 command.append("select " + pos);
116  0 command.append(newSelcom);
117    }
118  0 break;
119    }
120    }
121    }
122    }
123    {
124    // add final chunk
125  0 str.add(command.toString());
126  0 command.setLength(0);
127    }
128  0 return str.toArray(new String[str.size()]);
129    }
130   
 
131  0 toggle public static StringBuffer condenseCommand(StringBuffer command, int pos)
132    {
133   
134    // work back to last 'select'
135  0 int p = command.length(), q = p;
136  0 do
137    {
138  0 p -= 6;
139  0 if (p < 1)
140    {
141  0 p = 0;
142    }
143  0 ;
144  ? } while ((q = command.indexOf("select", p)) == -1 && p > 0);
145   
146  0 StringBuffer sb = new StringBuffer(command.substring(0, q + 7));
147   
148  0 command = command.delete(0, q + 7);
149   
150  0 String start;
151   
152  0 if (command.indexOf("-") > -1)
153    {
154  0 start = command.substring(0, command.indexOf("-"));
155    }
156    else
157    {
158  0 start = command.substring(0, command.indexOf(":"));
159    }
160   
161  0 sb.append(start + "-" + pos + command.substring(command.indexOf(":")));
162   
163  0 return sb;
164    }
165   
166    }