models = getApplicableScoreModels(nucleotide,
pca.isSelected());
/*
* now we can actually add entries to the combobox,
* remembering their descriptions for tooltips
*/
boolean selectedIsPresent = false;
for (ScoreModelI sm : models)
{
if (curSel != null && sm.getName().equals(curSel))
{
selectedIsPresent = true;
curSel = sm.getName();
}
model.addElement(sm.getName());
/*
* tooltip is description if provided, else text lookup with
* fallback on the model name
*/
String tooltip = sm.getDescription();
if (tooltip == null)
{
tooltip = MessageManager.getStringOrReturn("label.score_model_",
sm.getName());
}
toolTips.add(tooltip);
}
if (selectedIsPresent)
{
model.setSelectedItem(curSel);
}
// finally, update the model
comboBox.setModel(model);
}
/**
* Builds a list of score models which are applicable for the alignment and
* calculation type (peptide or generic models for protein, nucleotide or
* generic models for nucleotide).
*
* As a special case, includes BLOSUM62 as an extra option for nucleotide PCA.
* This is for backwards compatibility with Jalview prior to 2.8 when BLOSUM62
* was the only score matrix supported. This is included if property
* BLOSUM62_PCA_FOR_NUCLEOTIDE is set to true in the Jalview properties file.
*
* @param nucleotide
* @param forPca
* @return
*/
protected static List getApplicableScoreModels(
boolean nucleotide, boolean forPca)
{
List filtered = new ArrayList<>();
ScoreModels scoreModels = ScoreModels.getInstance();
for (ScoreModelI sm : scoreModels.getModels())
{
if (!nucleotide && sm.isProtein() || nucleotide && sm.isDNA())
{
filtered.add(sm);
}
}
/*
* special case: add BLOSUM62 as last option for nucleotide PCA,
* for backwards compatibility with Jalview < 2.8 (JAL-2962)
*/
if (nucleotide && forPca
&& Cache.getDefault("BLOSUM62_PCA_FOR_NUCLEOTIDE", false))
{
filtered.add(scoreModels.getBlosum62());
}
return filtered;
}
/**
* Open and calculate the selected tree or PCA on 'OK'
*/
protected void calculate_actionPerformed()
{
boolean doPCA = pca.isSelected();
String modelName = modelNames.getSelectedItem().toString();
SimilarityParamsI params = getSimilarityParameters(doPCA);
if (doPCA)
{
openPcaPanel(modelName, params);
}
else
{
openTreePanel(modelName, params);
}
// closeFrame();
}
/**
* Open a new Tree panel on the desktop
*
* @param modelName
* @param params
*/
protected void openTreePanel(String modelName, SimilarityParamsI params)
{
/*
* gui validation shouldn't allow insufficient sequences here, but leave
* this check in in case this method gets exposed programmatically in future
*/
AlignViewportI viewport = af.getViewport();
SequenceGroup sg = viewport.getSelectionGroup();
if (sg != null && sg.getSize() < MIN_TREE_SELECTION)
{
JvOptionPane.showMessageDialog(Desktop.desktop,
MessageManager.formatMessage(
"label.you_need_at_least_n_sequences",
MIN_TREE_SELECTION),
MessageManager.getString("label.not_enough_sequences"),
JvOptionPane.WARNING_MESSAGE);
return;
}
String treeType = neighbourJoining.isSelected()
? TreeBuilder.NEIGHBOUR_JOINING
: TreeBuilder.AVERAGE_DISTANCE;
af.newTreePanel(treeType, modelName, params);
}
/**
* Open a new PCA panel on the desktop
*
* @param modelName
* @param params
*/
protected void openPcaPanel(String modelName, SimilarityParamsI params)
{
AlignViewportI viewport = af.getViewport();
/*
* gui validation shouldn't allow insufficient sequences here, but leave
* this check in in case this method gets exposed programmatically in future
*/
if (((viewport.getSelectionGroup() != null)
&& (viewport.getSelectionGroup().getSize() < MIN_PCA_SELECTION)
&& (viewport.getSelectionGroup().getSize() > 0))
|| (viewport.getAlignment().getHeight() < MIN_PCA_SELECTION))
{
JvOptionPane.showInternalMessageDialog(this,
MessageManager.formatMessage(
"label.you_need_at_least_n_sequences",
MIN_PCA_SELECTION),
MessageManager
.getString("label.sequence_selection_insufficient"),
JvOptionPane.WARNING_MESSAGE);
return;
}
/*
* construct the panel and kick off its calculation thread
*/
pcaPanel = new PCAPanel(af.alignPanel, modelName, params);
new Thread(pcaPanel).start();
}
/**
*
*/
protected void closeFrame()
{
try
{
frame.setClosed(true);
} catch (PropertyVetoException ex)
{
}
}
/**
* Returns a data bean holding parameters for similarity (or distance) model
* calculation
*
* @param doPCA
* @return
*/
protected SimilarityParamsI getSimilarityParameters(boolean doPCA)
{
// commented out: parameter choices read from gui widgets
// SimilarityParamsI params = new SimilarityParams(
// includeGappedColumns.isSelected(), matchGaps.isSelected(),
// includeGaps.isSelected(), shorterSequence.isSelected());
boolean includeGapGap = true;
boolean includeGapResidue = true;
boolean matchOnShortestLength = false;
/*
* 'matchGaps' flag is only used in the PID calculation
* - set to false for PCA so that PCA using PID reproduces SeqSpace PCA
* - set to true for Tree to reproduce Jalview 2.10.1 calculation
* - set to false for Tree for a more correct calculation (JAL-374)
*/
boolean matchGap = doPCA ? false : treeMatchGaps;
return new SimilarityParams(includeGapGap, matchGap, includeGapResidue,
matchOnShortestLength);
}
/**
* Closes dialog on Close button press
*/
protected void close_actionPerformed()
{
try
{
frame.setClosed(true);
} catch (Exception ex)
{
}
}
public PCAPanel getPcaPanel()
{
return pcaPanel;
}
}