Skip to content

Commit

Permalink
provide example inputs and reformat comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanssen2 committed Jan 13, 2024
1 parent e1a4953 commit 9351398
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 114 deletions.
50 changes: 33 additions & 17 deletions alignments_singletrack.gap
Original file line number Diff line number Diff line change
Expand Up @@ -233,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 @@ -309,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 @@ -392,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 @@ -403,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 @@ -429,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 @@ -444,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 @@ -459,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 @@ -480,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 @@ -497,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
54 changes: 30 additions & 24 deletions binary_search_tree.gap
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ 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 @@ -48,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 @@ -96,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
*/
6 changes: 4 additions & 2 deletions genefinder.gap
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,12 @@ grammar gra_genefinder uses sig_genefinder(axiom = start) {
# h;
}

/*
example inputs: AAUAUGUCUGUUAAUGCAAUGGCGGCGAUUGAGUUUUCCAAGUAGAAUGAGGAUG
*/

instance ins_aa = gra_genefinder(alg_translate);
instance ins_aacount = gra_genefinder(alg_translate * alg_count);
instance ins_scoreaa = gra_genefinder(alg_score * alg_translate);
instance ins_aascore = gra_genefinder(alg_translate * alg_score);
instance ins_count = gra_genefinder(alg_count);

// example input "AAUAUGUCUGUUAAUGCAAUGGCGGCGAUUGAGUUUUCCAAGUAGAAUGAGGAUG"
4 changes: 4 additions & 0 deletions hmm_casino.gap
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ grammar gra_casino uses sig_casino(axiom=start) {
# h;
}

/*
example inputs: 15626
*/

instance enum = gra_casino(alg_enum);
instance viterbistatesmult = gra_casino(alg_viterbi * alg_states * alg_mult);
instance fwd = gra_casino(alg_fwd);
Expand Down
4 changes: 4 additions & 0 deletions hmm_cpg.gap
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ grammar gra_cpg uses sig_cpg(axiom=start) {
# h;
}

/*
example inputs: GCGGCCGA
*/

instance enum = gra_cpg(alg_enum);
instance viterbistatesmult = gra_cpg(alg_viterbi * alg_states * alg_mult);
instance fwd = gra_cpg(alg_fwd);
Expand Down
4 changes: 4 additions & 0 deletions hmm_markovchain.gap
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ grammar gra_dinuc uses sig_dinuc(axiom=state_init) {
state_end = nil(EMPTY);
}

/*
example inputs: ACCT
*/

instance ins_ppprobenum = gra_dinuc(alg_pretty * alg_prob * alg_enum);
4 changes: 4 additions & 0 deletions hmm_sonneregen.gap
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ grammar gra_weather uses sig_weather(axiom=start) {
# h;
}

/*
example inputs: SSRR
*/

instance enum = gra_weather(alg_enum);
instance viterbistatesmult = gra_weather(alg_viterbi * alg_states * alg_mult);
instance fwd = gra_weather(alg_fwd);
Expand Down
8 changes: 7 additions & 1 deletion hmm_transmembrane.gap
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ algebra alg_structure implements sig_transmembrane(alphabet=char, answer=Rope) {
}
}

//st_ short for state, em_ short for emission
/*
st_ short for state, em_ short for emission
*/
grammar gra_transmembrane uses sig_transmembrane(axiom=st_init) {
st_init = transition(CONST_FLOAT(0.89), CONST_CHAR('e'), em_ext, st_ext)
| transition(CONST_FLOAT(0.01), CONST_CHAR('T'), em_trans, st_trans)
Expand Down Expand Up @@ -135,4 +137,8 @@ grammar gra_transmembrane uses sig_transmembrane(axiom=st_init) {
# h;
}

/*
example inputs: GCGGCCGA
*/

instance test = gra_transmembrane(alg_states);
18 changes: 11 additions & 7 deletions matrix_chain_multiplication.gap
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,24 @@ algebra alg_kdepth extends alg_depth {
}
/*
note: right now, we "accept" impossible matrix chains,
i.e. left.cols is not enforced to be right.rows
*/
grammar gra_matmult uses sig_matmult(axiom = formula) {
// note: right now, we "accept" impossible matrix chains,
// i.e. left.cols is not enforced to be right.rows
formula = single(CHAR('('), INT, CHAR('x'), INT, CHAR(')'))
| mult(formula, CHAR('*'), formula)
# h;
}
/*
take care when applying the assertMatchingDimensions:
1) instance must contain alg_minmult
2) parenthesis become important in algebra products: alg_minmult * alg_enum * alg_count implicitly is
(alg_minmult * alg_enum) * alg_count, which will fail to compile
use explicit parenthesis like: alg_minmult * (alg_enum * alg_count)
*/
grammar gra_matmult_assert uses sig_matmult(axiom = formula) {
// take care when applying the assertMatchingDimensions:
// 1) instance must contain alg_minmult
// 2) parenthesis become important in algebra products: alg_minmult * alg_enum * alg_count implicitly is
// (alg_minmult * alg_enum) * alg_count, which will fail to compile
// use explicit parenthesis like: alg_minmult * (alg_enum * alg_count)
formula = single(CHAR('('), INT, CHAR('x'), INT, CHAR(')'))
| mult(formula, CHAR('*'), formula) suchthat_overlay assertMatchingDimension
# h;
Expand Down
3 changes: 3 additions & 0 deletions palindromes.gap
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ grammar gra_palloc uses sig_palindrome(axiom = skip_l) {
# h;
}

/*
example inputs: abbabaabba
*/

instance enum = gra_palindrome(alg_enum);
instance loc = gra_palloc(alg_palScore * alg_pretty);
Expand Down
Loading

0 comments on commit 9351398

Please sign in to comment.