forked from slyrus/cl-bio
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utilities.lisp
53 lines (43 loc) · 1.81 KB
/
utilities.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(in-package :bio)
;; utility functions
(defun split-string-into-lines-list (string &key (max-line-length 70))
(let ((line-buffer (make-string max-line-length)))
(with-input-from-string (stream string)
(loop for count = (read-sequence line-buffer stream)
while (plusp count)
collect (subseq line-buffer 0 count)))))
(defun split-string-into-lines (string &key stream max-line-length)
(format stream
"~{~A~^~&~}"
(apply #'split-string-into-lines-list string
(when max-line-length `(:max-line-length ,max-line-length)))))
(defun char-lookup-array-length (char-list)
(1+ (apply #'max
(mapcar #'char-code
(mapcan #'(lambda (x)
(list (char-upcase x)
(char-downcase x)))
char-list)))))
(defun flexichain-to-list (fc)
(loop for i below (flexichain:nb-elements fc)
collect (flexichain:element* fc i)))
(defun general-flexichain-to-string (fc)
(coerce (loop for i below (flexichain:nb-elements fc)
append (let ((el (flexichain:element* fc i)))
(cond ((characterp el)
(list el))
((stringp el)
(coerce el 'list)))))
'string))
(defun vector-flexichain-to-string (fc)
(coerce (loop for i below (flexichain:nb-elements fc)
collect (flexichain:element* fc i))
'string))
(defun find-matches (seq1 seq2)
"Returns a list of the occurences of seq1 in seq2. Note that the
instances of seq1 in seq2 can overlap such that (find-matches \"AA\"
\"AAA\" returns (0 1)."
(butlast
(loop with i = 0 while i
collect (setf i (search seq1 seq2 :start2 i))
when i do (incf i))))