Skip to content

Commit 4bd5b36

Browse files
committed
multichrom fixes for the haplotype plot
1 parent 8357169 commit 4bd5b36

File tree

4 files changed

+97
-13
lines changed

4 files changed

+97
-13
lines changed

QtSLiM/QtSLiMChromosomeWidget.cpp

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -569,19 +569,48 @@ Chromosome *QtSLiMChromosomeWidget::focalChromosome(void)
569569
{
570570
Species *focalSpecies = focalDisplaySpecies();
571571

572-
if (focalSpecies && focalChromosomeSymbol_.length())
572+
if (focalSpecies)
573573
{
574-
Chromosome *chromosome = focalSpecies->ChromosomeFromSymbol(focalChromosomeSymbol_);
575-
576-
if (isOverview_ && !chromosome)
574+
if (focalChromosomeSymbol_.length())
575+
{
576+
Chromosome *chromosome = focalSpecies->ChromosomeFromSymbol(focalChromosomeSymbol_);
577+
578+
if (isOverview_ && !chromosome)
579+
{
580+
// The focal chromosome apparently no longer exists, but we want to keep
581+
// trying to focus on it if it comes back (e.g., after a recycle), so we
582+
// do not reset or forget the focal chromosome symbol here; we only reset
583+
// the symbol to "" in setFocalDisplaySpecies() and setFocalChromosome().
584+
// However, if the focal species has chromosomes (and they don't match),
585+
// then apparently we're waiting for something that won't happen; give up
586+
// and switch.
587+
if (focalSpecies->Chromosomes().size() > 1)
588+
{
589+
focalChromosomeSymbol_ = "";
590+
return nullptr;
591+
}
592+
else if (focalSpecies->Chromosomes().size() == 1)
593+
{
594+
Chromosome *chromosome = focalSpecies->Chromosomes()[0];
595+
596+
focalChromosomeSymbol_ = chromosome->Symbol();
597+
return chromosome;
598+
}
599+
}
600+
601+
return chromosome;
602+
}
603+
else if (focalSpecies->Chromosomes().size() == 1)
577604
{
578-
// the focal chromosome apparently no longer exists, but we want to keep
579-
// trying to focus on it if it comes back (e.g., after a recycle), so we
580-
// do not reset or forget the focal chromosome symbol here; we only reset
581-
// the symbol to "" in setFocalDisplaySpecies() and setFocalChromosome()
605+
// The species has just one chromosome, so there is no visual difference
606+
// between that chromosome being selected vs. not selected. However, we
607+
// want to return that chromosome to the caller, so if it is not selected,
608+
// we fix that here and return it.
609+
Chromosome *chromosome = focalSpecies->Chromosomes()[0];
610+
611+
focalChromosomeSymbol_ = chromosome->Symbol();
612+
return chromosome;
582613
}
583-
584-
return chromosome;
585614
}
586615

587616
return nullptr;

QtSLiM/QtSLiMHaplotypeManager.cpp

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <QFileDialog>
3636
#include <QStandardPaths>
3737
#include <QLabel>
38+
#include <QMessageBox>
3839
#include <QDebug>
3940

4041
#include <vector>
@@ -51,7 +52,40 @@
5152
// This class method runs a plot options dialog, and then produces a haplotype plot with a progress panel as it is being constructed
5253
void QtSLiMHaplotypeManager::CreateHaplotypePlot(QtSLiMChromosomeWidgetController *controller)
5354
{
55+
QtSLiMWindow *slimWindow = controller->slimWindow();
56+
57+
if (!slimWindow)
58+
return;
59+
5460
Species *displaySpecies = controller->focalDisplaySpecies();
61+
62+
if (!displaySpecies)
63+
{
64+
QMessageBox messageBox(slimWindow);
65+
messageBox.setText("Haplotype Plot");
66+
messageBox.setInformativeText("A single species must be chosen to create a haplotype plot; the plot will be based upon the selected species.");
67+
messageBox.setIcon(QMessageBox::Warning);
68+
messageBox.setWindowModality(Qt::WindowModal);
69+
messageBox.exec();
70+
return;
71+
}
72+
73+
// We need a single chromosome to work with; QtSLiMHaplotypeManager creates a haplotype
74+
// plot for one chromosome, which makes sense since haplosomes assort independently.
75+
// If we can't get a single chromosome, then we tell the user to select a chromosome.
76+
Chromosome *chromosome = slimWindow->focalChromosome();
77+
78+
if (!chromosome)
79+
{
80+
QMessageBox messageBox(slimWindow);
81+
messageBox.setText("Haplotype Plot");
82+
messageBox.setInformativeText("A single chromosome must be chosen to create a haplotype plot; the plot will be based upon the selected chromosome.");
83+
messageBox.setIcon(QMessageBox::Warning);
84+
messageBox.setWindowModality(Qt::WindowModal);
85+
messageBox.exec();
86+
return;
87+
}
88+
5589
QtSLiMHaplotypeOptions optionsPanel(controller->slimWindow());
5690

5791
int result = optionsPanel.exec();
@@ -63,9 +97,6 @@ void QtSLiMHaplotypeManager::CreateHaplotypePlot(QtSLiMChromosomeWidgetControlle
6397
QtSLiMHaplotypeManager::ClusteringOptimization clusteringOptimization = optionsPanel.clusteringOptimization();
6498

6599
// First generate the haplotype plot data, with a progress panel
66-
// FIXME MULTICHROM this code path should work with all of the chromosomes, probably...
67-
Chromosome *chromosome = &displaySpecies->TheChromosome();
68-
69100
QtSLiMHaplotypeManager *haplotypeManager = new QtSLiMHaplotypeManager(nullptr, clusteringMethod, clusteringOptimization, controller,
70101
displaySpecies, chromosome, QtSLiMRange(0,0), haplosomeSampleSize, true);
71102

@@ -214,6 +245,9 @@ QtSLiMHaplotypeManager::QtSLiMHaplotypeManager(QObject *p_parent, ClusteringMeth
214245

215246
title.append(QString(", tick %1").arg(community->Tick()));
216247

248+
if (displaySpecies->Chromosomes().size() > 1)
249+
title.append(QString(", chromosome '%2'").arg(QString::fromStdString(chromosome->Symbol())));
250+
217251
titleString = title;
218252
subpopCount = static_cast<int>(selected_subpops.size());
219253

QtSLiM/QtSLiMWindow.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,6 +2236,25 @@ Species *QtSLiMWindow::focalDisplaySpecies(void)
22362236
return nullptr;
22372237
}
22382238

2239+
Chromosome *QtSLiMWindow::focalChromosome(void)
2240+
{
2241+
// There needs to be a focal display species to answer this question; if
2242+
// we are on the "all" tab in a multispecies model, there are multiple
2243+
// focal chromosomes, so we return nullptr.
2244+
Species *species = focalDisplaySpecies();
2245+
2246+
if (!species)
2247+
return nullptr;
2248+
2249+
// If there is one focal display species, then the first overview widget
2250+
// if the one being displayed (see updateChromosomeViewSetup()).
2251+
QtSLiMChromosomeWidget *overviewWidget = chromosomeOverviewWidgets[0];
2252+
2253+
Chromosome *chromosome = overviewWidget->focalChromosome();
2254+
2255+
return chromosome;
2256+
}
2257+
22392258
void QtSLiMWindow::selectedSpeciesChanged(void)
22402259
{
22412260
// We don't want to react to automatic tab changes as we are adding or removing tabs from the species bar

QtSLiM/QtSLiMWindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ class QtSLiMWindow : public QMainWindow
185185
void setScriptStringAndInitializeSimulation(std::string string);
186186

187187
Species *focalDisplaySpecies(void);
188+
Chromosome *focalChromosome(void);
189+
188190
void updateOutputViews(void);
189191
void updateTickCounter(void);
190192
void updateSpeciesBar(void);

0 commit comments

Comments
 (0)