Skip to content

Commit

Permalink
Adjust branch lengths toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Ondov committed Dec 31, 2014
1 parent a2dada2 commit 9baf419
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ <h2 id="menu">Menus (<a href="#">back to Contents</a>)</h2>
<li><strong>Tree</strong>
<ul>
<li><p><strong>Reroot at midpoint</strong> - Balances the tree at the center of the longest path.</p>
<li><p><strong>Adjust branch lengths</strong> - Toggles whether the branch lengths shown in the status bar (or exported to Newick) are adjusted to account for total core size (since trees are typically generated with variant columns only). Note that this option will only be available for Gingr files generated by Parsnp version 1.1 or later, or with harvesttools using the -u flag.</p>
</li>
</ul>
<li><strong>View</strong>
Expand Down
32 changes: 31 additions & 1 deletion src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,18 @@ void MainWindow::saveSnapshot(const QString & fileName, bool tree, bool alignmen
pixmap.save(fileName);
}

void MainWindow::setAdjustBranchLengths(bool adjust)
{
if ( adjust )
{
treeStatus->setMultiplier(hio.phylogenyTree.getMult());
}
else
{
treeStatus->setMultiplier(1);
}
}

void MainWindow::setDocumentChanged()
{
actionSave->setDisabled(false);
Expand Down Expand Up @@ -1192,7 +1204,7 @@ void MainWindow::exportFileBackground(const QString & fileName, ImportWindow::Fi
hio.writeXmfa(out);
break;
case ImportWindow::TRE_NWK:
hio.writeNewick(out);
hio.writeNewick(out, actionToggleAdjustBranchLengths->isChecked());
break;
case ImportWindow::VAR_MFA:
hio.writeSnp(out);
Expand Down Expand Up @@ -1348,6 +1360,7 @@ void MainWindow::initializeAlignment()
actionExportVariantsVcf->setDisabled(false);
}


void MainWindow::initializeLayout()
{
trackFocus = -1;
Expand Down Expand Up @@ -1379,6 +1392,12 @@ void MainWindow::initializeLayout()
actionMidpointReroot->setDisabled(true);
connect(actionMidpointReroot, SIGNAL(triggered()), this, SLOT(rerootTreeMidpoint()));

actionToggleAdjustBranchLengths = new QAction(tr("Adjust branch lengths"), this);
actionToggleAdjustBranchLengths->setCheckable(true);
actionToggleAdjustBranchLengths->setDisabled(true);
menuTree->addAction(actionToggleAdjustBranchLengths);
connect(actionToggleAdjustBranchLengths, SIGNAL(toggled(bool)), this, SLOT(setAdjustBranchLengths(bool)));

actionToggleSynteny = new QAction(tr("Synten&y"), this);
actionToggleSynteny->setCheckable(true);
actionToggleSynteny->setShortcut(QKeySequence("Ctrl+Y"));
Expand Down Expand Up @@ -1669,6 +1688,17 @@ void MainWindow::initializeTree()
hio.phylogenyTree.getLeafIds(leafIds);
treeViewMain->setPhylogenyTree(&hio.phylogenyTree);
treeViewMap->setPhylogenyTree(&hio.phylogenyTree);

if ( hio.phylogenyTree.getMult() == 1 )
{
actionToggleAdjustBranchLengths->setChecked(false);
actionToggleAdjustBranchLengths->setDisabled(true);
}
else
{
actionToggleAdjustBranchLengths->setEnabled(true);
actionToggleAdjustBranchLengths->setChecked(true);
}
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public slots:
void setNode(const PhylogenyTreeNode * node);
void setPosition(int gapped);
void toggleSynteny();
void setAdjustBranchLengths(bool adjust);
void setTrackFocus(int track);
void setTrackHover(int track, int trackEnd);
void setTrackListViewFocus(TrackListView * view);
Expand Down Expand Up @@ -185,6 +186,7 @@ public slots:
QAction * actionSaveAs;
QAction * actionSnps;
QAction * actionSearch;
QAction * actionToggleAdjustBranchLengths;
QAction * actionToggleShowInsertions;
QAction * actionToggleShowDeletions;
QAction * actionToggleSynteny;
Expand Down
4 changes: 3 additions & 1 deletion src/PhylogenyTreeStatusBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
PhylogenyTreeStatusBar::PhylogenyTreeStatusBar()
: QWidget()
{
mult = 1;

labelName = new StatusLabel();
labelDistance = new StatusLabel();
labelBootstrap = new StatusLabel();
Expand Down Expand Up @@ -73,7 +75,7 @@ void PhylogenyTreeStatusBar::setPhylogenyTreeNode(const PhylogenyTreeNode * phyl
}
else
{
labelDistance->setText(QString("%1").arg(node->getDistance()));
labelDistance->setText(QString("%1").arg(node->getDistance() * mult));
labelBootstrap->setText(QString("%1").arg(node->getBootstrap()));

if ( node->getBootstrap() > .5 || node->getBootstrap() == 0 )
Expand Down
4 changes: 4 additions & 0 deletions src/PhylogenyTreeStatusBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class PhylogenyTreeStatusBar : public QWidget

PhylogenyTreeStatusBar();

void setMultiplier(double multNew);
void setName(const QString & name);
void setPhylogenyTreeNode(const PhylogenyTreeNode * PhylogenyTreeNode, const QString & name, int leaf = -1);

Expand All @@ -26,6 +27,9 @@ class PhylogenyTreeStatusBar : public QWidget
StatusLabel * labelName;
StatusLabel * labelDistance;
StatusLabel * labelBootstrap;
double mult;
};

inline void PhylogenyTreeStatusBar::setMultiplier(double multNew) { mult = multNew; }

#endif /* defined(__gavqt__PhylogenyTreeStatusBar__) */

0 comments on commit 9baf419

Please sign in to comment.