Skip to content

Commit

Permalink
Merge pull request #15 from jlab/tikz
Browse files Browse the repository at this point in the history
adding auto tikz algebra
  • Loading branch information
sjanssen2 authored Jan 13, 2024
2 parents 94c606f + 9351398 commit 004594b
Show file tree
Hide file tree
Showing 16 changed files with 261 additions and 142 deletions.
53 changes: 37 additions & 16 deletions alignments.gap
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ signature sig_alignments(alphabet, answer) {

algebra alg_enum auto enum;
algebra alg_count auto count;
algebra alg_tikz auto tikz;

algebra alg_similarity implements sig_alignments(alphabet=char, answer=int) {
int Ins(<alphabet a, void>, int x) {
Expand Down Expand Up @@ -190,9 +191,11 @@ algebra alg_pretty implements sig_alignments(alphabet=char, answer=typ_ali) {
}
}

// a special pretty print algebra that uses the same symbol '-' for all types of gapc
// this illustrates semantic ambiguity and is e.g. used as the introductory example
// in the lecture slides.
/*
a special pretty print algebra that uses the same symbol '-' for all types of gapc
this illustrates semantic ambiguity and is e.g. used as the introductory example
in the lecture slides.
*/
algebra alg_pretty_onegap extends alg_pretty {
typ_ali Region(<Rope afirst, void>, typ_ali x, <Rope asecond, void>) {
typ_ali res;
Expand Down Expand Up @@ -245,8 +248,10 @@ algebra alg_pretty_onegap extends alg_pretty {
}
}

// an algebra that computes a Trace representation of an Alignment,
// i.e. we arbitraily say that Insertions cannot preceed Deletions (could be vice versa)
/*
an algebra that computes a Trace representation of an Alignment,
i.e. we arbitraily say that Insertions cannot preceed Deletions (could be vice versa)
*/
algebra alg_editops implements sig_alignments(alphabet=char, answer=Rope) {
Rope Ins(<alphabet a, void>, Rope x) {
Rope res;
Expand Down Expand Up @@ -312,7 +317,9 @@ algebra alg_editops implements sig_alignments(alphabet=char, answer=Rope) {



// pair-wise global alignment
/*
pair-wise global alignment
*/
grammar gra_needlemanwunsch uses sig_alignments(axiom=A) {
A = Ins(<CHAR, EMPTY>, A)
| Del(<EMPTY, CHAR>, A)
Expand All @@ -321,11 +328,12 @@ grammar gra_needlemanwunsch uses sig_alignments(axiom=A) {
# h;
}

/* a grammar that enumerates all traces but not all alignments
difference: X- and -X are two different alignments, but the same trace
-Y Y-
this is because there is no evidence that could tell us if deletion came before insertion
or vice versa.
/*
a grammar that enumerates all traces but not all alignments
difference: X- and -X are two different alignments, but the same trace
-Y Y-
this is because there is no evidence that could tell us if deletion came before insertion
or vice versa.
*/
grammar gra_traces uses sig_alignments(axiom=A) {
A = Ins(<CHAR, EMPTY>, I)
Expand All @@ -347,7 +355,9 @@ grammar gra_traces uses sig_alignments(axiom=A) {
# h;
}

// pair-wise semiglobal alignment, i.e. long in short
/*
pair-wise semiglobal alignment, i.e. long in short
*/
grammar gra_semiglobal uses sig_alignments(axiom=S) {
S = Region(<ROPE0, EMPTY>, A, <ROPE0, EMPTY>)
# h;
Expand All @@ -359,7 +369,9 @@ grammar gra_semiglobal uses sig_alignments(axiom=S) {
# h;
}

// pair-wise end-gap-free alignment, e.g. for assembly
/*
pair-wise end-gap-free alignment, e.g. for assembly
*/
grammar gra_endgapfree uses sig_alignments(axiom=S) {
S = Region_Pr(<ROPE0, EMPTY>, A, <EMPTY, ROPE0>)
# h;
Expand All @@ -371,7 +383,9 @@ grammar gra_endgapfree uses sig_alignments(axiom=S) {
# h;
}

// pair-wise local alignment, e.g. BLAST
/*
pair-wise local alignment, e.g. BLAST
*/
grammar gra_smithwaterman uses sig_alignments(axiom=S) {
S = Region(<ROPE0, EMPTY>, T, <ROPE0, EMPTY>)
# h;
Expand All @@ -386,7 +400,9 @@ grammar gra_smithwaterman uses sig_alignments(axiom=S) {
# h;
}

// pair-wise global alignment with affine gap costs
/*
pair-wise global alignment with affine gap costs
*/
grammar gra_gotoh uses sig_alignments(axiom=A) {
A = Ins(<CHAR, EMPTY>, xIns)
| Del(<EMPTY, CHAR>, xDel)
Expand All @@ -403,6 +419,9 @@ grammar gra_gotoh uses sig_alignments(axiom=A) {
# h;
}

/*
example inputs: ZEITGEIST FREIZEIT
*/
instance ins_needlemanwunsch_count = gra_needlemanwunsch(alg_count);
instance ins_semiglobal_count = gra_semiglobal(alg_count);
instance ins_endgapfree_count = gra_endgapfree(alg_count);
Expand All @@ -425,7 +444,9 @@ instance ins_gotoh_similaritypp = gra_gotoh(alg_similarity * alg_pretty);
instance test = gra_smithwaterman(alg_pretty * alg_enum);
instance ins_traces_ppcount = gra_traces(alg_pretty * alg_count);

// used in lecture as example of how to compile:
/*
used in lecture as example of how to compile:
*/
instance ins_gotoh_pp = gra_gotoh(alg_pretty_onegap);
instance ins_gotoh_ppenum = gra_gotoh(alg_pretty_onegap * alg_enum);
instance ins_gotoh_countmanual = gra_gotoh(alg_countmanual);
Expand Down
51 changes: 34 additions & 17 deletions alignments_singletrack.gap
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ signature sig_alignments(alphabet, answer) {

algebra alg_enum auto enum;
algebra alg_count auto count;
algebra alg_tikz auto tikz;

algebra alg_similarity implements sig_alignments(alphabet=char, answer=int) {
int Ins(alphabet a, int x) {
Expand Down Expand Up @@ -232,9 +233,11 @@ algebra alg_pretty implements sig_alignments(alphabet=char, answer=typ_ali) {
}
}

// a special pretty print algebra that uses the same symbol '-' for all types of gapc
// this illustrates semantic ambiguity and is e.g. used as the introductory example
// in the lecture slides.
/*
a special pretty print algebra that uses the same symbol '-' for all types of gapc
this illustrates semantic ambiguity and is e.g. used as the introductory example
in the lecture slides.
*/
algebra alg_pretty_onegap extends alg_pretty {
typ_ali Region(Rope afirst, typ_ali x) {
typ_ali res;
Expand Down Expand Up @@ -308,8 +311,10 @@ algebra alg_pretty_onegap extends alg_pretty {
}
}

// an algebra that computes a Trace representation of an Alignment,
// i.e. we arbitraily say that Insertions cannot preceed Deletions (could be vice versa)
/*
an algebra that computes a Trace representation of an Alignment,
i.e. we arbitraily say that Insertions cannot preceed Deletions (could be vice versa)
*/
algebra alg_editops implements sig_alignments(alphabet=char, answer=Rope) {
Rope Ins(alphabet a, Rope x) {
Rope res;
Expand Down Expand Up @@ -391,9 +396,9 @@ algebra alg_editops implements sig_alignments(alphabet=char, answer=Rope) {
}
}



// pair-wise global alignment
/*
pair-wise global alignment
*/
grammar gra_needlemanwunsch uses sig_alignments(axiom=A) {
A = Ins(CHAR, A)
| Del(A, CHAR)
Expand All @@ -402,11 +407,12 @@ grammar gra_needlemanwunsch uses sig_alignments(axiom=A) {
# h;
}

/* a grammar that enumerates all traces but not all alignments
difference: X- and -X are two different alignments, but the same trace
-Y Y-
this is because there is no evidence that could tell us if deletion came before insertion
or vice versa.
/*
a grammar that enumerates all traces but not all alignments
difference: X- and -X are two different alignments, but the same trace
-Y Y-
this is because there is no evidence that could tell us if deletion came before insertion
or vice versa.
*/
grammar gra_traces uses sig_alignments(axiom=A) {
A = Ins(CHAR, I)
Expand All @@ -428,7 +434,9 @@ grammar gra_traces uses sig_alignments(axiom=A) {
# h;
}

// pair-wise semiglobal alignment, i.e. long in short
/*
pair-wise semiglobal alignment, i.e. long in short
*/
grammar gra_semiglobal uses sig_alignments(axiom=S) {
S = Region(ROPE0, A)
# h;
Expand All @@ -443,7 +451,9 @@ grammar gra_semiglobal uses sig_alignments(axiom=S) {
# h;
}

// pair-wise end-gap-free alignment, e.g. for assembly
/*
pair-wise end-gap-free alignment, e.g. for assembly
*/
grammar gra_endgapfree uses sig_alignments(axiom=S) {
S = Region_Pr(ROPE0, A)
# h;
Expand All @@ -458,7 +468,9 @@ grammar gra_endgapfree uses sig_alignments(axiom=S) {
# h;
}

// pair-wise local alignment, e.g. BLAST
/*
pair-wise local alignment, e.g. BLAST
*/
grammar gra_smithwaterman uses sig_alignments(axiom=S) {
S = Region(ROPE0, T)
# h;
Expand All @@ -479,7 +491,9 @@ grammar gra_smithwaterman uses sig_alignments(axiom=S) {
# h;
}

// pair-wise global alignment with affine gap costs
/*
pair-wise global alignment with affine gap costs
*/
grammar gra_gotoh uses sig_alignments(axiom=A) {
A = Ins(CHAR, xIns)
| Del(xDel, CHAR)
Expand All @@ -496,6 +510,9 @@ grammar gra_gotoh uses sig_alignments(axiom=A) {
# h;
}

/*
example inputs: ZEITGEIST@TIEZIERF
*/
instance ins_needlemanwunsch_count = gra_needlemanwunsch(alg_count);
instance ins_semiglobal_count = gra_semiglobal(alg_count);
instance ins_endgapfree_count = gra_endgapfree(alg_count);
Expand Down
55 changes: 31 additions & 24 deletions binary_search_tree.gap
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ signature sig_bst(alphabet, answer) {

algebra alg_enum auto enum;
algebra alg_count auto count;
algebra alg_tikz auto tikz;

// It is not trivial to see why this computation works.
// You should first draw out an example tree and compute the mean access time by hand.
// The idea is, that you need to know the "depth" of an element within the tree.
// You can than compute the mean access time as the sum of key probabilities * key depth
// In ADP, you construct the trees buttom up, i.e. you don't know the depth!!
// The trick is, that whenever you go one level up, you repreat addition of the "yield"
// seen so far to the regular mean access time from left and right components plus the new key
// AND you need to update the yield. Thus, we need a tuple as answer type.
/*
It is not trivial to see why this computation works.
You should first draw out an example tree and compute the mean access time by hand.
The idea is, that you need to know the "depth" of an element within the tree.
You can than compute the mean access time as the sum of key probabilities * key depth
In ADP, you construct the trees buttom up, i.e. you don't know the depth!!
The trick is, that whenever you go one level up, you repreat addition of the "yield"
seen so far to the regular mean access time from left and right components plus the new key
AND you need to update the yield. Thus, we need a tuple as answer type.
*/
algebra alg_mean_access_time implements sig_bst(alphabet=char, answer=typ_access) {
typ_access branch(typ_access left, typ_access entry, typ_access right) {
typ_access res;
Expand Down Expand Up @@ -47,8 +50,10 @@ algebra alg_mean_access_time implements sig_bst(alphabet=char, answer=typ_access
}
}
// note that branch(nil, X, nil) and leaf(X) both collapse to the
// pretty print: "(X)", i.e. they are semantically ambiguous!
/*
note that branch(nil, X, nil) and leaf(X) both collapse to the
pretty print: "(X)", i.e. they are semantically ambiguous!
*/
algebra alg_pretty implements sig_bst(alphabet=char, answer=Rope) {
Rope branch(Rope left, Rope x, Rope right) {
Rope res;
Expand Down Expand Up @@ -95,23 +100,25 @@ grammar gra_bst uses sig_bst(axiom = bstree) {
entry = keypair(INT, CHAR(':'), FLOAT, CHAR(',')) # h;
}
/*
example inputs: 1:0.22,3:0.18,4:0.2,8:0.05,10:0.25,11:0.02,15:0.08,
*/
/*
note the trailing , at the end of each input!
the example input above corresponds to the following table:
key prob
1 0.22
3 0.18
4 0.2
8 0.05
10 0.25
11 0.02
15 0.08
*/
instance enum = gra_bst(alg_enum);
instance count = gra_bst(alg_count);
instance matpp = gra_bst(alg_mean_access_time * alg_pretty);
instance ppmat = gra_bst(alg_pretty * alg_mean_access_time);
instance ppcount = gra_bst(alg_pretty * alg_count);
instance matppcount = gra_bst(alg_mean_access_time * alg_pretty * alg_count);
/* example input (note the trailing , at the end of each input!)
"1:0.22,3:0.18,4:0.2,8:0.05,10:0.25,11:0.02,15:0.08,"
corresponds to the following table:
key prob
1 0.22
3 0.18
4 0.2
8 0.05
10 0.25
11 0.02
15 0.08
*/
16 changes: 10 additions & 6 deletions doorplate.gap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ signature sig_doorplate(alphabet, answer) {

algebra alg_enum auto enum;
algebra alg_count auto count;
algebra alg_tikz auto tikz;

algebra alg_pretty implements sig_doorplate(alphabet=char, answer=Rope) {
Rope root(Rope x) {
Expand Down Expand Up @@ -82,13 +83,16 @@ grammar gra_doorplate uses sig_doorplate(axiom=start) {
# h;
}

/*
example inputs: <floor><office><id>M3-114</id><person>Stefan</person></office><office><id>M3-107</id><person>Maddis</person><person>Jan</person></office></floor>
*/

instance test = gra_doorplate(alg_enum);
instance pp = gra_doorplate(alg_pretty);
instance count = gra_doorplate(alg_count);

// example input:
// "<floor><office><id>M3-114</id><person>Stefan</person></office><office><id>M3-107</id><person>Maddis</person><person>Jan</person></office></floor>"

// note that there are multiple parse tree possible, because e.g.
// algebra function "person" need to start with "<person>" and end with "</person>".
// A valid parse is "<person>Maddis</person>". However, also valid is "<person>Maddis</person><person>Jan</person>".
/*
note that there are multiple parse tree possible, because e.g.
algebra function "person" need to start with "<person>" and end with "</person>".
A valid parse is "<person>Maddis</person>". However, also valid is "<person>Maddis</person><person>Jan</person>".
/*
8 changes: 5 additions & 3 deletions elmamun.gap
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ signature sig_elmamun(alphabet, answer) {
algebra alg_enum auto enum;
algebra alg_count auto count;
algebra alg_tikz auto tikz;
algebra alg_pretty implements sig_elmamun(alphabet=char, answer=Rope) {
Rope number(int value) {
Expand Down Expand Up @@ -159,12 +160,13 @@ grammar gra_elmamun uses sig_elmamun(axiom = formula) {
# h;
}
/*
example inputs: 1+2*3*4+5
*/
instance pp = gra_elmamun(alg_pretty);
instance enum = gra_elmamun(alg_enum);
instance sellerpp = gra_elmamun(alg_seller * alg_pretty);
instance buyerpp = gra_elmamun(alg_buyer * alg_pretty);
instance ppbuyer = gra_elmamun(alg_pretty * alg_buyer);
instance timepp = gra_elmamun(alg_time * alg_pretty);
// example input:
// "1+2*3*4+5"
Loading

0 comments on commit 004594b

Please sign in to comment.