phy.deleteSubtree( node, true );
}
phy.externalNodesHaveChanged();
- phy.hashIDs();
+ phy.clearHashIdToNodeMap();
phy.recalculateNumberOfExternalDescendants( true );
}
return not_found;
for( final String remove_me : not_found ) {
phy.deleteSubtree( phy.getNode( remove_me ), true );
}
+ phy.clearHashIdToNodeMap();
+ phy.externalNodesHaveChanged();
if ( phy.getNumberOfExternalNodes() < 2 ) {
ForesterUtil.fatalError( PRG_NAME,
"after removal of unresolvable external nodes, phylogeny has "
final static private String REMAPPED_SUFFIX = "_gsdi_remapped.txt";
final static private String PRG_NAME = "gsdi";
final static private String PRG_VERSION = "1.000";
- final static private String PRG_DATE = "120608";
+ final static private String PRG_DATE = "120629";
final static private String PRG_DESC = "general speciation duplication inference";
final static private String E_MAIL = "phylosoft@gmail.com";
final static private String WWW = "www.phylosoft.org/forester";
for( final Phylogeny phy : phys ) {
PhylogenyMethods.orderAppearance( phy.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.TAXONOMY );
phy.externalNodesHaveChanged();
- phy.hashIDs();
+ phy.clearHashIdToNodeMap();
phy.recalculateNumberOfExternalDescendants( true );
}
}
public final class Constants {
final static boolean __ALLOW_PHYLOGENETIC_INFERENCE = true;
- public final static boolean __RELEASE = false; // TODO remove me
+ public final static boolean __RELEASE = true; // TODO remove me
public final static boolean __SNAPSHOT_RELEASE = false; // TODO remove me
public final static boolean __SYNTH_LF = false; // TODO remove me
public final static boolean ALLOW_DDBJ_BLAST = false;
public final static String PRG_NAME = "Archaeopteryx";
- final static String VERSION = "0.971 9M";
- final static String PRG_DATE = "2012.04.16";
+ final static String VERSION = "0.972 9M";
+ final static String PRG_DATE = "2012.06.29";
final static String DEFAULT_CONFIGURATION_FILE_NAME = "_aptx_configuration_file";
final static String[] DEFAULT_FONT_CHOICES = { "Verdana", "Tahoma",
"Arial", "Helvetica", "Dialog", "Lucida Sans", "SansSerif", "Sans-serif", "Sans" };
_order_of_appearance = !_order_of_appearance;
tp.setNodeInPreorderToNull();
tp.getPhylogeny().externalNodesHaveChanged();
- tp.getPhylogeny().hashIDs();
+ tp.getPhylogeny().clearHashIdToNodeMap();
tp.getPhylogeny().recalculateNumberOfExternalDescendants( true );
tp.resetNodeIdToDistToLeafMap();
tp.setEdited( true );
tp.updateSetOfCollapsedExternalNodes();
t.recalculateNumberOfExternalDescendants( false );
tp.setNodeInPreorderToNull();
- t.hashIDs();
+ t.clearHashIdToNodeMap();
showWhole();
}
}
import org.forester.phylogeny.factories.PhylogenyFactory;
import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
import org.forester.sdi.GSDI;
-import org.forester.sdi.SDI;
import org.forester.sdi.SDIR;
-import org.forester.sdi.SDIse;
import org.forester.sequence.Sequence;
import org.forester.util.BasicDescriptiveStatistics;
import org.forester.util.BasicTable;
// Analysis menu
private JMenu _analysis_menu;
private JMenuItem _load_species_tree_item;
- private JMenuItem _sdi_item;
private JMenuItem _gsdi_item;
private JMenuItem _root_min_dups_item;
private JMenuItem _root_min_cost_l_item;
else if ( o == _load_species_tree_item ) {
readSpeciesTreeFromFile();
}
- else if ( o == _sdi_item ) {
- if ( isSubtreeDisplayed() ) {
- return;
- }
- executeSDI();
- }
else if ( o == _lineage_inference ) {
if ( isSubtreeDisplayed() ) {
JOptionPane.showMessageDialog( this,
void buildAnalysisMenu() {
_analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
- _analysis_menu.add( _sdi_item = new JMenuItem( "SDI (Speciation Duplication Inference)" ) );
- if ( !Constants.__RELEASE && !Constants.__SNAPSHOT_RELEASE ) {
- _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
- }
+ _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
_analysis_menu.addSeparator();
_analysis_menu.add( _root_min_dups_item = new JMenuItem( "Root by Minimizing Duplications | Height (SDI)" ) );
_analysis_menu.add( _root_min_cost_l_item = new JMenuItem( "Root by Minimizing Cost L | Height (SDI)" ) );
_analysis_menu.addSeparator();
_analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) );
- customizeJMenuItem( _sdi_item );
customizeJMenuItem( _gsdi_item );
customizeJMenuItem( _root_min_dups_item );
customizeJMenuItem( _root_min_cost_l_item );
}
if ( to_be_removed.size() > 0 ) {
phy.externalNodesHaveChanged();
- phy.hashIDs();
+ phy.clearHashIdToNodeMap();
phy.recalculateNumberOfExternalDescendants( true );
getCurrentTreePanel().resetNodeIdToDistToLeafMap();
getCurrentTreePanel().updateSetOfCollapsedExternalNodes();
gene_tree.setAllNodesToNotCollapse();
gene_tree.recalculateNumberOfExternalDescendants( false );
GSDI gsdi = null;
- int duplications = -1;
try {
- gsdi = new GSDI( gene_tree, _species_tree.copy(), true, true, false );
- duplications = gsdi.getDuplicationsSum();
+ gsdi = new GSDI( gene_tree, _species_tree.copy(), false, true, true );
}
catch ( final Exception e ) {
JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE );
}
gene_tree.setRerootable( false );
_mainpanel.getCurrentTreePanel().setTree( gene_tree );
+ _mainpanel.getCurrentPhylogeny().clearHashIdToNodeMap();
+ _mainpanel.getCurrentPhylogeny().recalculateNumberOfExternalDescendants( true );
+ _mainpanel.getCurrentTreePanel().resetNodeIdToDistToLeafMap();
+ _mainpanel.getCurrentTreePanel().setEdited( true );
getControlPanel().setShowEvents( true );
showWhole();
+ final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
+ _mainpanel.addPhylogenyInNewTab( gsdi.getSpeciesTree(), getConfiguration(), "species tree", null );
+ showWhole();
+ _mainpanel.getTabbedPane().setSelectedIndex( selected );
+ showWhole();
_mainpanel.getCurrentTreePanel().setEdited( true );
- JOptionPane.showMessageDialog( this,
- "Number of duplications: " + duplications,
- "GSDI successfully completed",
- JOptionPane.INFORMATION_MESSAGE );
+ JOptionPane.showMessageDialog( this, "Duplications: " + gsdi.getDuplicationsSum() + "\n"
+ + "Potential duplications: " + gsdi.getSpeciationOrDuplicationEventsSum() + "\n" + "Speciations: "
+ + gsdi.getSpeciationsSum(), "GSDI successfully completed", JOptionPane.INFORMATION_MESSAGE );
}
void executeFunctionAnalysis() {
}
}
- void executeSDI() {
- if ( !isOKforSDI( true, true ) ) {
- return;
- }
- if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
- JOptionPane.showMessageDialog( this,
- "Gene tree is not rooted",
- "Cannot execute SDI",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
- gene_tree.setAllNodesToNotCollapse();
- gene_tree.recalculateNumberOfExternalDescendants( false );
- SDI sdi = null;
- int duplications = -1;
- try {
- sdi = new SDIse( gene_tree, _species_tree.copy() );
- duplications = sdi.getDuplicationsSum();
- }
- catch ( final Exception e ) {
- JOptionPane.showMessageDialog( this, e.toString(), "Error during SDI", JOptionPane.ERROR_MESSAGE );
- }
- gene_tree.setRerootable( false );
- _mainpanel.getCurrentTreePanel().setTree( gene_tree );
- getControlPanel().setShowEvents( true );
- showWhole();
- _mainpanel.getCurrentTreePanel().setEdited( true );
- JOptionPane.showMessageDialog( this,
- "Number of duplications: " + duplications,
- "SDI successfully completed",
- JOptionPane.INFORMATION_MESSAGE );
- }
-
void executeSDIR( final boolean minimize_cost ) {
if ( !isOKforSDI( true, true ) ) {
return;
}
setNodeInPreorderToNull();
_phylogeny.externalNodesHaveChanged();
- _phylogeny.hashIDs();
+ _phylogeny.clearHashIdToNodeMap();
_phylogeny.recalculateNumberOfExternalDescendants( true );
resetNodeIdToDistToLeafMap();
setEdited( true );
setCopiedAndPastedNodes( null );
setCutOrCopiedTree( _phylogeny.copy( node ) );
_phylogeny.deleteSubtree( node, true );
- _phylogeny.hashIDs();
+ _phylogeny.clearHashIdToNodeMap();
_phylogeny.recalculateNumberOfExternalDescendants( true );
resetNodeIdToDistToLeafMap();
setEdited( true );
_phylogeny.deleteSubtree( node, true );
}
_phylogeny.externalNodesHaveChanged();
- _phylogeny.hashIDs();
+ _phylogeny.clearHashIdToNodeMap();
_phylogeny.recalculateNumberOfExternalDescendants( true );
resetNodeIdToDistToLeafMap();
setEdited( true );
getCopiedAndPastedNodes().addAll( node_ids );
setNodeInPreorderToNull();
_phylogeny.externalNodesHaveChanged();
- _phylogeny.hashIDs();
+ _phylogeny.clearHashIdToNodeMap();
_phylogeny.recalculateNumberOfExternalDescendants( true );
resetNodeIdToDistToLeafMap();
setEdited( true );
node.swapChildren();
setNodeInPreorderToNull();
_phylogeny.externalNodesHaveChanged();
- _phylogeny.hashIDs();
+ _phylogeny.clearHashIdToNodeMap();
_phylogeny.recalculateNumberOfExternalDescendants( true );
resetNodeIdToDistToLeafMap();
setEdited( true );
PhylogenyMethods.sortNodeDescendents( node, pri );
setNodeInPreorderToNull();
_phylogeny.externalNodesHaveChanged();
- _phylogeny.hashIDs();
+ _phylogeny.clearHashIdToNodeMap();
_phylogeny.recalculateNumberOfExternalDescendants( true );
resetNodeIdToDistToLeafMap();
setEdited( true );
private Confidence _confidence;
private Identifier _identifier;
private boolean _rerootable;
- private HashMap<Integer, PhylogenyNode> _idhash;
+ private HashMap<Integer, PhylogenyNode> _id_to_node_map;
private List<PhylogenyNode> _external_nodes_set;
private Collection<Sequence> _sequenceRelationQueries;
private Collection<SequenceRelation.SEQUENCE_RELATION_TYPE> _relevant_sequence_relation_types;
}
/**
- * Need the delete and/or rehash _idhash (not done automatically
+ * Need to call clearHashIdToNodeMap() afterwards (not done automatically
* to allow client multiple deletions in linear time).
* Need to call 'recalculateNumberOfExternalDescendants(boolean)' after this
* if tree is to be displayed.
}
}
remove_us.removeConnections();
- setIdHash( null );
externalNodesHaveChanged();
}
return _identifier;
}
- // ---------------------------------------------------------
- // Modification of Phylogeny topology and Phylogeny appearance
- // ---------------------------------------------------------
- private HashMap<Integer, PhylogenyNode> getIdHash() {
- return _idhash;
+ private HashMap<Integer, PhylogenyNode> getIdToNodeMap() {
+ return _id_to_node_map;
}
/**
/**
* Finds the PhylogenyNode of this Phylogeny which has a matching ID number.
- * Takes O(n) time. After method hashIDs() has been called it runs in
- * constant time.
- *
- * @param id
- * ID number (int) of the PhylogenyNode to find
* @return PhylogenyNode with matching ID, null if not found
*/
public PhylogenyNode getNode( final int id ) throws NoSuchElementException {
if ( isEmpty() ) {
throw new NoSuchElementException( "attempt to get node in an empty phylogeny" );
}
- if ( _idhash != null ) {
- return _idhash.get( id );
- }
- else {
- for( final PhylogenyNodeIterator iter = iteratorPreorder(); iter.hasNext(); ) {
- final PhylogenyNode node = iter.next();
- if ( node.getId() == id ) {
- return node;
- }
- }
+ if ( ( getIdToNodeMap() == null ) || getIdToNodeMap().isEmpty() ) {
+ reHashIdToNodeMap();
}
- return null;
+ return getIdToNodeMap().get( id );
}
/**
* constant time. Important: The user is responsible for calling this method
* (again) after this Phylogeny has been changed/created/renumbered.
*/
- public void hashIDs() {
+ private void reHashIdToNodeMap() {
if ( isEmpty() ) {
return;
}
- setIdHash( new HashMap<Integer, PhylogenyNode>() );
+ setIdToNodeMap( new HashMap<Integer, PhylogenyNode>() );
for( final PhylogenyNodeIterator iter = iteratorPreorder(); iter.hasNext(); ) {
final PhylogenyNode node = iter.next();
- getIdHash().put( node.getId(), node );
+ getIdToNodeMap().put( node.getId(), node );
}
}
+ public void clearHashIdToNodeMap() {
+ setIdToNodeMap( null );
+ }
+
/**
* Deletes this Phylogeny.
*/
_description = "";
_type = "";
_distance_unit = "";
- _idhash = null;
+ _id_to_node_map = null;
_confidence = null;
_identifier = null;
_rerootable = true;
if ( isEmpty() ) {
return;
}
- _idhash = null;
+ _id_to_node_map = null;
int max = 0;
for( final PhylogenyNodeIterator it = iteratorPreorder(); it.hasNext(); ) {
final PhylogenyNode node = it.next();
if ( isEmpty() ) {
return;
}
- setIdHash( null );
+ setIdToNodeMap( null );
int i = PhylogenyNode.getNodeCount();
for( final PhylogenyNodeIterator it = iteratorPreorder(); it.hasNext(); ) {
it.next().setId( i++ );
_identifier = identifier;
}
- void setIdHash( final HashMap<Integer, PhylogenyNode> idhash ) {
- _idhash = idhash;
+ private void setIdToNodeMap( final HashMap<Integer, PhylogenyNode> idhash ) {
+ _id_to_node_map = idhash;
}
/**
}
public static void deleteExternalNodesNegativeSelection( final Set<Integer> to_delete, final Phylogeny phy ) {
- phy.hashIDs();
+ phy.clearHashIdToNodeMap();
for( final Integer id : to_delete ) {
phy.deleteSubtree( phy.getNode( id ), true );
}
- phy.hashIDs();
+ phy.clearHashIdToNodeMap();
+ phy.externalNodesHaveChanged();
}
public static void deleteExternalNodesNegativeSelection( final String[] node_names_to_delete, final Phylogeny p )
p.deleteSubtree( n, true );
}
}
+ p.clearHashIdToNodeMap();
+ p.externalNodesHaveChanged();
}
public static void deleteExternalNodesPositiveSelection( final Set<Taxonomy> species_to_keep, final Phylogeny phy ) {
throw new IllegalArgumentException( "node " + n.getId() + " has no taxonomic data" );
}
}
- phy.hashIDs();
+ phy.clearHashIdToNodeMap();
phy.externalNodesHaveChanged();
- // deleteExternalNodesNegativeSelection( to_delete, phy );
}
public static List<String> deleteExternalNodesPositiveSelection( final String[] node_names_to_keep,
}
if ( remove_me.isExternal() ) {
phylogeny.deleteSubtree( remove_me, false );
+ phylogeny.clearHashIdToNodeMap();
+ phylogeny.externalNodesHaveChanged();
}
else {
final PhylogenyNode parent = remove_me.getParent();
desc.getDistanceToParent() ) );
}
remove_me.setParent( null );
- phylogeny.setIdHash( null );
+ phylogeny.clearHashIdToNodeMap();
phylogeny.externalNodesHaveChanged();
}
}
for( final PhylogenyNode phylogenyNode : nodes_to_delete ) {
to_be_stripped.deleteSubtree( phylogenyNode, true );
}
+ to_be_stripped.clearHashIdToNodeMap();
+ to_be_stripped.externalNodesHaveChanged();
return nodes_to_delete.size();
}
_stripped_species_tree_nodes.add( s );
}
}
+ _species_tree.clearHashIdToNodeMap();
+ _species_tree.externalNodesHaveChanged();
}
public List<PhylogenyNode> getStrippedSpeciesTreeNodes() {
for( final PhylogenyNode g : _stripped_gene_tree_nodes ) {
_gene_tree.deleteSubtree( g, true );
}
+ _gene_tree.clearHashIdToNodeMap();
+ _gene_tree.externalNodesHaveChanged();
}
public Set<PhylogenyNode> getMappedExternalSpeciesTreeNodes() {
// phylos are saved
// to file.
evaluator_phylogeny.externalNodesHaveChanged();
- evaluator_phylogeny.hashIDs();
+ evaluator_phylogeny.clearHashIdToNodeMap();
evaluator_phylogeny.recalculateNumberOfExternalDescendants( true );
}
final double s = SupportCount.compare( phylogeny,
public final class ForesterConstants {
- public final static String FORESTER_VERSION = "1.004";
- public final static String FORESTER_DATE = "120619";
+ public final static String FORESTER_VERSION = "1.005";
+ public final static String FORESTER_DATE = "120629";
public final static String PHYLO_XML_VERSION = "1.10";
public final static String PHYLO_XML_LOCATION = "http://www.phyloxml.org";
public final static String PHYLO_XML_XSD = "phyloxml.xsd";