/**
* Returns all HMM consensus sequences. This will not return real sequences
- * with HMMs. If remove is set to true, the consensus sequences will be
- * removed from the alignment.
+ * with HMMs.
*/
- @Override // TODO make this more efficient.
- public List<SequenceI> getHMMConsensusSequences(boolean remove)
+ @Override
+ public List<SequenceI> getHMMConsensusSequences()
{
List<SequenceI> seqs = new ArrayList<>();
- int position = 0;
- int seqsRemoved = 0;
- boolean endReached = false;
- while (!endReached)
+ for (int position = 0; position < sequences.size(); position++)
{
SequenceI seq = sequences.get(position);
if (seq.isHMMConsensusSequence())
{
- if (remove)
- {
- sequences.remove(position);
- seqsRemoved++;
- seq.setPreviousPosition(seqsRemoved + position - 1);
- }
- else
- {
- position++;
- }
seqs.add(seq);
}
- else
- {
- position++;
- }
-
- if (position >= sequences.size())
- {
- endReached = true;
- }
}
return seqs;
}
private char[] sequence;
- int previousPosition;
-
String description;
int start;
hasInfo = true;
}
- @Override
- public int getPreviousPosition()
- {
- return previousPosition;
- }
-
- @Override
- public void setPreviousPosition(int previousPosition)
- {
- this.previousPosition = previousPosition;
- }
-
/**
* {@inheritDoc}
*/
boolean isNucleotide();
/**
- * Returns all HMM consensus sequences.
+ * Returns all HMM consensus sequences (possibly an empty list)
*
- * @param remove
- * If true, remove all HMM consensus sequences from the alignment.
* @return
*/
- List<SequenceI> getHMMConsensusSequences(boolean remove);
+ List<SequenceI> getHMMConsensusSequences();
}
public boolean isShowHMMSequenceLogo()
{
- // TODO Auto-generated method stub
return showHMMSequenceLogo;
}
public boolean isNormaliseHMMSequenceLogo()
{
- // TODO Auto-generated method stub
return normaliseHMMSequenceLogo;
}
/**
* Returns all HMM consensus sequences. This will not return real sequences
- * with HMMs. If remove is set to true, the consensus sequences will be
- * removed from the alignment.
+ * with HMMs.
*/
- @Override // TODO make this more efficient.
- public List<SequenceI> getHMMConsensusSequences(boolean remove)
+ @Override
+ public List<SequenceI> getHMMConsensusSequences()
{
List<SequenceI> seqs = new ArrayList<>();
- int position = 0;
- int seqsRemoved = 0;
- boolean endReached = false;
- while (!endReached)
+ for (int position = 0; position < sequences.size(); position++)
{
SequenceI seq = sequences.get(position);
if (seq.isHMMConsensusSequence())
{
- if (remove)
- {
- sequences.remove(position);
- seqsRemoved++;
- seq.setPreviousPosition(seqsRemoved + position - 1);
- }
- else
- {
- position++;
- }
seqs.add(seq);
}
- else
- {
- position++;
- }
-
- if (position >= sequences.size())
- {
- endReached = true;
- }
}
return seqs;
}
void setHasInfo(boolean status);
- int getPreviousPosition();
-
- void setPreviousPosition(int previousPosition);
-
/**
* Returns a (possibly empty) list of sequence features that overlap the given
* alignment column range, optionally restricted to one or more specified
try
{
SequenceI[] array;
- List<SequenceI> seqs = null;
+ List<SequenceI> hmmSeqs = null;
if (forGroup)
{
- seqs = group.getHMMConsensusSequences(true);
- if (seqs.size() > 0)
+ hmmSeqs = group.getHMMConsensusSequences();
+ if (hmmSeqs.size() > 0)
{
+ // todo why this test? means can't re-run hmmbuild on a group?
return;
}
array = group.getSelectionAsNewSequences(alignment);
}
else
{
- seqs = alignment.getHMMConsensusSequences(true);
+ hmmSeqs = alignment.getHMMConsensusSequences();
if (!alignment.isAligned())
{
alignment.padGaps();
}
return;
}
- SequenceI[] newArr = new SequenceI[array.length];
+
+ /*
+ * copy over sequences excluding hmm consensus sequences
+ */
+ SequenceI[] newArr = new SequenceI[array.length - hmmSeqs.size()];
int index = 0;
for (SequenceI seq : array)
{
- newArr[index] = new Sequence(seq);
- index++;
+ if (!seq.isHMMConsensusSequence())
+ {
+ newArr[index] = new Sequence(seq);
+ index++;
+ }
}
uniquifySequences(newArr);
long barID;
- SequenceI hmmSeq;
-
List<ArgumentI> params;
File hmmTemp = null;
hmm = af.getSelectedHMM();
}
- hmmSeq = af.getSelectedHMMSequence();
+ SequenceI hmmSeq = af.getSelectedHMMSequence();
barID = System.currentTimeMillis();
af.setProgressBar(MessageManager.getString("status.running_hmmsearch"),
barID);
}
try
{
- importData();
+ importData(hmmSeq);
} catch (IOException | InterruptedException e)
{
// TODO Auto-generated catch block
{
AlignmentI alignment = af.getViewport().getAlignment();
AlignmentI copy = new Alignment(alignment);
- copy.getHMMConsensusSequences(true);
+ List<SequenceI> hmms = copy.getHMMConsensusSequences();
+ for (SequenceI seq : hmms)
+ {
+ copy.deleteSequence(seq);
+ }
StockholmFile stoFile = new StockholmFile(copy);
stoFile.setSeqs(copy.getSequencesArray());
String alignmentString = stoFile.print();
/**
* Imports the data from the temporary file to which the output of hmmsearch
* is directed.
+ *
+ * @param hmmSeq
*/
- private void importData() throws IOException, InterruptedException
+ private void importData(SequenceI hmmSeq)
+ throws IOException, InterruptedException
{
BufferedReader br = new BufferedReader(
new FileReader(inputAlignmentTemp));
}
/**
- * Adds any HMM sequences removed before submitting the alignment as a job
- * back into the alignment.
- *
- * @param af
- */
- public void addHMMConsensusSequences(AlignFrame af)
- {
- AlignmentI al = af.getViewport().getAlignment();
- if (hmmSeqs == null || hmmSeqs.size() < 1)
- {
- return;
- }
- for (SequenceI seq : hmmSeqs)
- {
- Integer position = seq.getPreviousPosition();
- al.getSequences().add(position, seq);
- }
- af.getViewport().setAlignment(al);
- af.alignPanel.adjustAnnotationHeight();
- af.getViewport().updateSequenceIdColours();
- af.buildSortByAnnotationScoresMenu();
- }
-
- /**
* Returns the list of HMM sequences removed
*
* @return
updateInformation(ap);
List<SequenceI> hmmSequences;
- hmmSequences = alignment.getHMMConsensusSequences(false);
+ hmmSequences = alignment.getHMMConsensusSequences();
for (SequenceI seq : hmmSequences)
{
@Override
public void initInformation()
{
- for (SequenceI seq : alignment.getHMMConsensusSequences(false))
+ for (SequenceI seq : alignment.getHMMConsensusSequences())
{
if (!seq.hasHMMAnnotation())
{
- AlignmentAnnotation information;
- information = new AlignmentAnnotation(seq.getName(),
+ AlignmentAnnotation info = new AlignmentAnnotation(seq.getName(),
MessageManager.getString("label.information_description"),
new Annotation[1], 0f, 6.52f,
AlignmentAnnotation.BAR_GRAPH);
- information.hasText = true;
- information.autoCalculated = true;
- information.hasText = true;
- information.autoCalculated = false;
- information.sequenceRef = seq;
- information.setCalcId("HMM");
- this.information.add(information);
+ info.hasText = true;
+ info.autoCalculated = true;
+ info.hasText = true;
+ info.autoCalculated = false;
+ info.sequenceRef = seq;
+ info.setCalcId("HMM");
+ this.information.add(info);
hinformation.add(new Profiles(new ProfileI[1]));
- alignment.addAnnotation(information);
+ alignment.addAnnotation(info);
seq.updateHMMMapping();
seq.setHasInfo(true);
- seq.addAlignmentAnnotation(information);
+ seq.addAlignmentAnnotation(info);
}
}
-
}
// these should be extracted from the view model - style and settings for
return;
}
calcMan.notifyStart(this);
- long started = System.currentTimeMillis();
+ // long started = System.currentTimeMillis();
List<AlignmentAnnotation> information = getInformationAnnotations();
try
protected void computeInformation(AlignmentI alignment)
{
int width = alignment.getWidth();
- List<SequenceI> hmmSeqs = alignment.getHMMConsensusSequences(false);
+ List<SequenceI> hmmSeqs = alignment.getHMMConsensusSequences();
int index = 0;
for (SequenceI seq : hmmSeqs)
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
+import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.fail;
import jalview.bin.Jalview;
fail();
}
- AlignFrame frame = Desktop.getAlignFrames()[0];
- AlignmentI al = frame.getViewport().getAlignment();
+ AlignFrame fr = Desktop.getAlignFrames()[0];
+ AlignmentI al = fr.getViewport().getAlignment();
assertNotEquals(al, null);
- List<SequenceI> hmmSeqs = al.getHMMConsensusSequences(false);
- assertNotEquals(hmmSeqs, null);
-
+ List<SequenceI> hmmSeqs = al.getHMMConsensusSequences();
+ assertNotNull(hmmSeqs);
}
}