public void linkModels() { int[] selRows = dataTable.getSelectedRows(); List<AbstractPartitionData> selectedPartitionData = new ArrayList<AbstractPartitionData>(); DataType dateType = null; for (int row : selRows) { AbstractPartitionData partition = options.dataPartitions.get(row); if (dateType == null) { dateType = partition.getDataType(); } else { if (partition.getDataType() != dateType) { JOptionPane.showMessageDialog( this, "Can only link the models for data partitions \n" + "of the same data type (e.g., nucleotides)", "Unable to link models", JOptionPane.ERROR_MESSAGE); return; } } if (!selectedPartitionData.contains(partition)) selectedPartitionData.add(partition); } Object[] modelArray = options.getPartitionSubstitutionModels(selectedPartitionData).toArray(); if (selectModelDialog == null) { selectModelDialog = new SelectModelDialog(frame); } int result = selectModelDialog.showDialog(modelArray); if (result != JOptionPane.CANCEL_OPTION) { PartitionSubstitutionModel model = selectModelDialog.getModel(); if (selectModelDialog.getMakeCopy()) { model.setName(selectModelDialog.getName()); } for (AbstractPartitionData partition : selectedPartitionData) { partition.setPartitionSubstitutionModel(model); } } if (options.getPartitionSubstitutionModels(Microsatellite.INSTANCE).size() <= 1) { options.shareMicroSat = true; } modelsChanged(); fireDataChanged(); repaint(); }
public void unlinkModels() { int[] selRows = dataTable.getSelectedRows(); for (int row : selRows) { PartitionData partition = options.dataPartitions.get(row); PartitionSubstitutionModel model = partition.getPartitionSubstitutionModel(); if (!model.getName().equals(partition.getName())) { PartitionSubstitutionModel newModel = new PartitionSubstitutionModel(options, partition); partition.setPartitionSubstitutionModel(newModel); } } modelsChanged(); fireDataChanged(); repaint(); }
/** Lays out the appropriate components in the panel for this partition model. */ private void setupPanel() { switch (model.getDataType().getType()) { case DataType.NUCLEOTIDES: addComponentWithLabel("Substitution Model:", nucSubstCombo); addComponentWithLabel("Base frequencies:", frequencyCombo); addComponentWithLabel("Site Heterogeneity Model:", heteroCombo); heteroCombo.setSelectedIndex(0); gammaCatLabel = addComponentWithLabel("Number of Gamma Categories:", gammaCatCombo); gammaCatCombo.setEnabled(false); addSeparator(); addComponentWithLabel("Partition into codon positions:", codingCombo); JPanel panel2 = new JPanel(); panel2.setOpaque(false); panel2.setLayout(new BoxLayout(panel2, BoxLayout.PAGE_AXIS)); panel2.setBorder(BorderFactory.createTitledBorder("Link/Unlink parameters:")); panel2.add(substUnlinkCheck); panel2.add(heteroUnlinkCheck); panel2.add(freqsUnlinkCheck); addComponent(panel2); addComponent(setYang96Button); addComponent(setSRD06Button); break; case DataType.AMINO_ACIDS: addComponentWithLabel("Substitution Model:", aaSubstCombo); addComponentWithLabel("Citation:", citationText); addComponentWithLabel("Site Heterogeneity Model:", heteroCombo); heteroCombo.setSelectedIndex(0); gammaCatLabel = addComponentWithLabel("Number of Gamma Categories:", gammaCatCombo); gammaCatCombo.setEnabled(false); break; case DataType.TWO_STATES: case DataType.COVARION: addComponentWithLabel("Substitution Model:", binarySubstCombo); addComponentWithLabel("Base frequencies:", frequencyCombo); addComponentWithLabel("Site Heterogeneity Model:", heteroCombo); heteroCombo.setSelectedIndex(0); gammaCatLabel = addComponentWithLabel("Number of Gamma Categories:", gammaCatCombo); gammaCatCombo.setEnabled(false); addSeparator(); addComponentWithLabel("", useAmbiguitiesTreeLikelihoodCheck); // Easy XML specification is currently only available for binary models if (ENABLE_STOCHASTIC_DOLLO) { addSeparator(); addComponent(dolloCheck); } break; case DataType.GENERAL: addComponentWithLabel("Discrete Trait Substitution Model:", discreteTraitSiteModelCombo); addComponent(activateBSSVS); break; case DataType.CONTINUOUS: addComponentWithLabel("Continuous Trait Model:", continuousTraitSiteModelCombo); addComponent(latLongCheck); addSeparator(); addComponent(useLambdaCheck); break; case DataType.MICRO_SAT: addComponentWithLabel("Microsatellite Name:", microsatName); addComponentWithLabel("Max of Length:", microsatMax); addComponentWithLabel("Min of Length:", microsatMin); addComponent(shareMicroSatCheck); addSeparator(); addComponentWithLabel("Rate Proportionality:", rateProportionCombo); addComponentWithLabel("Mutational Bias:", mutationBiasCombo); addComponentWithLabel("Phase:", phaseCombo); break; default: throw new IllegalArgumentException("Unknown data type"); } setOptions(); }
/** * Sets the components up according to the partition model - but does not layout the top level * options panel. */ public void setOptions() { if (SiteModelsPanel.DEBUG) { String modelName = (model == null) ? "null" : model.getName(); Logger.getLogger("dr.app.beauti").info("ModelsPanel.setModelOptions(" + modelName + ")"); } if (model == null) { return; } int dataType = model.getDataType().getType(); switch (dataType) { case DataType.NUCLEOTIDES: nucSubstCombo.setSelectedItem(model.getNucSubstitutionModel()); frequencyCombo.setSelectedItem(model.getFrequencyPolicy()); break; case DataType.AMINO_ACIDS: aaSubstCombo.setSelectedItem(model.getAaSubstitutionModel()); break; case DataType.TWO_STATES: case DataType.COVARION: binarySubstCombo.setSelectedItem(model.getBinarySubstitutionModel()); useAmbiguitiesTreeLikelihoodCheck.setSelected(model.isUseAmbiguitiesTreeLikelihood()); break; case DataType.GENERAL: discreteTraitSiteModelCombo.setSelectedItem(model.getDiscreteSubstType()); activateBSSVS.setSelected(model.isActivateBSSVS()); break; case DataType.CONTINUOUS: continuousTraitSiteModelCombo.setSelectedItem(model.getContinuousSubstModelType()); ContinuousComponentOptions component = (ContinuousComponentOptions) model.getOptions().getComponentOptions(ContinuousComponentOptions.class); latLongCheck.setSelected(model.isLatitudeLongitude()); latLongCheck.setEnabled(model.getContinuousTraitCount() == 2); useLambdaCheck.setSelected(component.useLambda(model)); break; case DataType.MICRO_SAT: microsatName.setText(model.getMicrosatellite().getName()); microsatMax.setText(Integer.toString(model.getMicrosatellite().getMax())); microsatMin.setText(Integer.toString(model.getMicrosatellite().getMin())); shareMicroSatCheck.setSelected(model.getOptions().shareMicroSat); rateProportionCombo.setSelectedItem(model.getRatePorportion()); mutationBiasCombo.setSelectedItem(model.getMutationBias()); phaseCombo.setSelectedItem(model.getPhase()); shareMicroSatCheck.setEnabled( model.getOptions().getPartitionSubstitutionModels(Microsatellite.INSTANCE).size() > 1); break; default: throw new IllegalArgumentException("Unknown data type"); } if (model.isGammaHetero() && !model.isInvarHetero()) { heteroCombo.setSelectedIndex(1); } else if (!model.isGammaHetero() && model.isInvarHetero()) { heteroCombo.setSelectedIndex(2); } else if (model.isGammaHetero() && model.isInvarHetero()) { heteroCombo.setSelectedIndex(3); } else { heteroCombo.setSelectedIndex(0); } gammaCatCombo.setSelectedIndex(model.getGammaCategories() - 4); if (model.getCodonHeteroPattern() == null) { codingCombo.setSelectedIndex(0); } else if (model.getCodonHeteroPattern().equals("112")) { codingCombo.setSelectedIndex(1); } else { codingCombo.setSelectedIndex(2); } substUnlinkCheck.setSelected(model.isUnlinkedSubstitutionModel()); heteroUnlinkCheck.setSelected(model.isUnlinkedHeterogeneityModel()); freqsUnlinkCheck.setSelected(model.isUnlinkedFrequencyModel()); dolloCheck.setSelected(model.isDolloModel()); }
/** * write log to file * * @param writer XMLWriter * @param treePriorGenerator TreePriorGenerator * @param branchRatesModelGenerator BranchRatesModelGenerator * @param substitutionModelGenerator SubstitutionModelGenerator * @param treeLikelihoodGenerator TreeLikelihoodGenerator * @param generalTraitGenerator */ public void writeLogToFile( XMLWriter writer, TreePriorGenerator treePriorGenerator, BranchRatesModelGenerator branchRatesModelGenerator, SubstitutionModelGenerator substitutionModelGenerator, TreeLikelihoodGenerator treeLikelihoodGenerator, GeneralTraitGenerator generalTraitGenerator) { writer.writeComment("write log to file"); if (options.logFileName == null) { options.logFileName = options.fileNameStem + ".log"; } writer.writeOpenTag( LoggerParser.LOG, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, "fileLog"), new Attribute.Default<String>(LoggerParser.LOG_EVERY, options.logEvery + ""), new Attribute.Default<String>(LoggerParser.FILE_NAME, options.logFileName), new Attribute.Default<Boolean>( LoggerParser.ALLOW_OVERWRITE_LOG, options.allowOverwriteLog) }); if (options.hasData()) { writer.writeIDref(CompoundLikelihoodParser.POSTERIOR, "posterior"); } writer.writeIDref(CompoundLikelihoodParser.PRIOR, "prior"); if (options.hasData()) { writer.writeIDref(CompoundLikelihoodParser.LIKELIHOOD, "likelihood"); } if (options.useStarBEAST) { // species // coalescent prior writer.writeIDref( MultiSpeciesCoalescentParser.SPECIES_COALESCENT, TraitData.TRAIT_SPECIES + "." + COALESCENT); // prior on population sizes // if (options.speciesTreePrior == TreePriorType.SPECIES_YULE) { writer.writeIDref(MixedDistributionLikelihoodParser.DISTRIBUTION_LIKELIHOOD, SPOPS); // } else { // writer.writeIDref(SpeciesTreeBMPrior.STPRIOR, STP); // } // prior on species tree writer.writeIDref(SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD, SPECIATION_LIKE); writer.writeIDref( ParameterParser.PARAMETER, TraitData.TRAIT_SPECIES + "." + options.starBEASTOptions.POP_MEAN); writer.writeIDref( ParameterParser.PARAMETER, SpeciesTreeModelParser.SPECIES_TREE + "." + SPLIT_POPS); if (options.getPartitionTreePriors().get(0).getNodeHeightPrior() == TreePriorType.SPECIES_BIRTH_DEATH) { writer.writeIDref( ParameterParser.PARAMETER, TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.MEAN_GROWTH_RATE_PARAM_NAME); writer.writeIDref( ParameterParser.PARAMETER, TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.RELATIVE_DEATH_RATE_PARAM_NAME); } else if (options.getPartitionTreePriors().get(0).getNodeHeightPrior() == TreePriorType.SPECIES_YULE) { writer.writeIDref( ParameterParser.PARAMETER, TraitData.TRAIT_SPECIES + "." + YuleModelParser.YULE + "." + YuleModelParser.BIRTH_RATE); } else { throw new IllegalArgumentException( "Get wrong species tree prior using *BEAST : " + options.getPartitionTreePriors().get(0).getNodeHeightPrior().toString()); } // Species Tree: tmrcaStatistic writer.writeIDref( TMRCAStatisticParser.TMRCA_STATISTIC, SpeciesTreeModelParser.SPECIES_TREE + "." + TreeModelParser.ROOT_HEIGHT); } for (PartitionTreeModel model : options.getPartitionTreeModels()) { writer.writeIDref( ParameterParser.PARAMETER, model.getPrefix() + TreeModel.TREE_MODEL + "." + TreeModelParser.ROOT_HEIGHT); } for (Taxa taxa : options.taxonSets) { // make tmrca(tree.name) eay to read in log for Tracer writer.writeIDref( TMRCAStatisticParser.TMRCA_STATISTIC, "tmrca(" + taxa.getTreeModel().getPrefix() + taxa.getId() + ")"); } // if ( options.shareSameTreePrior ) { // Share Same Tree Prior // treePriorGenerator.setModelPrefix(""); // treePriorGenerator.writeParameterLog(options.activedSameTreePrior, writer); // } else { // no species for (PartitionTreePrior prior : options.getPartitionTreePriors()) { // treePriorGenerator.setModelPrefix(prior.getPrefix()); // priorName.treeModel treePriorGenerator.writeParameterLog(prior, writer); } // } for (PartitionSubstitutionModel model : options.getPartitionSubstitutionModels()) { substitutionModelGenerator.writeLog(writer, model); if (model.hasCodon()) { writer.writeIDref(CompoundParameterParser.COMPOUND_PARAMETER, model.getPrefix() + "allMus"); } } if (options.clockModelOptions.getRateOptionClockModel() == FixRateType.FIX_MEAN) { writer.writeIDref(ParameterParser.PARAMETER, "allClockRates"); for (PartitionClockModel model : options.getPartitionClockModels()) { if (model.getClockType() == ClockType.UNCORRELATED_LOGNORMAL) writer.writeIDref(ParameterParser.PARAMETER, model.getPrefix() + ClockType.UCLD_STDEV); } } else { for (PartitionClockModel model : options.getPartitionClockModels()) { branchRatesModelGenerator.writeLog(model, writer); } } for (PartitionClockModel model : options.getPartitionClockModels()) { branchRatesModelGenerator.writeLogStatistic(model, writer); } generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_FILE_LOG_PARAMETERS, writer); if (options.hasData()) { treeLikelihoodGenerator.writeTreeLikelihoodReferences(writer); } generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_FILE_LOG_LIKELIHOODS, writer); // coalescentLikelihood for (PartitionTreeModel model : options.getPartitionTreeModels()) { PartitionTreePrior prior = model.getPartitionTreePrior(); treePriorGenerator.writePriorLikelihoodReferenceLog(prior, model, writer); writer.writeText(""); } for (PartitionTreePrior prior : options.getPartitionTreePriors()) { if (prior.getNodeHeightPrior() == TreePriorType.EXTENDED_SKYLINE) writer.writeIDref( CoalescentLikelihoodParser.COALESCENT_LIKELIHOOD, prior.getPrefix() + COALESCENT); // only 1 coalescent } if (options.hasDiscreteIntegerTraitsExcludeSpecies()) { generalTraitGenerator.writeAncestralTreeLikelihoodReferences(writer); } writer.writeCloseTag(LoggerParser.LOG); generateInsertionPoint(ComponentGenerator.InsertionPoint.AFTER_FILE_LOG, writer); }