Skip to content

Commit

Permalink
improve error messages + fix taxon id numbering issue CompEvol/BeastF…
Browse files Browse the repository at this point in the history
  • Loading branch information
rbouckaert committed May 22, 2023
1 parent 4f5b496 commit 4261c54
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/snap/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
41 changes: 34 additions & 7 deletions src/snap/app/inputeditor/DataInputEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;



Expand Down Expand Up @@ -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() {
Expand All @@ -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> taxonset = ((snap.Data)input.get()).m_taxonsets.get();
Expand Down Expand Up @@ -332,13 +354,17 @@ void parseTrait(String trait) {
List<Taxon> taxa = new ArrayList<Taxon>();
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<String, TaxonSet> map = new HashMap<String, TaxonSet>();
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 4261c54

Please sign in to comment.