### Archive

Archive for March, 2013

## eMarch 5 : Tramp

We are all living in a modern world, the cloud is everywhere and of course also in emacs. So the closing post of this serie will talk about tramp. Tramp is so rich of features that a post won’t be enough. I’ll focus on the point I’ve used so far.

## Basic use

I generally use a lot of ssh connection. Tramp allows me to naviguate through the remote directory as if they were on my local machine. The basic commands C-x D and C-x f just need a special syntax to describe the path to the file directory you want to access to.

With ssh, the syntax is similar to the scp one. Hence to access the file test.txt in your home directory “~” on remote host “rem1” , just do

```C-x C-f
/ssh:rem1:~/test.txt```

To access the directory “/work/you/project” on remote1 “remote1.com”, ip “127.0.0.1”

```C-x d
/ssh:remote1.com:/work/you/project
/ssh:127.0.0.1:/work/you/project```

Last, while visiting a remote directory, if you start a shell buffer with “M-x shell”, the later will be started on the remote host. If a shell buffer is already open on your localhost, M-x shell will redirect you to this buffer. The trick here is to use  C-u M-x shell to start a second buffer shell.

## Some other hints

Of course the neat way to access remote host is to create a ssh config file. Anyway if your login on the remote host is different from the one you generally use, or if you are using a tunnel with a different port, you ‘ll have to modify your path.

Taking the former example, assuming now that your login is “Name” you want to connect on localhost port 9022 (We are considering an access via an ssh tunnel).

```C-x d
/ssh:Name@remote1.com#9022:/work/you/project```

Other useful tips and alternative can be found on the emacs wiki tramp page, like :

• setting a default tramp user with (setq tramp-default-user “ClassicalLogin”)
• setting a default tramp protocol (setq tramp-default-method “ssh”)
Categories: emacs, Linux, Shell

## eMarch 4: Compilation environment variable

I sometime use improved library like mkl, in my code, the later need to have their path added to the LD_LIBRARY_PATH, in order to be accessed during compilation. Eventually, this may prevent the very handful M-x compile command to work with emacs. The fix I found on stackoverflow

```(let ((path (shell-command-to-string ". ~/.bashrc; echo -n \$PATH")))
(setenv "PATH" path)
(setq exec-path
(append
(split-string-and-unquote path ":")
exec-path)))
(let ((ld_library_path (shell-command-to-string ". ~/.bashrc; echo -n \$LD_LIBRARY_PATH")))
(setenv "LD_LIBRARY_PATH" ld_library_path)
(setq exec-path
(append
(split-string-and-unquote ld_library_path ":")
exec-path)))
```
Categories: emacs, Fortran, Linux

## Recent articles

March 21, 2013 1 comment

Just a small review of the articles I went through recently :

• Two inspiring articles discussing genetic architecture : one on missing heritability and the other on beavis effect
• The buzz article criticizing the ENCODE project.
• A  potentially interesting algorithm Herded Gibbs sampling. I am still not sure, that it could be applied in our area, but as long as parallelization and faster computation are part of the claims, you got my attention ;-). At the very least the reference deserve a more in depth analysis (at least the first one !)

## eMarch 3 : Time-stamps

Keeping a track of changes in your source code is always a good idea. I generally use two ways to know when I’ve done my last change of a file.

## Time-stamps

This function is generally useful for small scripts or projects. First you have to insert the following lines in your .emacs

``` (setq
time-stamp-active t          ; Set  time-stamp
time-stamp-line-limit 20     ; Indicate within how many lines a time-stamp should be seek (here the 20th first lines)
time-stamp-format "%04y-%02m-%02d %02H:%02M:%02S (%u)") ; Format date
(add-hook 'write-file-hooks 'time-stamp) ; ask for automatic update```

Second, just add within the first line of your file (20 in the latter code); the keyword:

`Time-stamp: <>`

Any time you ‘ll save your file, the Time-stamp will be updated. A nice feature here is that emacs is looking for a pattern, so we can play a bit with is. As instance, if you want to keep a track in a log file of which version of a script was used, just add :

```T="Time-stamp: <>"
echo "Running "\$0 "Version "\$T
```

Likewise, you can add some similar kind of code to your FORTRAN, C etc…  source code to know which version of the source was used to create your executable as already mentioned in a later post.

## SVN ID version

The last comment lead us directly to the second time-stamping option. When I first start using svn I had trouble with the Time-stamp tags in my files since any small change in a file under svn generate at least two lines of changes (the actual change and the Time-stamp change). In this case the correct way to proceed is to use the
VC-dir tool.

Either, with C-x v h, or Tools, Version Control,  Insert Header, or click-1 on major mode keyword in baseline  and then Insert Header.

This will add the tag \$Id\$ preceded by an appropriate comment sign. Every time you commit your source the tag will be updated (and won’t be considered as an actual changes in the code).

Categories: emacs, Linux

## eMarch 2 : create a pdf with highlighted code source

A very nice feature of emacs is syntax highlighting for a wide variety of language. Back in the old time, I used to print my a lot of my source code in order to analyse it in details, as the AIX server I was working on had no access to any color-printer, I had to print my buffer to a postscript file first, (convert it to pdf) and last transfer it to my main computer. But one, day I found a nice small piece of lisp which allow me simplify the process.

Thus I just added this in my  .emacs file

```(defun print-to-pdf ()
(interactive)
(ps-spool-buffer-with-faces)
(switch-to-buffer "*PostScript*")
(write-file "tmp.ps")
(kill-buffer "tmp.ps")
(setq cmd (concat "ps2pdf14 tmp.ps " (buffer-name) ".pdf"))
(shell-command cmd)
(shell-command "rm tmp.ps")
(message (concat "File printed in : "(buffer-name) ".pdf"))
)```

Then, from any buffer, typing M-x print-to-pdf,  create nice and colorful pdf of my source code.

This script used to be a neat way to keep a pretty printed version of my work, fortunately printing to pdf became much easier with later version emacs, making the previous code a bit useless. But here comes the way I recycled this script. As I very often have to document my script and source code (who doesn’t ???), I took the habit to add as an appendix to my manuals the source code of the main scripts or software used. To do so, I produce a syntax highlighted pdf that I include via the \includepdf{} $\LaTeX$ command. Still, an annoying point is that scripts are updated rather often, so we have to think about an easy way to recreate the pdf.

In my .emacs, I thus modify my previous function into :

```(defun print-to-pdf-batch ()
(interactive)
(ps-spool-buffer-with-faces)
(switch-to-buffer "*PostScript*")
(write-file "tmp.ps")
(kill-buffer "tmp.ps")
(setq cmd (concat "ps2pdf14 tmp.ps " (buffer-name) ".pdf"))
(shell-command cmd)
(shell-command "rm tmp.ps")
(kill-emacs t)
)```

The changes are that we now avoid message output and ask to kill emacs at the end of the execution. For a series of sources code , you just have to run e.g.

```for File in *.sh ; do emacs \$File --eval "(print-to-pdf-batch)" ; done
```

This trick works, I imagine a better version would be to use the “-batch” argument of emacs, and eventually a lisp file (thus you should not change your .emacs). Unfortunately, I could not achieve to obtain color in the output (probably due to X issues ? any hints/solutions wold be appreciated). If you have no X server the -nw options also works but the colors used are to my opinion not so nice.

Categories: emacs

## Software update

A very hot update summary !

BWA 0.7.0

A new algorithm (BWA-MEM)  still in beta version, expected to be twice faster, and more accurate. On the short-term, it should replace BWA algorithm which apparently doesn’t handle correctly long read. I am eager to test it.

GATK 2.4

A lot of changes, first the licence, with an access to the whole source code ! As always, some accuracy and speed improvments were announced. On a first small test, I obtained a three fold time decrease for HaplotypeCaller — Nicely done, but I am still wondering whether it’ll be enough to make HaplotypeCaller practicable. A worth noticing tool appear : RegenotypeVariants, provided that you already have a rock solid set of variants, I guess the latter may give a quickly updated vcf.

Beagle 4
This is still a beta version, a big change in the input format, beagle is now working with vcf — this will simplify a lot some of my scripts–, imputation is so far not available (Coming soon ?).

Igv2.2

This version accept ReducedRead bam from GATK 2 (I now only have one argument left for not using it). The UI changed a bit, and a direct access to genomespace is now available.

snpEff

Some improvement and database updates plus the addition of snpSIFT a side software to manipulate vcf.

Varscan2.3.4

I was looking for a better vcf4.1 conformity, there has been some improvment (but this is still not enough to IGV’s opinion !).

Categories: emacs, Linux, NGS

## eMarch 1 : Add AucTeX local variables to your LaTeX file

March 1, 2013 2 comments

I just thought about a fancy way to present some of my favorite emacs tips. So every Friday of marsh, I’ll try to give an emacs tips I like.

English is obviously not my maternal tongue, so I really need some word spelling software. When I first started using LaTeX with emacs, I thought that this was impossible. I was really wrong, in fact if ispell and FlySpell you can have a first help against misspelling. Type in emacs M-x Flyspell-mode. In order to change the dictionnary, type M-X change-dictionnary and choose the correct language.

Second point, if you really want to take advantage of LaTeX power, you should split your source in several files, that will be called from a “main” or “master ” file which in turn have the “\include” instruction to include each of your file. With this scheme, if you edit one file and want to check your output, you should always compile (from) the main file. AucTeX, allow you to declare the master file from its menu (command, Master File).  Then, when you  compile your source code, no matter which file you are visiting, the master file will be compiled.

Now the awesome tips, an even better way to proceed is to add local variables to the end of each of your latex file. Like this :

```%%%Local Variables:
%%%TeX-master: "MasterDocument"
%%%End:```

The latter indicate that the file “MasterDocument.sty”, is the master file to compile and from which the actual file will be called. Likewise, the following code :

```%%%Local Variables:
%%% mode: latex
%%% eval: (TeX-PDF-mode 1)
%%% ispell-local-dictionary: "en_US"
%%% eval: (flyspell-mode 1)
%%%End:```

Will ask AucTeX to use pdfTeX for compilation and to switch to the “en_US” dictionary, with flyspell mode enabled by default, every time you open your file.

Note since emacs 24.1 you should use eval to use the Tex-PDF Minor-mode (earlier version allowed the ” %%% mode: Tex-pdf ” syntax).

Categories: emacs, LaTeX, Linux