import jalview.datamodel.AlignmentView;
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.HiddenColumns;
+import jalview.datamodel.HiddenMarkovModel;
import jalview.datamodel.HiddenSequences;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SeqCigar;
import jalview.datamodel.SequenceI;
import jalview.gui.ColourMenuHelper.ColourChangeListener;
import jalview.gui.ViewSelectionMenu.ViewSetProvider;
+import jalview.hmmer.HMMAlign;
+import jalview.hmmer.HMMBuild;
+import jalview.hmmer.HMMERParamStore;
+import jalview.hmmer.HMMERPreset;
+import jalview.hmmer.HMMSearch;
+import jalview.hmmer.HmmerCommand;
import jalview.io.AlignmentProperties;
import jalview.io.AnnotationFile;
import jalview.io.BioJsHTMLOutput;
import jalview.schemes.ResidueColourScheme;
import jalview.schemes.TCoffeeColourScheme;
import jalview.util.MessageManager;
+import jalview.util.StringUtils;
import jalview.viewmodel.AlignmentViewport;
import jalview.viewmodel.ViewportRanges;
import jalview.ws.DBRefFetcher;
import jalview.ws.jws1.Discoverer;
import jalview.ws.jws2.Jws2Discoverer;
import jalview.ws.jws2.jabaws2.Jws2Instance;
+import jalview.ws.params.ArgumentI;
+import jalview.ws.params.ParamDatastoreI;
+import jalview.ws.params.WsParamSetI;
+import jalview.ws.params.simple.Option;
import jalview.ws.seqfetcher.DbSourceProxy;
import java.awt.BorderLayout;
import java.beans.PropertyChangeEvent;
import java.io.File;
import java.io.FileWriter;
+import java.io.IOException;
import java.io.PrintWriter;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
+import java.util.Map;
+import java.util.Scanner;
import java.util.Vector;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JEditorPane;
+import javax.swing.JFileChooser;
+import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLayeredPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
{
+ Map<String, Float> distribution = new HashMap<>(); // temporary
+
public static final int DEFAULT_WIDTH = 700;
public static final int DEFAULT_HEIGHT = 500;
AlignViewport viewport;
public AlignViewControllerI avc;
+ /*
+ * The selected HMM for this align frame
+ */
+ SequenceI selectedHMMSequence;
List<AlignmentPanel> alignPanels = new ArrayList<>();
*/
String fileName = null;
+
/**
* Creates a new AlignFrame object with specific width and height.
*
ap.av.updateConservation(ap);
ap.av.updateConsensus(ap);
ap.av.updateStrucConsensus(ap);
+ ap.av.initInformationWorker(ap);
}
}
showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
showSequenceLogo.setSelected(av.isShowSequenceLogo());
normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
+ showInformationHistogram.setSelected(av.isShowInformationHistogram());
+ showHMMSequenceLogo.setSelected(av.isShowHMMSequenceLogo());
+ normaliseHMMSequenceLogo.setSelected(av.isNormaliseHMMSequenceLogo());
ColourMenuHelper.setColourSelected(colourMenu,
av.getGlobalColourScheme());
}
@Override
+ public void hmmBuild_actionPerformed(boolean withDefaults)
+ {
+ if (!alignmentIsSufficient(1))
+ {
+ return;
+ }
+ List<ArgumentI> args = new ArrayList<>();
+ if (withDefaults)
+ {
+ // todo: construct this in HMMERPreset?
+ String argName = MessageManager.getString("label.hmmbuild_for");
+ String argValue = MessageManager.getString("label.alignment");
+ args.add(
+ new Option(argName, null, false, null, argValue, null, null));
+ }
+ else
+ {
+ WsParamSetI set = new HMMERPreset();
+ ParamDatastoreI store = HMMERParamStore.forBuild();
+ WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
+ args);
+ if (params.showRunDialog())
+ {
+ args = params.getJobParams();
+ }
+ else
+ {
+ return; // user cancelled
+ }
+ }
+ new Thread(new HMMBuild(this, args)).start();
+ }
+
+ @Override
+ public void hmmAlign_actionPerformed(boolean withDefaults)
+ {
+ if (!(checkForHMM() && alignmentIsSufficient(2)))
+ {
+ return;
+ }
+ List<ArgumentI> args = new ArrayList<>();
+ if (!withDefaults)
+ {
+ WsParamSetI set = new HMMERPreset();
+ ParamDatastoreI store = HMMERParamStore.forAlign();
+ WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
+ args);
+ if (params.showRunDialog())
+ {
+ args = params.getJobParams();
+ }
+ else
+ {
+ return; // user cancelled
+ }
+ }
+ new Thread(new HMMAlign(this, args)).start();
+ }
+
+ @Override
+ public void hmmSearch_actionPerformed(boolean withDefaults)
+ {
+ if (!checkForHMM())
+ {
+ return;
+ }
+ List<ArgumentI> args = new ArrayList<>();
+ if (!withDefaults)
+ {
+ WsParamSetI set = new HMMERPreset();
+ ParamDatastoreI store = HMMERParamStore.forSearch();
+ WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
+ args);
+ if (params.showRunDialog())
+ {
+ args = params.getJobParams();
+ }
+ else
+ {
+ return; // user cancelled
+ }
+ }
+ new Thread(new HMMSearch(this, args)).start();
+ alignPanel.repaint();
+ }
+
+ /**
+ * Checks if the frame has a selected hidden Markov model
+ *
+ * @return
+ */
+ private boolean checkForHMM()
+ {
+ if (getSelectedHMM() == null)
+ {
+ JOptionPane.showMessageDialog(this,
+ MessageManager.getString("warn.no_selected_hmm"));
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Checks if the alignment contains the required number of sequences.
+ *
+ * @param required
+ * @return
+ */
+ public boolean alignmentIsSufficient(int required)
+ {
+ if (getViewport().getAlignment().getSequences().size() < required)
+ {
+ JOptionPane.showMessageDialog(this,
+ MessageManager.getString("warn.not_enough_sequences"));
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void addDatabase_actionPerformed() throws IOException
+ {
+ if (Cache.getProperty(Preferences.HMMSEARCH_DB_PATHS) == null)
+ {
+ Cache.setProperty(Preferences.HMMSEARCH_DBS, "");
+ Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, "");
+ }
+
+ String path = openFileChooser(false);
+ if (new File(path).exists())
+ {
+ IdentifyFile identifier = new IdentifyFile();
+ FileFormatI format = identifier.identify(path, DataSourceType.FILE);
+ if (format == FileFormat.Fasta || format == FileFormat.Stockholm
+ || format == FileFormat.Pfam)
+ {
+ String currentDbs = Cache.getProperty(Preferences.HMMSEARCH_DBS);
+ String currentDbPaths = Cache
+ .getProperty(Preferences.HMMSEARCH_DB_PATHS);
+ currentDbPaths += " " + path;
+
+ String fileName = StringUtils.getLastToken(path, File.separator);
+ Scanner scanner = new Scanner(fileName).useDelimiter(".");
+ String name = scanner.next();
+ scanner.close();
+ currentDbs += " " + path; // TODO remove path from file name
+ scanner.close();
+
+ Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, currentDbPaths);
+ Cache.setProperty(Preferences.HMMSEARCH_DBS, currentDbPaths);
+ }
+ else
+ {
+ JOptionPane.showMessageDialog(this,
+ MessageManager.getString("warn.invalid_format"));
+ }
+ }
+ else
+ {
+ JOptionPane.showMessageDialog(this,
+ MessageManager.getString("warn.not_enough_sequences"));
+ }
+ }
+
+ /**
+ * Opens a file chooser
+ *
+ * @param forFolder
+ * @return
+ */
+ protected String openFileChooser(boolean forFolder)
+ {
+ String choice = null;
+ JFileChooser chooser = new JFileChooser();
+ if (forFolder)
+ {
+ chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ }
+ chooser.setDialogTitle(
+ MessageManager.getString("label.open_local_file"));
+ chooser.setToolTipText(MessageManager.getString("action.open"));
+
+ int value = chooser.showOpenDialog(this);
+
+ if (value == JFileChooser.APPROVE_OPTION)
+ {
+ choice = chooser.getSelectedFile().getPath();
+ }
+ return choice;
+ }
+
+ @Override
public void reload_actionPerformed(ActionEvent e)
{
if (fileName != null)
@Override
public void associatedData_actionPerformed(ActionEvent e)
+ throws IOException, InterruptedException
{
// Pick the tree file
JalviewFileChooser chooser = new JalviewFileChooser(
@Override
protected void copy_actionPerformed(ActionEvent e)
{
- System.gc();
if (viewport.getSelectionGroup() == null)
{
return;
return;
}
- ArrayList<int[]> hiddenColumns = null;
+ HiddenColumns hiddenColumns = null;
if (viewport.hasHiddenColumns())
{
- hiddenColumns = new ArrayList<>();
int hiddenOffset = viewport.getSelectionGroup().getStartRes();
int hiddenCutoff = viewport.getSelectionGroup().getEndRes();
- ArrayList<int[]> hiddenRegions = viewport.getAlignment()
- .getHiddenColumns().getHiddenColumnsCopy();
- for (int[] region : hiddenRegions)
- {
- if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
- {
- hiddenColumns
- .add(new int[]
- { region[0] - hiddenOffset, region[1] - hiddenOffset });
- }
- }
+
+ // create new HiddenColumns object with copy of hidden regions
+ // between startRes and endRes, offset by startRes
+ hiddenColumns = new HiddenColumns(
+ viewport.getAlignment().getHiddenColumns(), hiddenOffset,
+ hiddenCutoff, hiddenOffset);
}
Desktop.jalviewClipboard = new Object[] { seqs,
*
* @param e
* DOCUMENT ME!
+ * @throws InterruptedException
+ * @throws IOException
*/
@Override
protected void pasteNew_actionPerformed(ActionEvent e)
+ throws IOException, InterruptedException
{
paste(true);
}
*
* @param e
* DOCUMENT ME!
+ * @throws InterruptedException
+ * @throws IOException
*/
@Override
protected void pasteThis_actionPerformed(ActionEvent e)
+ throws IOException, InterruptedException
{
paste(false);
}
*
* @param newAlignment
* true to paste to a new alignment, otherwise add to this.
+ * @throws InterruptedException
+ * @throws IOException
*/
- void paste(boolean newAlignment)
+ void paste(boolean newAlignment) throws IOException, InterruptedException
{
boolean externalPaste = true;
try
if (Desktop.jalviewClipboard != null
&& Desktop.jalviewClipboard[2] != null)
{
- List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
- for (int[] region : hc)
- {
- af.viewport.hideColumns(region[0], region[1]);
- }
+ HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
+ af.viewport.setHiddenColumns(hc);
}
// >>>This is a fix for the moment, until a better solution is
System.out.println("Exception whilst pasting: " + ex);
// could be anything being pasted in here
}
-
}
@Override
if (Desktop.jalviewClipboard != null
&& Desktop.jalviewClipboard[2] != null)
{
- List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
- for (int region[] : hc)
- {
- af.viewport.hideColumns(region[0], region[1]);
- }
+ HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
+ af.viewport.setHiddenColumns(hc);
}
// >>>This is a fix for the moment, until a better solution is
*
* @param file
* either a filename or a URL string.
+ * @throws InterruptedException
+ * @throws IOException
*/
public void loadJalviewDataFile(String file, DataSourceType sourceType,
FileFormatI format, SequenceI assocSeq)
new JnetAnnotationMaker();
JnetAnnotationMaker.add_annotation(predictions,
viewport.getAlignment(), 0, false);
- SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
- viewport.getAlignment().setSeqrep(repseq);
- HiddenColumns cs = new HiddenColumns();
- cs.hideInsertionsFor(repseq);
- viewport.getAlignment().setHiddenColumns(cs);
+ viewport.getAlignment().setupJPredAlignment();
isAnnotation = true;
}
// else if (IdentifyFile.FeaturesFile.equals(format))
}
if (isAnnotation)
{
-
alignPanel.adjustAnnotationHeight();
viewport.updateSequenceIdColours();
buildSortByAnnotationScoresMenu();
MessageManager.getString("option.trim_retrieved_seqs"));
trimrs.setToolTipText(
MessageManager.getString("label.trim_retrieved_sequences"));
- trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
+ trimrs.setSelected(
+ Cache.getDefault(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES, true));
trimrs.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
trimrs.setSelected(trimrs.isSelected());
- Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
+ Cache.setProperty(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES,
Boolean.valueOf(trimrs.isSelected()).toString());
};
});
}
}
+ /**
+ * Sets the status of the HMMER menu
+ */
+ public void updateHMMERStatus()
+ {
+ hmmerMenu.setEnabled(HmmerCommand.isHmmerAvailable());
+ }
+
+ /**
+ * Returns the selected hidden Markov model.
+ *
+ * @return
+ */
+ public HiddenMarkovModel getSelectedHMM()
+ {
+ if (selectedHMMSequence == null)
+ {
+ return null;
+ }
+ return selectedHMMSequence.getHMM();
+ }
+
+ /**
+ * Returns the selected hidden Markov model.
+ *
+ * @return
+ */
+ public SequenceI getSelectedHMMSequence()
+ {
+ return selectedHMMSequence;
+ }
+
+ /**
+ * Sets the selected hidden Markov model
+ *
+ * @param selectedHMM
+ */
+ public void setSelectedHMMSequence(SequenceI selectedHMM)
+ {
+ this.selectedHMMSequence = selectedHMM;
+ hmmAlign.setText(MessageManager.getString("label.hmmalign") + " to "
+ + selectedHMM.getHMM().getName());
+ hmmSearch.setText(MessageManager.getString("label.hmmsearch") + " with "
+ + selectedHMM.getHMM().getName());
+ }
+
+ @Override
+ public void hmmerMenu_actionPerformed(ActionEvent e)
+ {
+ SequenceGroup grp = getViewport().getSelectionGroup();
+ if (grp != null)
+ {
+ hmmBuild.setText(MessageManager.getString("label.hmmbuild") + " from "
+ + grp.getName());
+ }
+ else
+ {
+ hmmBuild.setText(MessageManager.getString("label.hmmbuild")
+ + " from Alignment");
+ }
+ }
+
@Override
protected void loadVcf_actionPerformed()
{