2

I am using org-mode as a labbook and it is working pretty nicely.

I often have the situation where I need to state which material/reagents were used in an experiment and those are an ever growing pool that are used in multiple experiments.

Is there a way to collect all the used material/reagents in one file and be able to link to them using the mini-buffer?

I have org-ref in mind and the way it accesses bibtex files.

The idea would be to run a command that shows me a list of all the reagents/materials in a table and me being able to search the table and insert the names and other information of the reagents/materials.

Is there a way to do it already? If not, what do I need to look into to make it possible?

Thank you in advance

Edit:

Example table that would sit in a file called materials.org

| Name      | Manufacturer  | Catalog Number | Molecular Weight | Stock conc. |
|-----------+---------------+----------------+------------------+-------------|
| TWEEN® 20 | Sigma-Aldrich | P9416 SIGMA    |             1228 |        100% |

And it would be nice to access this via a search in the minibuffer and insert that line of the table into the new file.

  • Would you provide an example of a table you're using with a few sample rows, please? There are a number of ways to do this so it would be helpful to narrow the options down to the one that fits your needs best. Thanks. – Melioratus Feb 26 '17 at 18:08
  • 1
    @Melioratus updated with a small example – Cumol Feb 26 '17 at 19:42
1

Suppose instead of putting all your reagents in one file, and then looking them up you use a syntax like:

#+attr_org: :type reagents
| Tween 20 | Sigma-Aldrich | batch-1 |
| acetone  | Fisher        |    3456 |

in your notebook entries. then, you can loop through your notebook files and collect them, and use that information in a completion tool like helm. It might look something like this. Here we specify a list of files (one in this case) and loop through them collecting all the tables with an attr_org type of reagents. We eliminate duplicates, and then construct the helm candidates. Finally the helm command gives you the list, you mark what you want, and they are inserted. It doesn't offer any promise the fields are all in the same order or anything. ou could pretty easily adapt this to a single table in a single file that had a long list of reagents. After many years (maybe even months) though the table might get large, with entries you ran out of a while ago though.

(setq notebook-files '("blog.org"))

(defun insert-reagent ()
  "Insert a reagent as a table row."
  (interactive)
  (let ((candidates '()))
    (loop for nbfile in notebook-files
      do
      (setq candidates (append candidates (-flatten-n 1
                           (org-element-map (org-element-parse-buffer) 'table
                         (lambda (table)
                           (when (string=
                              "reagents"
                              (plist-get (org-export-read-attribute :attr_org table) :type))
                             (save-excursion
                               (goto-char (org-element-property :contents-begin table))
                               (org-babel-read-table)))))))))
    ;; get unique reagents
    (setq candidates (-uniq candidates))
    (setq candidates (mapcar (lambda (s)
                   (cons (mapconcat (lambda (e) (format "%s" e)) s " | ") s))
                 candidates))
    (helm :sources
      (helm-build-sync-source "Reagents"
        :candidates candidates
        :action '(("Insert" . (lambda (_)
                    (loop for choice in (helm-marked-candidates)
                      do 
                      (insert "| "
                          (mapconcat
                           (lambda (e)
                             (format "%s" e)) choice " | ")
                          " |")
                      (org-ctrl-c-ctrl-c)
                      (insert "\n")))))))))

An alternative might be to use org-headings and properties to store your information. You could then link to them with org-id for example, and have an easy way to find all the experiments that used a particular reagent.

  • Thank you for your answer! I was wondering what would be smarter in the long run. My idea was to have one file per research project (that, thanks to Scimax, I organize with projectile) and be able to collect all the reagents used in a project in one file. So, at the end of a project one would be able to compile a list of all used reagents. Also, currently I am generating PDF files of my experiment protocols when they are finished. Putting a table like the one in your response in it without column names looks weird/doesn't make sense for the reader. Any idea how to overcome it? – Cumol Feb 27 '17 at 16:49
  • Either add headers by hand or adapt the function to check if it is adding a row to an existing table and if not create one with headers. – John Kitchin Feb 27 '17 at 16:55
  • After trying around with multiple options, I ended up with one file (animals.org) that I add entries to via a capture template. The entries contain every information needed as a property. These entries are then sorted manually into sub-headings, depending on the experiment number. Whenever I am writing protocol of an experiment, I use column view to capture from another file (animals.org) and the ID of the subheading connected to the experiment. This was I have a major file with everything and tables in individual files. Any suggestions for improving/making it more elegant? – Cumol May 24 '18 at 13:33
  • You could write a function that uses completing read (or ivy/helm if you prefer) that scans that file, and offers you the options you need to insert what you want. – John Kitchin May 25 '18 at 15:48
  • 1
    There isn't an easy direction to point. One is look at how to use completing read to select things with completion, and one is how to aggregate data from org headings, and then combine them. There are some ivy commands I have written at github.com/jkitchin/scimax/blob/master/scimax-ivy.el. But you could do the same things with helm, or even ido I suppose. You just have to start with something small, solve it, then add stuff till it does what you want. – John Kitchin May 28 '18 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.