| 1 |
|
package jalview.hmmer; |
| 2 |
|
|
| 3 |
|
import jalview.analysis.AlignmentSorter; |
| 4 |
|
import jalview.analysis.SeqsetUtils.SequenceInfo; |
| 5 |
|
import jalview.datamodel.Alignment; |
| 6 |
|
import jalview.datamodel.AlignmentI; |
| 7 |
|
import jalview.datamodel.AlignmentOrder; |
| 8 |
|
import jalview.datamodel.AlignmentView; |
| 9 |
|
import jalview.datamodel.HiddenColumns; |
| 10 |
|
import jalview.datamodel.HiddenMarkovModel; |
| 11 |
|
import jalview.datamodel.SequenceI; |
| 12 |
|
import jalview.gui.AlignFrame; |
| 13 |
|
import jalview.gui.Desktop; |
| 14 |
|
import jalview.gui.JvOptionPane; |
| 15 |
|
import jalview.gui.SplitFrame; |
| 16 |
|
import jalview.io.DataSourceType; |
| 17 |
|
import jalview.io.StockholmFile; |
| 18 |
|
import jalview.util.FileUtils; |
| 19 |
|
import jalview.util.MessageManager; |
| 20 |
|
import jalview.viewmodel.seqfeatures.FeatureRendererSettings; |
| 21 |
|
import jalview.ws.params.ArgumentI; |
| 22 |
|
|
| 23 |
|
import java.io.File; |
| 24 |
|
import java.io.IOException; |
| 25 |
|
import java.util.ArrayList; |
| 26 |
|
import java.util.Hashtable; |
| 27 |
|
import java.util.List; |
| 28 |
|
import java.util.Map; |
| 29 |
|
|
| 30 |
|
import javax.swing.JInternalFrame; |
| 31 |
|
|
| |
|
| 0% |
Uncovered Elements: 144 (144) |
Complexity: 27 |
Complexity Density: 0.26 |
|
| 32 |
|
public class HMMAlign extends HmmerCommand |
| 33 |
|
{ |
| 34 |
|
static final String HMMALIGN = "hmmalign"; |
| 35 |
|
|
| 36 |
|
private final AlignmentI dataset; |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
@param |
| 42 |
|
@param |
| 43 |
|
|
| |
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 44 |
0 |
public HMMAlign(AlignFrame af, List<ArgumentI> args)... |
| 45 |
|
{ |
| 46 |
0 |
super(af, args); |
| 47 |
0 |
if (alignment.getDataset() != null) |
| 48 |
|
{ |
| 49 |
0 |
dataset = alignment.getDataset(); |
| 50 |
|
} |
| 51 |
|
else |
| 52 |
|
{ |
| 53 |
0 |
dataset = null; |
| 54 |
|
} |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| |
|
| 0% |
Uncovered Elements: 34 (34) |
Complexity: 3 |
Complexity Density: 0.09 |
|
| 64 |
0 |
@Override... |
| 65 |
|
public void run() |
| 66 |
|
{ |
| 67 |
0 |
HiddenMarkovModel hmm = getHmmProfile(); |
| 68 |
|
|
| 69 |
0 |
long msgId = System.currentTimeMillis(); |
| 70 |
0 |
af.setProgressBar(MessageManager.getString("status.running_hmmalign"), |
| 71 |
|
msgId); |
| 72 |
|
|
| 73 |
|
|
| 74 |
0 |
alignment.padGaps(); |
| 75 |
|
|
| 76 |
0 |
AlignmentView msa = af.gatherSequencesForAlignment(); |
| 77 |
0 |
SequenceI[][] subAlignments = msa.getVisibleContigs(alignment.getGapCharacter()); |
| 78 |
|
|
| 79 |
0 |
List<AlignmentOrder> allOrders = new ArrayList<>(); |
| 80 |
|
|
| 81 |
0 |
SequenceI[][] allResults = new SequenceI[subAlignments.length][]; |
| 82 |
0 |
int job = 0; |
| 83 |
0 |
for (SequenceI[] seqs : subAlignments) |
| 84 |
|
{ |
| 85 |
0 |
Map<String, SequenceInfo> sequencesHash = stashSequences(seqs); |
| 86 |
0 |
try |
| 87 |
|
{ |
| 88 |
0 |
File modelFile = FileUtils.createTempFile("hmm", ".hmm"); |
| 89 |
0 |
File alignmentFile = FileUtils.createTempFile("output", ".sto"); |
| 90 |
0 |
File resultFile = FileUtils.createTempFile("input", ".sto"); |
| 91 |
|
|
| 92 |
0 |
exportStockholm(seqs, alignmentFile.getAbsoluteFile(), null); |
| 93 |
0 |
exportHmm(hmm, modelFile.getAbsoluteFile()); |
| 94 |
|
|
| 95 |
0 |
boolean ran = runCommand(modelFile, alignmentFile, resultFile); |
| 96 |
0 |
if (!ran) |
| 97 |
|
{ |
| 98 |
0 |
JvOptionPane.showInternalMessageDialog(af, MessageManager |
| 99 |
|
.formatMessage("warn.command_failed", "hmmalign")); |
| 100 |
0 |
return; |
| 101 |
|
} |
| 102 |
|
|
| 103 |
0 |
SequenceI[] result = importData(resultFile, allOrders); |
| 104 |
0 |
recoverSequences(sequencesHash, result); |
| 105 |
0 |
allResults[job] = result; |
| 106 |
0 |
modelFile.delete(); |
| 107 |
0 |
alignmentFile.delete(); |
| 108 |
0 |
resultFile.delete(); |
| 109 |
|
} catch (IOException e) |
| 110 |
|
{ |
| 111 |
0 |
e.printStackTrace(); |
| 112 |
|
} |
| 113 |
0 |
job++; |
| 114 |
|
} |
| 115 |
|
|
| 116 |
0 |
String title = "hmmalign to " + hmm.getConsensusSequence().getName(); |
| 117 |
0 |
displayResults(allResults, allOrders, msa, title); |
| 118 |
|
|
| 119 |
0 |
af.setProgressBar("", msgId); |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
@param |
| 127 |
|
|
| 128 |
|
@param |
| 129 |
|
|
| 130 |
|
@param |
| 131 |
|
|
| 132 |
|
@return |
| 133 |
|
@throws |
| 134 |
|
|
| |
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 4 |
Complexity Density: 0.27 |
|
| 135 |
0 |
private boolean runCommand(File modelFile, File alignmentFile,... |
| 136 |
|
File resultFile) throws IOException |
| 137 |
|
{ |
| 138 |
0 |
String command = getCommandPath(HMMALIGN); |
| 139 |
0 |
if (command == null) |
| 140 |
|
{ |
| 141 |
0 |
return false; |
| 142 |
|
} |
| 143 |
0 |
List<String> args = new ArrayList<>(); |
| 144 |
0 |
args.add(command); |
| 145 |
|
|
| 146 |
0 |
if (params != null) |
| 147 |
|
{ |
| 148 |
0 |
for (ArgumentI arg : params) |
| 149 |
|
{ |
| 150 |
0 |
String name = arg.getName(); |
| 151 |
0 |
if (MessageManager.getString("label.trim_termini").equals(name)) |
| 152 |
|
{ |
| 153 |
0 |
args.add(ARG_TRIM); |
| 154 |
|
} |
| 155 |
|
} |
| 156 |
|
} |
| 157 |
0 |
args.add("-o"); |
| 158 |
0 |
args.add(getFilePath(resultFile, true)); |
| 159 |
0 |
args.add(getFilePath(modelFile, true)); |
| 160 |
0 |
args.add(getFilePath(alignmentFile, true)); |
| 161 |
|
|
| 162 |
0 |
return runCommand(args); |
| 163 |
|
} |
| 164 |
|
|
| 165 |
|
|
| 166 |
|
|
| 167 |
|
|
| 168 |
|
@param |
| 169 |
|
@param |
| 170 |
|
|
| 171 |
|
|
| 172 |
|
@return |
| 173 |
|
@throws |
| 174 |
|
|
| |
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 175 |
0 |
private SequenceI[] importData(File resultFile,... |
| 176 |
|
List<AlignmentOrder> allOrders) throws IOException |
| 177 |
|
{ |
| 178 |
0 |
StockholmFile file = new StockholmFile(getFilePath(resultFile, false), |
| 179 |
|
DataSourceType.FILE); |
| 180 |
0 |
SequenceI[] result = file.getSeqsAsArray(); |
| 181 |
0 |
AlignmentOrder msaorder = new AlignmentOrder(result); |
| 182 |
0 |
AlignmentSorter.recoverOrder(result); |
| 183 |
0 |
allOrders.add(msaorder); |
| 184 |
|
|
| 185 |
0 |
return result; |
| 186 |
|
} |
| 187 |
|
|
| 188 |
|
|
| 189 |
|
|
| 190 |
|
|
| 191 |
|
@param |
| 192 |
|
|
| 193 |
|
@param |
| 194 |
|
@param |
| 195 |
|
@param |
| 196 |
|
|
| |
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
| 197 |
0 |
private void displayResults(SequenceI[][] allResults,... |
| 198 |
|
List<AlignmentOrder> allOrders, AlignmentView msa, String title) |
| 199 |
|
{ |
| 200 |
0 |
AlignmentOrder[] arrOrders = allOrders |
| 201 |
|
.toArray(new AlignmentOrder[allOrders.size()]); |
| 202 |
0 |
Object[] newview = msa.getUpdatedView(allResults, arrOrders, |
| 203 |
|
alignment.getGapCharacter()); |
| 204 |
0 |
SequenceI[] seqs = (SequenceI[]) newview[0]; |
| 205 |
0 |
HiddenColumns hidden = (HiddenColumns) newview[1]; |
| 206 |
0 |
Alignment al = new Alignment(seqs); |
| 207 |
0 |
al.setProperty("Alignment Program", "hmmalign"); |
| 208 |
0 |
if (dataset != null) |
| 209 |
|
{ |
| 210 |
0 |
al.setDataset(dataset); |
| 211 |
|
} |
| 212 |
|
|
| 213 |
0 |
displayInNewFrame(al, allOrders, hidden, title); |
| 214 |
|
} |
| 215 |
|
|
| 216 |
|
|
| 217 |
|
|
| 218 |
|
|
| 219 |
|
@param |
| 220 |
|
|
| 221 |
|
@param |
| 222 |
|
|
| 223 |
|
|
| 224 |
|
@param |
| 225 |
|
|
| 226 |
|
@param |
| 227 |
|
|
| |
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 7 |
Complexity Density: 0.32 |
|
| 228 |
0 |
private void displayInNewFrame(AlignmentI al,... |
| 229 |
|
List<AlignmentOrder> alorders, HiddenColumns hidden, String title) |
| 230 |
|
{ |
| 231 |
0 |
AlignFrame alignFrame = new AlignFrame(al, hidden, AlignFrame.DEFAULT_WIDTH, |
| 232 |
|
AlignFrame.DEFAULT_HEIGHT); |
| 233 |
0 |
alignFrame.setTitle(title); |
| 234 |
|
|
| 235 |
0 |
FeatureRendererSettings featureSettings = af.getFeatureRenderer() |
| 236 |
|
.getSettings(); |
| 237 |
|
|
| 238 |
0 |
alignFrame.getFeatureRenderer().transferSettings(featureSettings); |
| 239 |
|
|
| 240 |
0 |
addSortByMenuItems(alignFrame, alorders); |
| 241 |
|
|
| 242 |
|
|
| 243 |
|
|
| 244 |
|
|
| 245 |
|
|
| 246 |
|
|
| 247 |
|
|
| 248 |
0 |
AlignFrame requestedBy = this.af; |
| 249 |
0 |
if (requestedBy != null && requestedBy.getSplitViewContainer() != null |
| 250 |
|
&& requestedBy.getSplitViewContainer() |
| 251 |
|
.getComplement(requestedBy) != null) |
| 252 |
|
{ |
| 253 |
0 |
AlignmentI complement = requestedBy.getSplitViewContainer() |
| 254 |
|
.getComplement(requestedBy); |
| 255 |
0 |
String complementTitle = requestedBy.getSplitViewContainer() |
| 256 |
|
.getComplementTitle(requestedBy); |
| 257 |
|
|
| 258 |
|
|
| 259 |
0 |
AlignmentI copyComplement = new Alignment(complement); |
| 260 |
|
|
| 261 |
0 |
copyComplement.setGapCharacter(complement.getGapCharacter()); |
| 262 |
|
|
| 263 |
0 |
copyComplement.setDataset(complement.getDataset()); |
| 264 |
0 |
copyComplement.alignAs(al); |
| 265 |
0 |
if (copyComplement.getHeight() > 0) |
| 266 |
|
{ |
| 267 |
0 |
alignFrame.setTitle(this.af.getTitle()); |
| 268 |
0 |
AlignFrame af2 = new AlignFrame(copyComplement, |
| 269 |
|
AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); |
| 270 |
0 |
af2.setTitle(complementTitle); |
| 271 |
0 |
String linkedTitle = MessageManager |
| 272 |
|
.getString("label.linked_view_title"); |
| 273 |
0 |
JInternalFrame splitFrame = new SplitFrame( |
| 274 |
0 |
al.isNucleotide() ? alignFrame : af2, al.isNucleotide() ? af2 : alignFrame); |
| 275 |
0 |
Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1); |
| 276 |
0 |
return; |
| 277 |
|
} |
| 278 |
|
} |
| 279 |
|
|
| 280 |
|
|
| 281 |
|
|
| 282 |
|
|
| 283 |
0 |
Desktop.addInternalFrame(alignFrame, alignFrame.getTitle(), AlignFrame.DEFAULT_WIDTH, |
| 284 |
|
AlignFrame.DEFAULT_HEIGHT); |
| 285 |
|
} |
| 286 |
|
|
| 287 |
|
|
| 288 |
|
|
| 289 |
|
|
| 290 |
|
@param |
| 291 |
|
@param |
| 292 |
|
|
| |
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 8 |
Complexity Density: 0.47 |
|
| 293 |
0 |
protected void addSortByMenuItems(AlignFrame alignFrame,... |
| 294 |
|
List<AlignmentOrder> alorders) |
| 295 |
|
{ |
| 296 |
|
|
| 297 |
0 |
if (alorders.size() == 1) |
| 298 |
|
{ |
| 299 |
0 |
alignFrame.addSortByOrderMenuItem("hmmalign" + " Ordering", alorders.get(0)); |
| 300 |
|
} |
| 301 |
|
else |
| 302 |
|
{ |
| 303 |
|
|
| 304 |
0 |
List<String> names = new ArrayList<>(); |
| 305 |
0 |
for (int i = 0, l = alorders.size(); i < l; i++) |
| 306 |
|
{ |
| 307 |
0 |
String orderName = " Region " + i; |
| 308 |
0 |
int j = i + 1; |
| 309 |
|
|
| 310 |
0 |
while (j < l) |
| 311 |
|
{ |
| 312 |
0 |
if (alorders.get(i).equals(alorders.get(j))) |
| 313 |
|
{ |
| 314 |
0 |
alorders.remove(j); |
| 315 |
0 |
l--; |
| 316 |
0 |
orderName += "," + j; |
| 317 |
|
} |
| 318 |
|
else |
| 319 |
|
{ |
| 320 |
0 |
j++; |
| 321 |
|
} |
| 322 |
|
} |
| 323 |
|
|
| 324 |
0 |
if (i == 0 && j == 1) |
| 325 |
|
{ |
| 326 |
0 |
names.add(""); |
| 327 |
|
} |
| 328 |
|
else |
| 329 |
|
{ |
| 330 |
0 |
names.add(orderName); |
| 331 |
|
} |
| 332 |
|
} |
| 333 |
0 |
for (int i = 0, l = alorders.size(); i < l; i++) |
| 334 |
|
{ |
| 335 |
0 |
alignFrame.addSortByOrderMenuItem("hmmalign" + (names.get(i)) + " Ordering", |
| 336 |
|
alorders.get(i)); |
| 337 |
|
} |
| 338 |
|
} |
| 339 |
|
} |
| 340 |
|
} |