25 March 2013

Embedding Pubmed, Graphiviz and a remote image in #LaTeX. My notebook. .

I'm learning LaTeX. Today I learned how to create a new command in LaTeX.

"Basically the command requires two arguments: the name of the command you want to create, and the definition of the command" . I played with LaTeX and wrote the following three commands:

Embedding a remote picture

The following LaTeX document defines a new command "\remoteimage". It takes 3 parameters: a filename, a URL and some parameters for \includegraphics. If the file doesn't exist, the url is downloaded and saved in 'file'. The downloaded image is then included in the final LaTeX document.

Note: latex files must be compiled with --enable-write18 to enable system-calls.
pdflatex --enable-write18 input.tex

External Image /Latex by lindenb

GraphViz Dot

The second LaTex Document works the same way. It defines a command "\graphviz" , sends the content of the 2nd argument to graphviz dot and save the resulting image before importing it into the LaTeX document.


GraphViz / Latex by lindenb


The last command define "\pmid" . It needs one Pubmed identifer. It downloads the XML record for this pmid, transforms it to LaTeX with xsltproc and the following XSLT stylesheet:

The LaTeX document includes four pubmed identifiers:


Pumed / Latex by lindenb

That's it,


13 March 2013

Filtering a BAM with javascript.

The following was created to answer that question on biostar: "Exclude reads with XA tag". SamJs is a java program filtering the reads of a BAM file using the javascript engine for java (rhino).


java -jar samjs.jar [options] (-e script | -f script) (file.bam|stdin)
for each SamRecord in the BAM, the program injects the following variables in the javascript context:
  • 'record' a SamRecord ( http://picard.sourceforge.net/javadoc/net/sf/samtools/SAMRecord.html ).
  • 'header' a SAMFileHeader ( http://picard.sourceforge.net/javadoc/net/sf/samtools/SAMFileHeader.html)


  • -S : SAM output.
  • -e (script).
  • -f (script-file).
  • -L (int) limit to 'L' records.


$ java -jar dist/samjs.jar -L 4  -S \
  -e '(record.inferredInsertSize > 60 || record.alignmentStart  < 50000000) && !record.readUnmappedFlag && record.getAttribute("MD")!=null ' \
@HD VN:1.0 SO:unsorted
@SQ SN:chr1 LN:247249719
IL31_4368:1:1:997:15684 163 chr1 241356442 60 54M = 241356612 224 CAGCCTCAGATTCAGCATTCTCAAATTCAGCTGCGGCTGAAACAGCAGCAGGAC EEEEDEEE9EAEEDEEEEEEEEEECEEAAEEDEE<CD=D=*BCAC?;CB,<D@, X0:i:1 X1:i:0 MD:Z:53T0 XG:i:0 AM:i:37 NM:i:1 SM:i:37 XM:i:1 XO:i:0 XT:A:U
IL31_4368:1:1:997:1657 163 chr1 143630066 60 54M = 143630364 352 CCCACCTCTCTCAATGTTTTCCATATGGCAGGGACTCAGCACAGGTGGATTAAT A;0A?AA+@A<7A7019/<65,3A;'''07<A=<=>?7=?6&)'9('*%,>/(< X0:i:1 X1:i:0 MD:Z:54 XG:i:0 AM:i:37 NM:i:0 SM:i:37 XM:i:0 XO:i:0 XT:A:U
IL31_4368:1:1:999:9391 163 chr1 195364100 29 54M = 195364272 226 AAAAAAAAAAACCCTCATTTTTTTTAAGTACTAAATTTTTTTTCCCATTTGAAA 1>??E?>@BB>0A/43;,=9A98A(',0/<*4>>/@=90A51&(**3;>'*;=; MD:Z:11A5A7C12A2G1A1T1C6 XG:i:0 AM:i:29 NM:i:8 SM:i:29 XM:i:8 XO:i:0 XT:A:M
IL31_4368:1:1:1002:11012 99 chr1 147142473 60 54M = 147142575 156 NGATTAGTACATAGTAAGTACTCAATAGATGTTAGCTATTATTGTAATCACCGC (1*4+236332679?1..87><-6<@<7>>@><7;@@@>962$-6075584093 X0:i:1 X1:i:0 MD:Z:0A40C12 XG:i:0 AM:i:37 NM:i:2 SM:i:37 XM:i:2 XO:i:0 XT:A:U

That's it,