import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
hiddenCols = cols;
}
+
@Override
- public Map<Integer, SequenceI> getHMMConsensusSequences(boolean remove)
+ public List<SequenceI> getHMMConsensusSequences(boolean remove)
{
- Map<Integer, SequenceI> seqs = new HashMap<>();
+ List<SequenceI> seqs = new ArrayList<>();
int position = 0;
- for (SequenceI seq : sequences)
+ int seqsRemoved = 0;
+ boolean endReached = false;
+
+ while (!endReached)
{
+ SequenceI seq = sequences.get(position);
if (seq.isHMMConsensusSequence())
{
- seqs.put(position, seq);
if (remove)
{
- sequences.set(position, null);
+ sequences.remove(position);
+ seqsRemoved++;
+ seq.setPreviousPosition(seqsRemoved + position - 1);
}
-
- }
- position++;
- }
- boolean endReached = false;
- int pos = 0;
- while (!endReached)
- {
- if (sequences.get(pos) == null)
- {
- sequences.remove(pos);
+ else
+ {
+ position++;
+ }
+ seqs.add(seq);
}
else
{
- pos++;
- }
- if (pos >= sequences.size())
- {
- endReached = true;
+ position++;
}
- }
-
- return seqs;
- }
- @Override
- public List<SequenceI> getHMMConsensusSequences()
- {
- List<SequenceI> seqs = new ArrayList<>();
- for (SequenceI seq : sequences)
- {
- if (seq.isHMMConsensusSequence())
+ if (position >= sequences.size())
{
- seqs.add(seq);
+ endReached = true;
}
}
return seqs;
public int[] getVisibleStartAndEndIndex(List<int[]> hiddenCols);
public void setHiddenColumns(HiddenColumns cols);
-
- public Map<Integer, SequenceI> getHMMConsensusSequences(boolean remove);
- public List<SequenceI> getHMMConsensusSequences();
+ public List<SequenceI> getHMMConsensusSequences(boolean remove);
private char[] sequence;
+ int previousPosition;
+
String description;
int start;
int end;
+ boolean hasInfo;
+
HiddenMarkovModel hmm;
boolean isHMMConsensusSequence = false;
this.isHMMConsensusSequence = isHMMConsensusSequence;
}
+ @Override
+ public boolean hasHMMAnnotation()
+ {
+ return hasInfo;
+ /*
+ if (annotation == null)
+ {
+ return false;
+ }
+
+ for (AlignmentAnnotation annot : annotation)
+ {
+ if (annot.label.contains("_HMM"))
+ {
+ return true;
+ }
+ }
+ return false;
+ */
+ }
+
+ @Override
+ public void setHasInfo(boolean status)
+ {
+ hasInfo = true;
+ }
+
+ @Override
+ public int getPreviousPosition()
+ {
+ return previousPosition;
+ }
+ @Override
+ public void setPreviousPosition(int previousPosition)
+ {
+ this.previousPosition = previousPosition;
+ }
}
boolean colourText = false;
- HiddenMarkovModel hmm;
-
/**
* True if the group is defined as a group on the alignment, false if it is
* just a selection.
endRes + 1, showSequenceLogo);
if (information != null)
{
- // _updateInformationRow(cnsns, sequences.size()); TODO don't know what
- // to do here
+ HiddenMarkovModel hmm = information.sequenceRef.getHMM();
+
+ ProfilesI info = AAFrequency.calculateInformation(hmm,
+ (endRes + 1) - startRes, startRes, endRes + 1,
+ showHMMSequenceLogo, ignoreBelowBackground);
+ _updateInformationRow(info, sequences.size());
upd = true;
}
if (consensus != null)
if (information == null)
{
information = new AlignmentAnnotation("", "", new Annotation[1], 0f,
- 100f, AlignmentAnnotation.BAR_GRAPH);
+ 6.25f, AlignmentAnnotation.BAR_GRAPH);
information.hasText = true;
- information.autoCalculated = true;
+ information.autoCalculated = false;
information.groupRef = this;
- information.label = "Consensus for " + getName();
- information.description = "Percent Identity";
+ information.label = getName() + "_HMM";
+ information.description = "Information content, measured in bits";
}
return information;
}
void setIsHMMConsensusSequence(boolean isHMMConsensusSequence);
+ boolean hasHMMAnnotation();
+
+ void setHasInfo(boolean status);
+
+ int getPreviousPosition();
+
+ void setPreviousPosition(int previousPosition);
}
import jalview.bin.Cache;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.gui.AlignFrame;
import jalview.gui.Preferences;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.util.Map;
+import java.util.List;
+
+import javax.swing.JOptionPane;
public class HMMBuildThread implements Runnable
{
AlignFrame af;
AlignmentI alignment;
+ SequenceGroup group;
+
+ boolean canRun = true;
+
File hmmTemp = null;
File stoTemp = null;
long barID;
-
- Map<Integer, SequenceI> hmmSeqs;
public HMMBuildThread(AlignFrame af)
{
this.af = af;
+ if (af.getViewport().getSelectionGroup() != null)
+ {
+ group = af.getViewport().getSelectionGroup();
+ }
alignment = af.getViewport().getAlignment();
+
}
@Override
public void run()
{
barID = System.currentTimeMillis();
- System.out.println(System.getProperty("java.io.tmpdir"));
af.setProgressBar(MessageManager.getString("status.running_hmmbuild"),
barID);
cmds.HMMERFOLDER = Cache.getProperty(Preferences.HMMER_PATH);
+ if (alignment == null && group == null)
+ {
+ JOptionPane.showMessageDialog(af,
+ MessageManager.getString("label.no_sequence_data"));
+ return;
+ }
try
{
hmmTemp = File.createTempFile("hmm", ".hmm");
{
try
{
- hmmSeqs = alignment.getHMMConsensusSequences(true);
- if (!alignment.isAligned())
+ List<SequenceI> seqs = alignment
+ .getHMMConsensusSequences(true);
+ cmds.setHmmSeqs(seqs);
+ if (group != null)
{
- alignment.padGaps();
+ SequenceI[] array = group.getSelectionAsNewSequences(alignment);
+
+ cmds.exportData(array, stoTemp, null, null);
+ }
+ else
+ {
+ if (!alignment.isAligned())
+ {
+ alignment.padGaps();
+ }
+ cmds.exportData(alignment.getSequencesArray(), stoTemp, null,
+ null);
}
- cmds.exportData(alignment.getSequencesArray(), stoTemp, null, null);
} catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
}
} catch (Exception e)
{
-
+ e.printStackTrace();
} finally
{
af.setProgressBar(MessageManager.getString("status.running_hmmbuild"),
private void importData() throws IOException, InterruptedException
{
+ cmds.addHMMConsensusSequences(af);
af.loadJalviewDataFile(hmmTemp.getAbsolutePath(), DataSourceType.FILE,
FileFormat.HMMER3, null);
- for (Map.Entry<Integer, SequenceI> entry : hmmSeqs.entrySet())
- {
- SequenceI seq = entry.getValue();
- Integer pos = entry.getKey();
- cmds.addHMMConsensusSequence(af, seq, pos);
- }
- af.alignPanel.alignmentChanged();
hmmTemp.delete();
stoTemp.delete();
}
+ public boolean canRun()
+ {
+ return canRun;
+ }
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Hashtable;
+import java.util.List;
public class HMMERCommands
{
Hashtable hash = new Hashtable();
+ List<SequenceI> hmmSeqs;
+
public void uniquifySequences(SequenceI[] seqs)
{
hash = jalview.analysis.SeqsetUtils.uniquify(seqs, true);
}
}
- public void addHMMConsensusSequence(AlignFrame af, SequenceI seq,
- Integer position)
+ public void addHMMConsensusSequences(AlignFrame af)
{
- seq.getHMM().initHMMSequence(af, position);
AlignmentI al = af.getViewport().getAlignment();
+ 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();
}
+ public List<SequenceI> getHmmSeqs()
+ {
+ return hmmSeqs;
+ }
+ public void setHmmSeqs(List<SequenceI> hmmSeqs)
+ {
+ this.hmmSeqs = hmmSeqs;
+ }
}
{
int width = alignment.getWidth();
- List<SequenceI> hmmSeqs = alignment.getHMMConsensusSequences();
+ List<SequenceI> hmmSeqs = alignment.getHMMConsensusSequences(false);
int index = 0;
for (SequenceI seq : hmmSeqs)
{