Skip to content

Commit

Permalink
added exponential distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatschiner committed Jul 28, 2022
1 parent 32ccc61 commit 589c8a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
20 changes: 12 additions & 8 deletions example.con.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# This file demonstrates the format of age constraints used by the script snapp_prep.rb:
#
# - All lines beginning with # are ignored by snapp_prep.rb, as are empty lines.
# - Lines beginning with "normal", "lognormal", "uniform", or "cladeage" are assumed to
# specify age constraints. The clades used for these constraints are always also
# constrained to be monophyletic. Clades can also be constrained to be monophyletic
# without additional age constraints. These monophyly constraints can be specified with
# lines starting with "monophyletic".
# - Lines beginning with "normal", "lognormal", "uniform", "exponential, "or "cladeage"
# are assumed to specify age constraints. The clades used for these constraints are
# always also constrained to be monophyletic. Clades can also be constrained to be
# monophyletic without additional age constraints. These monophyly constraints can be
# specified with lines starting with "monophyletic".
# - The format for these age constraints consists of three character strings separated
# by white space (tabs or spaces).
# - The first of these three character strings specifies the prior distribution, where
# the type of the distribution ("normal", "lognormal", "uniform", or "cladeage") is
# followed by the parameters of the distribution, given in parentheses and separated
# by commas.
# the type of the distribution ("normal", "lognormal", "uniform", "exponential", or
# "cladeage") is followed by the parameters of the distribution, given in parentheses
# and separated by commas.
# For a normal distribution, these parameters are (in this order)
# (1.) offset
# (2.) mean
Expand All @@ -23,6 +23,9 @@
# For a uniform distribution, these parameters are
# (1.) lower boundary
# (2.) upper boundary
# For an exponential distribution, these parameters are
# (1.) offset
# (2.) mean
# For a cladeage distribution, these parameters are
# (1.) minimum estimate of fossil age
# (2.) maximum estimate of fossil age
Expand All @@ -48,6 +51,7 @@
# - normal(10,5,1) crown speciesA,speciesB,speciesC
# - lognormal(10,5,1) stem speciesA,speciesB,speciesC
# - uniform(10,15) crown speciesA,speciesB,speciesC
# - exponential(10,5) crown speciesA,speciesB,speciesC
# - cladeage(10,11,0.01,0.02,0.2,0.5,0.001,0.01) stem speciesA,speciesB,speciesC
# - monophyletic NA speciesA,speciesB,speciesC

Expand Down
17 changes: 12 additions & 5 deletions snapp_prep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,9 @@
else
constraint_type = constraint_distribution.split("(")[0].strip
end
unless ["normal","lognormal","uniform","cladeage","monophyletic"].include?(constraint_type)
puts "ERROR: Expected 'normal', 'lognormal', 'uniform', 'cladeage', or 'monophyletic' as part"
puts " of the first character string in '#{c}' but found '#{constraint_type}'!"
unless ["normal","lognormal","uniform","exponential","cladeage","monophyletic"].include?(constraint_type)
puts "ERROR: Expected 'normal', 'lognormal', 'uniform', 'exponential', 'cladeage', or 'monophyletic'"
puts " as part of the first character string in '#{c}' but found '#{constraint_type}'!"
exit(1)
end
unless constraint_type == "monophyletic"
Expand All @@ -857,12 +857,17 @@
end
elsif constraint_type == "uniform"
unless constraint_parameters.size == 2
puts "ERROR: Expected 2 parameters for lognormal distribution, but found #{constraint_parameters.size}!"
puts "ERROR: Expected 2 parameters for uniform distribution, but found #{constraint_parameters.size}!"
exit(1)
end
elsif constraint_type == "exponential"
unless constraint_parameters.size == 2
puts "ERROR: Expected 2 parameters for exponential distribution, but found #{constraint_parameters.size}!"
exit(1)
end
elsif constraint_type == "cladeage"
unless constraint_parameters.size == 8
puts "ERROR: Expected 8 parameters for lognormal distribution, but found #{constraint_parameters.size}!"
puts "ERROR: Expected 8 parameters for cladeage distribution, but found #{constraint_parameters.size}!"
exit(1)
end
else
Expand Down Expand Up @@ -905,6 +910,8 @@
xml_string << " </LogNormal>\n"
elsif constraint_type == "uniform"
xml_string << " <Uniform name=\"distr\" lower=\"#{constraint_parameters[0]}\" upper=\"#{constraint_parameters[1]}\"/>\n"
elsif constraint_type == "exponential"
xml_string << " <Exponential name=\"distr\" offset=\"#{constraint_parameters[0]}\" mean=\"#{constraint_parameters[1]}\"/>\n"
elsif constraint_type == "cladeage"
xml_string << " <fossilDistr\n"
xml_string << " id=\"#{constraint_id}\"\n"
Expand Down

0 comments on commit 589c8a5

Please sign in to comment.