Skip to content

Commit

Permalink
js/makepsw.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ihh committed Oct 29, 2018
1 parent 07f11b7 commit 532bf22
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions js/makepsw.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var getopt = Getopt.create([
['a' , 'alphabet=STRING' , 'alphabet'],
['n' , 'name=STRING' , 'name'],
['m' , 'mix=N' , 'no. of components to mixture geometric indel-length distribution'],
['i' , 'irrev' , 'allow insertion & deletion probs to be different (not strictly the same as irreversibility, but close)'],
['w' , 'write' , 'write preset & constraints files'],
['p' , 'pretty'],
['h' , 'help' , 'display this help message']
Expand All @@ -22,9 +23,9 @@ function inputError(err) {

opt.options.alphabet || inputError ("Please specify an alphabet")
opt.options.name || inputError ("Please specify a model name")
var alph = opt.options.alphabet.split("")
var name = opt.options.name
var mixCpts = opt.options.mix
const alph = opt.options.alphabet.split("")
const name = opt.options.name
const mixCpts = opt.options.mix

function transitions (inLabel, outLabel, dest) {
return alph.map (function (c) {
Expand All @@ -36,7 +37,7 @@ function transitions (inLabel, outLabel, dest) {
}

function not (param) {
return {"-":[true,param]}
return {"not":param}
}

function times (expr1,expr2) {
Expand All @@ -50,20 +51,35 @@ function iota (n) {
: new Array(parseInt(n)).fill(0).map (function(_val,k) { return k + 1 }))
}

const irrev = opt.options.irrev
function capitalize(text) { return text[0].toUpperCase() + text.substr(1) }

function insOrGap(upper) { var str = irrev ? "ins" : "gap"; return upper ? capitalize(str) : str }
function insParam(type) { return insOrGap() + type }
function insOpen(k) { return insParam ("Open" + k) }
function insExtend(k) { return insParam ("Extend" + k) }
function notInsOpen() { return (mixCpts ? ("not" + insOrGap(true) + "Open") : not(insOrGap() + "Open")) }

function delOrGap(upper) { var str = irrev ? "del" : "gap"; return upper ? capitalize(str) : str }
function delParam(type) { return delOrGap() + type }
function delOpen(k) { return delParam ("Open" + k) }
function delExtend(k) { return delParam ("Extend" + k) }
function notDelOpen() { return (mixCpts ? ("not" + delOrGap(true) + "Open") : not(delOrGap() + "Open")) }

var iotaMix = iota (mixCpts)
var machine = { state: [{id: name+"-S",
trans: iotaMix.map ((k) => {return {to: name+"-I"+k, weight: "gapOpen"+k}} )
.concat ([{ to: name+"-W", weight: (mixCpts ? "notGapOpen" : not("gapOpen")) }])}]
trans: iotaMix.map ((k) => {return {to: name+"-I"+k, weight: insOpen(k)}} )
.concat ([{ to: name+"-W", weight: notInsOpen() }])}]
.concat (iotaMix.map ((k) => { return {id: name+"-J"+k,
trans: [{to: name+"-I"+k, weight: "gapExtend"+k},
{to: name+"-W", weight: not("gapExtend"+k)}]} }))
trans: [{to: name+"-I"+k, weight: insExtend(k)},
{to: name+"-W", weight: not(insExtend(k))}]} }))
.concat ([{id: name+"-W",
trans: [{ to: name+"-M", weight: (mixCpts ? "notGapOpen" : not("gapOpen")) }]
.concat (iotaMix.map ((k) => { return {to: name+"-D"+k, weight: "gapOpen"+k} } ))
trans: [{ to: name+"-M", weight: notDelOpen() }]
.concat (iotaMix.map ((k) => { return {to: name+"-D"+k, weight: delOpen(k)} } ))
}])
.concat (iotaMix.map ((k) => { return {id: name+"-X"+k,
trans: [{to: name+"-D"+k, weight: "gapExtend"+k},
{to: name+"-M", weight: not("gapExtend"+k)}]} } ))
trans: [{to: name+"-D"+k, weight: delExtend(k)},
{to: name+"-M", weight: not(delExtend(k))}]} } ))
.concat (iotaMix.map ((k) => { return {id: name+"-I"+k,
trans: alph.map ((c) => {return { out: c, to: name+"-J"+k, weight: "eqm"+c } })} }))
.concat ([{id: name+"-M",
Expand All @@ -74,12 +90,13 @@ var machine = { state: [{id: name+"-S",
.concat (alph.map ((c) => {return { in: c, to: name+"-X"+k }}))} } ))
.concat ([{id: name+"-E"} ]),
cons: { prob: (mixCpts
? iotaMix.map ((k) => "gapExtend"+k)
: ["gapOpen","gapExtend"]),
? iotaMix.map(insExtend).concat (irrev ? iotaMix.map(delExtend) : [])
: (irrev ? ["insOpen","insExtend","delOpen","delExtend"] : ["gapOpen","gapExtend"])),
norm: [alph.map ((c) => "eqm"+c)]
.concat (alph.map ((c) => alph.map ((d)=>"sub"+c+d)))
.concat (mixCpts
? [iotaMix.map((k)=>"gapOpen"+k).concat("notGapOpen")]
? ([iotaMix.map(insOpen).concat([notInsOpen()])]
.concat (irrev ? [iotaMix.map(delOpen).concat([notDelOpen()])] : []))
: []) } }

if (opt.options.write) {
Expand Down

0 comments on commit 532bf22

Please sign in to comment.