diff --git a/src/snap/Data.java b/src/snap/Data.java index 94ef213..08797b1 100644 --- a/src/snap/Data.java +++ b/src/snap/Data.java @@ -36,6 +36,7 @@ import beast.base.core.Input; import beast.base.core.ProgramStatus; import beast.base.core.Input.Validate; +import beast.base.core.Log; import beast.base.evolution.alignment.Sequence; import beast.base.evolution.alignment.Taxon; import beast.base.evolution.alignment.TaxonSet; @@ -125,6 +126,13 @@ public void initAndValidate() { } else if (rawDataType instanceof Nucleotide) { // call SNPs by setting first sequence to all zero // any character in subsequent sequences that is not the same will be set to one + Log.warning("====================================================================="); + Log.warning("WARNING: Calling SNPs by setting the first sequence to be all zero "); + Log.warning("WARNING: This may not be appropriate if your data has more than two "); + Log.warning("WARNING: states on a site and the first sequence has a low frequency"); + Log.warning("WARNING: state."); + Log.warning("====================================================================="); + String refferenceSeq = sequences.get(0).dataInput.get().replaceAll("\\s", ""); for(TaxonSet set : m_taxonsets.get()) { diff --git a/src/snap/app/inputeditor/DataInputEditor.java b/src/snap/app/inputeditor/DataInputEditor.java index 7fa557e..8da04ef 100644 --- a/src/snap/app/inputeditor/DataInputEditor.java +++ b/src/snap/app/inputeditor/DataInputEditor.java @@ -11,7 +11,9 @@ import beastfx.app.inputeditor.BeautiDoc; import beastfx.app.inputeditor.GuessPatternDialog; import beastfx.app.inputeditor.InputEditor; +import beastfx.app.util.Alert; import beastfx.app.util.FXUtils; +import javafx.application.Platform; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.EventHandler; @@ -34,6 +36,7 @@ import beast.base.evolution.alignment.Sequence; import beast.base.evolution.alignment.Taxon; import beast.base.evolution.alignment.TaxonSet; +import beast.base.evolution.datatype.Nucleotide; @@ -76,6 +79,15 @@ public void setTaxon2(String taxon2) { String m_sFilter = ".*"; int m_sortByColumn = 0; boolean m_bIsAscending = true; + + private static boolean firstNucleotideOccurance = false; + private final static String nucleotideMessage = + "A nucleotide alignment was loaded and SNPs will be called by setting the first " + + "sequence as all zeros and other sequences as 1 when they differ from the first sequence.\n\n" + + "This could lead to problems if you have sites with more than two values and the first sequence " + + "contains a low frequency state.\n\n" + + "Consider using phrynomics or other tools to preprocess your alignment instead of using the" + + "raw nucleotide alignment."; @Override public Class type() { @@ -86,6 +98,16 @@ public Class type() { @Override public void init(Input input, BEASTInterface plugin, int itemNr, ExpandOption bExpand, boolean bAddButtons) { m_input = input; + + if (!firstNucleotideOccurance) { + snap.Data data = (snap.Data) m_input.get(); + Alignment rawdata = data.m_rawData.get(); + if (rawdata.getDataType() instanceof Nucleotide) { + Platform.runLater(() -> Alert.showMessageDialog(this, nucleotideMessage)); + firstNucleotideOccurance = true; + } + } + m_beastObject = plugin; this.itemNr = itemNr; List taxonset = ((snap.Data)input.get()).m_taxonsets.get(); @@ -332,13 +354,17 @@ void parseTrait(String trait) { List taxa = new ArrayList(); for (Alignment alignment : getDoc().alignments) { for (Sequence sequence : alignment.sequenceInput.get()) { - Taxon taxon = new Taxon(); - // ensure sequence and taxon do not get same ID - if (sequence.getID() == null || sequence.getID().equals(sequence.taxonInput.get())) { - sequence.setID("_"+sequence.getID()); - } - taxon.setID(sequence.taxonInput.get()); - taxa.add(taxon); + if (!doc.taxaset.containsKey(sequence.taxonInput.get())) { + Taxon taxon = new Taxon(); + // ensure sequence and taxon do not get same ID + if (sequence.getID() == null || sequence.getID().equals(sequence.taxonInput.get())) { + sequence.setID("_"+sequence.getID()); + } + taxon.setID(sequence.taxonInput.get()); + taxa.add(taxon); + doc.addPlugin(taxon); + } + taxa.add(doc.taxaset.get(sequence.taxonInput.get())); } } HashMap map = new HashMap(); @@ -484,6 +510,7 @@ private void modelToTaxonset() { TaxonSet taxonset = new TaxonSet(); taxonset.setID(sTaxonSetID); m_taxonset.add(taxonset); + doc.addPlugin(taxonset); } m_taxonMap.put(sLineageID, sTaxonSetID); }