import jalview.io.FileParse;
import jalview.io.HMMFile;
import jalview.util.MessageManager;
-import jalview.viewmodel.AlignmentViewport;
import jalview.ws.params.ArgumentI;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
-import java.util.Iterator;
import java.util.List;
/**
@Override
public void run()
{
- if (params == null)
+ if (params == null || params.isEmpty())
{
Cache.log.error("No parameters to HMMBuild!|");
return;
{
hmmFile = createTempFile("hmm", ".hmm");
alignmentFile = createTempFile("output", ".sto");
- List<SequenceI> seqs = ac.getSequences();
- List<SequenceI> copy = new ArrayList<>();
- copy.addAll(seqs);
if (ac instanceof Alignment)
{
}
}
- /*
- * copy over sequences, excluding hmm consensus sequences
- * hmm sequences are also deleted in preparation for
- * re-adding them when recalculated; Information annotation is not
- * deleted, it will be updated to reference the new hmm sequence
- * by InformationThread.findOrCreateAnnotation
- */
- Iterator<SequenceI> it = copy.iterator();
- while (it.hasNext())
+ deleteHmmSequences(ac);
+
+ List<SequenceI> copy = new ArrayList<>();
+ if (ac instanceof Alignment)
{
- SequenceI seq = it.next();
- if (seq.isHMMConsensusSequence())
+ copy.addAll(ac.getSequences());
+ }
+ else
+ {
+ SequenceI[] sel = ((SequenceGroup) ac)
+ .getSelectionAsNewSequences((AlignmentI) ac.getContext());
+ for (SequenceI seq : sel)
{
- alignment.deleteSequence(seq);
- it.remove();
+ copy.add(seq);
}
}
exportStockholm(copyArray, alignmentFile, ac);
- recoverSequences(sequencesHash, seqs.toArray(new SequenceI[] {}));
+ recoverSequences(sequencesHash, copy.toArray(new SequenceI[] {}));
boolean ran = runCommand(alignmentFile, hmmFile, ac);
if (!ran)
}
/**
+ * A helper method that deletes any HMM consensus sequence from the given
+ * collection, and from the parent alignment if <code>ac</code> is a subgroup
+ *
+ * @param ac
+ */
+ void deleteHmmSequences(AnnotatedCollectionI ac)
+ {
+ SequenceI hmmSeq = ac.getHmmConsensus();
+ if (hmmSeq != null)
+ {
+ if (ac instanceof SequenceGroup)
+ {
+ ((SequenceGroup) ac).deleteSequence(hmmSeq, false);
+ AnnotatedCollectionI context = ac.getContext();
+ if (context != null && context instanceof AlignmentI)
+ {
+ ((AlignmentI) context).deleteSequence(hmmSeq);
+ }
+ }
+ else
+ {
+ ((AlignmentI) ac).deleteSequence(hmmSeq);
+ }
+ }
+ }
+
+ /**
* Constructs and executes the hmmbuild command as a separate process
*
* @param sequencesFile
* 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 align frame title with _HMM appended (if title is not too long)
* - else "Alignment_HMM"
*/
String name = "";
{
HMMFile file = new HMMFile(
new FileParse(hmmFile.getAbsolutePath(), DataSourceType.FILE));
- SequenceI[] seqs = file.getSeqsAsArray();
- SequenceI hmmSeq = seqs[0];
- hmmSeq.createDatasetSequence();
+ SequenceI hmmSeq = file.getHMM().getConsensusSequence();
+
if (ac instanceof SequenceGroup)
{
SequenceGroup grp = (SequenceGroup) ac;
- hmmSeq.insertCharAt(0, ac.getStartRes(), '-');
+ char gapChar = alignment.getGapCharacter();
+ hmmSeq.insertCharAt(0, ac.getStartRes(), gapChar);
hmmSeq.insertCharAt(ac.getEndRes() + 1,
- alignment.getWidth() - ac.getEndRes() - 1, '-');
- hmmSeq.updateHMMMapping();
+ alignment.getWidth() - ac.getEndRes() - 1, gapChar);
SequenceI topSeq = grp.getSequencesInOrder(alignment)[0];
int topIndex = alignment.findIndex(topSeq);
alignment.insertSequenceAt(topIndex, hmmSeq);