/
pcr_tables.el
190 lines (175 loc) · 5.67 KB
/
pcr_tables.el
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
;; functions for creating, formatting, and manipulating PCR tables
(defun pcr_reactions_table ()
"Insert and format a PCR reactions table."
(interactive)
(let* ((rxns (read-number "N. Reactions:"))
(r-count rxns)
(fragments)
(new-fragments '())
(rows (format "%s" (+ 2 (* 2 rxns))))
(ret-point))
(pcr-master-mix-table rxns)
(insert (concat "\n\n\n#+NAME: " (format-time-string "%Y.%m.%d") "_PCR_reactions_table\n"))
(org-table-create (concat "9x" rows))
(org-table-analyze)
;; while loop builds the list of fragment names
(while (> rxns 0)
(global-data-entry-mode -1)
(setq fragments (cons (read-string "Fragment name: ") fragments))
(setq fragments (cons "" fragments)
rxns (1- rxns)))
(org-table-goto-field "@1$1")
(push-mark)
(end-of-line)
(delete-region (point) (mark))
(beginning-of-line)
(forward-char 1)
(insert "-\n| N | Fragment | OFA | Sequence | fwd/rev | T_a (°C) | T_ext (sec) | Prod. Size (bp) | yield (ng/μl)")
(org-cycle)
(goto-char (org-table-end))
(insert "#+TBLFM: $1 = @# % 2 = 0 ? round((@# - 1)/2) : string(\"\")::$3 = OFA0::$5 = @# % 2 = 0 ? fwd : rev")
(org-ctrl-c-ctrl-c)
(previous-line)
(beginning-of-line)
(forward-char 1)
(insert "-")
(org-ctrl-c-ctrl-c)
(goto-char (org-table-begin))
(let ((count 11))
;; put the cursor in the correct posn. based on table dimensions
(while (> count 0)
(org-cycle)
(setq count (1- count))))
(setq ret-point (point))
(insert-rectangle (reverse fragments))
(goto-char ret-point)
(pcr-table-h-lines r-count)
(org-cycle)
(goto-char (org-table-end))
(dolist (test fragments)
(when (not (string= test ""))
(setq new-fragments (cons test new-fragments))))
(goto-char ret-point)
(org-cycle)))
;; -----
(defun pcr-table-h-lines (reactions)
"Add horizontal lines to demarcate reactions in a PCR table"
(let ((beg (org-table-begin))
(end (org-table-end))
(count 0))
(goto-char beg)
(while (and
(< (point) end)
(< count (1- reactions)))
(when
(re-search-forward "^| +[[:digit:]]\\{1,2\\}" end t)
(progn
(next-line)
(org-ctrl-c-ret)
(previous-line))
(setq curr-number (number-at-point)
count (+ 1 count)
end (org-table-end)))
(forward-char 1))
))
;; -----
(defun assembly-table ()
"Insert a table and calculate fragment amounts for an assembly reaction"
(interactive)
(insert (concat "#+NAME: " (format-time-string "%Y.%m.%d") "_Assembly_Table"))
(newline)
(let* ((n-frags (read-number "number of fragments: "))
(f-list '()))
(org-table-create (concat "6x" (format "%s" (1+ n-frags))))
(push-mark)
(end-of-line)
(delete-region (point) (mark))
(insert "| N | Component | Concentration (ng/μl) | Fragment Size (bp) | ng/0.1 pmole | Volume (μl) |")
(org-ctrl-c-ctrl-c)
(next-line)
(org-metaup)
(next-line)
(org-ctrl-c-ret)
(goto-char (org-table-end))
(insert "|-\n| \n|-")
(org-ctrl-c-ctrl-c)
(goto-char (org-table-end))
(insert "#+TBLFM: $1 = @# - 1::$5 = (0.1 * $4 * 650)/1000;%.1f::$6 = $5/$3;%.2f\n")
(insert "#+TBLFM: @>$>> = Total::@>$> = vsum(@2..@>>);%.2f")
(previous-line 3)
(org-table-analyze)
(org-table-goto-field "@2$2")
(dotimes (var n-frags)
(setq f-list (cons (read-string "fragment: ") f-list)))
(setq f-list (reverse f-list))
(insert-rectangle f-list)
(org-table-goto-field "@2$3")
(org-ctrl-c-ctrl-c)
))
;; -----
(defun pcr-master-mix-table (n-rxns)
"Insert a table with amounts to make a master mix based on 'n' reactions."
(interactive)
(insert (concat "#+NAME: " (format-time-string "%Y.%m.%d") "_Mix_Table\n"))
(org-table-create "4x9")
(push-mark)
(end-of-line)
(delete-region (point) (mark))
(insert (concat "| N | Component | 1_rxn | " (number-to-string n-rxns) "_rxns"))
(org-table-analyze)
(org-table-goto-field "@2$2")
(insert-rectangle
(mapcar
(lambda (arg) (format "%s" arg))
(list 'UPW 'HF 'dNTP 'fwd 'rev 'DNA 'phusion 'Total)))
(org-ctrl-c-ctrl-c)
(org-table-goto-field "@2$3")
(insert-rectangle
(mapcar
(lambda (arg) (format "%s" arg))
(list '32.5 '10 '1 2.5 '2.5 '1 '0.5 '50.0)))
(org-table-goto-field "@1$1")
(org-open-line 1)
(beginning-of-line)
(forward-char 1)
(insert "-")
(org-table-goto-field "@8$2")
(org-ctrl-c-ret)
(end-of-line)
(insert "\n|-")
(org-ctrl-c-ctrl-c)
(end-of-line)
(insert "\n#+TBLFM: $1 = @# - 1::@>$2 = Total")
(org-ctrl-c-ctrl-c)
(end-of-line)
(insert (concat "\n#+TBLFM: @>$3 = vsum(@2..@>>);%.1f::$4 = $3 * " (format "%s" n-rxns) ".1;%.2f"))
(org-ctrl-c-ctrl-c)
)
;; -----
(defun pcr-tubes-table (fragments)
"Create a table of tubes for a series of PCR reactions"
(insert (concat "\n\n#+NAME: " (format-time-string "%Y.%m.%d") "_Tubes_Table"))
(let* ((rows (1+ (* 2 (length fragments))))
(frag-list '()))
(org-table-create (concat "3x" (number-to-string rows)))
(forward-line 1)
(org-table-analyze)
(org-table-goto-field "@1$1")
(push-mark)
(end-of-line)
(delete-region (point) (mark))
(insert "N | Fragment | Template |")
(beginning-of-line)
(org-ctrl-c-ctrl-c)
(org-ctrl-c-ret)
(goto-char (org-table-end))
(insert "|-")
(org-ctrl-c-ctrl-c)
(end-of-line)
(insert "\n#+TBLFM: $1 = @# - 1::$3 = $1 % 2 = 0 ? no : yes")
(org-ctrl-c-ctrl-c)
(dolist (frag fragments)
(setq frag-list (cons frag (cons frag frag-list))))
(org-table-goto-field "@2$2")
(insert-rectangle frag-list)
(org-ctrl-c-ctrl-c)))