- Feb 3, 2005
- 7,326
- 2
- 76
On my latest assignment, I'm stuck with two problems:
1. DNA is sampled in small fragments, which are then glued together into a longer strand. Define a procedure fuse-fragments which takes two DNA sequences, seq1 and seq2, locates the area of overlap, and returns the result of joining the two sequences together. The overlap area is the longest suffix of seq1 that matches a prefix of seq2 and it only appears once in the resulting sequence. Hint: use the prefix? procedure that you defined in the previous problem.
> (fuse-fragments '(a a a t t t t) '(t t t t g g g g g))
(a a a t t t t g g g g g)
> (fuse-fragments '(a a a) '(g g g))
(a a a g g g)
> (fuse-fragments '(a t t a) '(t t a a))
(a t t a a)
This is what I defined prefix as:
; prefix? takes two lists and returns #t if the first list is a prefix of the
; second list, and #f otherwise
(define prefix?
(lambda (ls1 ls2)
(if (null? ls1)
#t
(if (equal? (car ls1) (car ls2))
(prefix? (cdr ls1) (cdr ls2))
#f))))
And the next problem:
2. In a highly simplified model of reproduction, the DNA from two parents is combined to form the DNA of the offspring. In a process called crossover, corresponding chunks of the parent's DNA are exchanged. The following diagram illustrates what happens when there is just one crossover point.
Define a procedure crossover that takes two DNA sequences and a single crossover point (i.e., a number indicating where the transition occurs), and returns the DNA for the offspring. You may assume that both parent sequences are the same length, say n, and the crossover point is an integer in the range 1 to n -1, inclusive.
> (crossover '(a c t) '(t g g) 2)
(a c g)
> (crossover '(a a a a a a a a a a) '(t t t t t t t t t t) 4)
(a a a a t t t t t t)
> (crossover
'(t t t t t t t t t t t t t)
'(a a a a a a a a a a a a a)
8)
(t t t t t t t t a a a a a)
Any hints or help? I'd greatly appreciate it.
1. DNA is sampled in small fragments, which are then glued together into a longer strand. Define a procedure fuse-fragments which takes two DNA sequences, seq1 and seq2, locates the area of overlap, and returns the result of joining the two sequences together. The overlap area is the longest suffix of seq1 that matches a prefix of seq2 and it only appears once in the resulting sequence. Hint: use the prefix? procedure that you defined in the previous problem.
> (fuse-fragments '(a a a t t t t) '(t t t t g g g g g))
(a a a t t t t g g g g g)
> (fuse-fragments '(a a a) '(g g g))
(a a a g g g)
> (fuse-fragments '(a t t a) '(t t a a))
(a t t a a)
This is what I defined prefix as:
; prefix? takes two lists and returns #t if the first list is a prefix of the
; second list, and #f otherwise
(define prefix?
(lambda (ls1 ls2)
(if (null? ls1)
#t
(if (equal? (car ls1) (car ls2))
(prefix? (cdr ls1) (cdr ls2))
#f))))
And the next problem:
2. In a highly simplified model of reproduction, the DNA from two parents is combined to form the DNA of the offspring. In a process called crossover, corresponding chunks of the parent's DNA are exchanged. The following diagram illustrates what happens when there is just one crossover point.
Define a procedure crossover that takes two DNA sequences and a single crossover point (i.e., a number indicating where the transition occurs), and returns the DNA for the offspring. You may assume that both parent sequences are the same length, say n, and the crossover point is an integer in the range 1 to n -1, inclusive.
> (crossover '(a c t) '(t g g) 2)
(a c g)
> (crossover '(a a a a a a a a a a) '(t t t t t t t t t t) 4)
(a a a a t t t t t t)
> (crossover
'(t t t t t t t t t t t t t)
'(a a a a a a a a a a a a a)
8)
(t t t t t t t t a a a a a)
Any hints or help? I'd greatly appreciate it.
