*/
public static float completeInformation(AlignmentAnnotation information,
ProfilesI profiles, int startCol, int endCol, long nseq,
- Float currentMax)
+ float currentMax)
{
// long now = System.currentTimeMillis();
if (information == null || information.annotations == null
return 0;
}
- Float max = 0f;
+ float max = 0f;
+ SequenceI hmmSeq = information.sequenceRef;
+ HiddenMarkovModel hmm = hmmSeq.getHMM();
- for (int i = startCol; i < endCol; i++)
+ for (int column = startCol; column < endCol; column++)
{
- ProfileI profile = profiles.get(i);
+ ProfileI profile = profiles.get(column);
if (profile == null)
{
/*
* happens if sequences calculated over were
* shorter than alignment width
*/
- information.annotations[i] = null;
- return 0;
+ information.annotations[column] = null;
+ return 0f;
}
- SequenceI hmmSeq = information.sequenceRef;
-
- HiddenMarkovModel hmm = hmmSeq.getHMM();
-
- float value = hmm.getInformationContent(i);
-
- if (value > max)
+ float value = hmm.getInformationContent(column);
+ if (!Float.isNaN(value))
{
- max = value;
+ max = Math.max(max, value);
}
- String description = value + " bits";
- information.annotations[i] = new Annotation(
+ String description = Float.isNaN(value) ? null
+ : String.format("%.4f bits", value);
+ information.annotations[column] = new Annotation(
Character.toString(Character
- .toUpperCase(hmm.getConsensusAtAlignColumn(i))),
+ .toUpperCase(hmm.getConsensusAtAlignColumn(column))),
description, ' ', value);
}
- if (max > currentMax)
- {
- information.graphMax = max;
- return max;
- }
- else
- {
- information.graphMax = currentMax;
- return currentMax;
- }
+
+ max = Math.max(max, currentMax);
+ information.graphMax = max;
+ return max;
}
/**
package jalview.hmmer;
import jalview.api.AlignViewportI;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.gui.AlignFrame;
import jalview.gui.AlignViewport;
+import jalview.gui.AlignmentPanel;
import jalview.gui.JvOptionPane;
import jalview.io.DataSourceType;
import jalview.io.FileParse;
import jalview.io.HMMFile;
import jalview.util.MessageManager;
+import jalview.workers.InformationThread;
import jalview.ws.params.ArgumentI;
import java.io.File;
if (alignment != null)
{
- runHMMBuild(null);
+ // alignment.findOrCreateAnnotation("", HMMBUILD, autoCalc, seqRef,
+ // groupRef);
+ runHMMBuild(alignment);
}
if (alignment == null)
alignment = viewport.getAlignment();
}
- for (SequenceGroup grp : groups)
+ for (AnnotatedCollectionI grp : groups)
{
runHMMBuild(grp);
}
{
if (af != null)
{
+ viewport.updateInformation(af.alignPanel);
af.buildColourMenu(); // enable HMMER colour schemes
af.setProgressBar("", msgID);
}
*
* @param grp
*/
- private void runHMMBuild(SequenceGroup group)
+ private void runHMMBuild(AnnotatedCollectionI ac)
{
- if (alignment == null && group == null)
+ if (ac == null)
{
JOptionPane.showMessageDialog(af,
MessageManager.getString("warn.no_sequence_data"));
alignmentFile = createTempFile("output", ".sto");
SequenceI[] array;
List<SequenceI> hmmSeqs = null;
- if (group != null)
+ hmmSeqs = ac.getHMMConsensusSequences();
+ if (ac instanceof SequenceGroup)
{
- hmmSeqs = group.getHMMConsensusSequences();
- array = group.getSelectionAsNewSequences(alignment);
+ array = ((SequenceGroup) ac)
+ .getSelectionAsNewSequences(alignment);
}
else
{
- hmmSeqs = alignment.getHMMConsensusSequences();
+ AlignmentI al = (Alignment) ac;
// todo pad gaps in an unaligned SequenceGroup as well?
- if (!alignment.isAligned())
+ if (!al.isAligned())
{
- alignment.padGaps();
+ al.padGaps();
}
- array = alignment.getSequencesArray();
+ array = al.getSequencesArray();
}
if (array.length < 1)
}
/*
- * copy over sequences excluding hmm consensus sequences
+ * copy over sequences, excluding hmm consensus sequences
+ * hmm sequences and their Information annotation are also deleted
+ * in preparation for re-adding them when recalculated
*/
SequenceI[] newArr = new SequenceI[array.length - hmmSeqs.size()];
int index = 0;
{
if (seq.isHMMConsensusSequence())
{
+ AlignmentAnnotation[] seqAnnotations = seq
+ .getAnnotation();
+ if (seqAnnotations != null)
+ {
+ for (AlignmentAnnotation ann : seqAnnotations)
+ {
+ if (InformationThread.HMM_CALC_ID.equals(ann.getCalcId()))
+ {
+ alignment.deleteAnnotation(ann);
+ }
+ }
+ }
alignment.deleteSequence(seq);
}
else
stashSequences(newArr);
exportStockholm(newArr, alignmentFile,
- group != null ? group : alignment);
+ ac != null ? ac : alignment);
recoverSequences(array);
- boolean ran = runCommand(alignmentFile, hmmFile, group);
+ boolean ran = runCommand(alignmentFile, hmmFile, ac);
if (!ran)
{
return;
}
- importData(hmmFile, group);
+ importData(hmmFile, ac);
} catch (Exception e)
{
e.printStackTrace();
/**
* Constructs and executes the hmmbuild command as a separate process
*
- * @param sequences
+ * @param sequencesFile
* the alignment from which the HMM is built
- * @param hmm
+ * @param hmmFile
* the output file to which the HMM is written
* @param group
- * (optional) group for which the hmm is generated
+ * alignment or group for which the hmm is generated
*
* @return
* @throws IOException
- * @throws InterruptedException
*/
- private boolean runCommand(File sequences, File hmm, SequenceGroup group)
- throws IOException, InterruptedException
+ private boolean runCommand(File sequencesFile, File hmmFile,
+ AnnotatedCollectionI group) throws IOException
{
-
String cmd = getCommandPath(HMMBUILD);
if (cmd == null)
{
- return false;
+ return false; // executable not found
}
List<String> args = new ArrayList<>();
args.add(cmd);
- String name = null;
+
+ /*
+ * HMM name (will be given to consensus sequence) is
+ * - as specified by an input parameter if set
+ * - else group name with _HMM appended (if for a group)
+ * - else align fame title with _HMM appended (if title is not too long)
+ * - else "Alignment_HMM"
+ */
+ String name = "";
if (params != null)
{
switch (argName)
{
case "HMM Name":
- name = arg.getValue();
- name = name.trim();
+ name = arg.getValue().trim();
break;
case "Use Reference Annotation":
args.add("--hand");
}
}
- if (group != null)
+ if (group instanceof SequenceGroup)
{
- name = group.getName() + "_HMM";
+ name = ((SequenceGroup) group).getName() + "_HMM";
}
- if (name == null || "".equals(name))
+ if ("".equals(name))
{
- if (af != null)
+ if (af != null && af.getTitle().length() < 15)
{
- if (af.getTitle().length() < 15)
- {
- name = af.getTitle();
- }
+ name = af.getTitle();
}
- if (name == null || "".equals(name))
+ else
{
- name = "Alignment";
+ name = "Alignment_HMM";
}
-
}
args.add("-n");
args.add(ARG_DNA);
}
- args.add(hmm.getAbsolutePath());
- args.add(sequences.getAbsolutePath());
+ args.add(hmmFile.getAbsolutePath());
+ args.add(sequencesFile.getAbsolutePath());
return runCommand(args);
}
* or group for which it was generated
*
* @param hmmFile
- * @oparam group (optional) the group for which the hmm was generated
+ * @param ac
+ * (optional) the group for which the hmm was generated
* @throws IOException
- * @throws InterruptedException
*/
- private void importData(File hmmFile, SequenceGroup group)
- throws IOException, InterruptedException
+ private void importData(File hmmFile, AnnotatedCollectionI ac)
+ throws IOException
{
HMMFile file = new HMMFile(
new FileParse(hmmFile.getAbsolutePath(), DataSourceType.FILE));
SequenceI[] seqs = file.getSeqsAsArray();
SequenceI seq = seqs[0];
seq.createDatasetSequence();
- if (group != null)
+ if (ac instanceof SequenceGroup)
{
- seq.insertCharAt(0, group.getStartRes(), '-');
- seq.insertCharAt(group.getEndRes() + 1,
- alignment.getWidth() - group.getEndRes() - 1, '-');
+ SequenceGroup grp = (SequenceGroup) ac;
+ seq.insertCharAt(0, ac.getStartRes(), '-');
+ seq.insertCharAt(ac.getEndRes() + 1,
+ alignment.getWidth() - ac.getEndRes() - 1, '-');
seq.updateHMMMapping();
- SequenceI topSeq = group.getSequencesInOrder(alignment)[0];
+ SequenceI topSeq = grp.getSequencesInOrder(alignment)[0];
int topIndex = alignment.findIndex(topSeq);
alignment.insertSequenceAt(topIndex, seq);
- group.setSeqrep(seq);
- group.addSequence(seq, false);
+ ac.setSeqrep(seq);
+ grp.addSequence(seq, false);
}
else
{
AlignViewport viewport = af.getViewport();
if (viewport != null)
{
- viewport.alignmentChanged(viewport.getAlignPanel());
- viewport.getAlignPanel().adjustAnnotationHeight();
+ AlignmentPanel alignPanel = viewport.getAlignPanel();
+ viewport.alignmentChanged(alignPanel);
+ alignPanel.adjustAnnotationHeight();
viewport.updateSequenceIdColours();
- if (viewport.getAlignPanel().alignFrame.getSelectedHMM() == null)
+ if (alignPanel.alignFrame.getSelectedHMM() == null)
{
- viewport.getAlignPanel().alignFrame.setSelectedHMMSequence(seq);
+ alignPanel.alignFrame.setSelectedHMMSequence(seq);
}
}
}