Thursday, October 22, 2009

Variable modifiers in csh and bash: bash

Bash do not have variable modifiers, but it has a feature called Posix, which originates from ksh and seems to be more powerful, albeit somewhat more cryptic.

% is used to remove smallest suffix pattern. Like:
$ gatesfile=/home/gates/bin/foo.bar
$ echo ${gatesfile%.bar}
/home/gates/bin/foo
Of course you can append something to the end and forge the functionality of replace:
$ echo ${gatesfile%.bar}.x
/home/gates/bin/foo.x
%% is to remove largest suffix pattern:
$ gatesfile=posix/src/std
$ echo ${gatesfile%%/*}
posix
# is used to remove smallest prefix pattern, and ## is to remove largest prefix pattern

In summary, given:
a=/a/b/c/d
b=b.xxx

+------------------------------------+
|csh bash result |
+------------------------------------+
|$a:h ${a%/*} /a/b/c |
|$a:t ${a##*/} d |
|$b:r ${b%.*} b |
|$b:e ${b##*.} xxx |
+------------------------------------+

Variable modifiers in csh and bash: csh

csh has a nice feature called variable modification to easily trim your variable for your needs. The modifiers work by appending to the variable interpolation with a ":". This feature is especially useful dealing with pathnames.

For example
% set gatesfile=/home/gates/bin/foo.bar
% echo $gatesfile
/home/gates/bin/foo.bar
In order to get the directory name, you only need this:
% echo $gatesfile:h
home/gates/bin

and for file name:
% echo $gatesfile:t
foo.bar
how about file base? Use combinations:
% echo $gatesfile:r:t
foo
Ok, here is all of the appendixes:

+----------------------------------------------------------+
|Modifier Meaning Example Results |
+----------------------------------------------------------+
|r Root $a:r a/b/c.d.e.f |
|e Extension $a:e g |
|h Head (or Directory) $a:h /a/b |
|t Tail (or Filename) $a:t c.d.e.f.g |
+----------------------------------------------------------+

Friday, October 16, 2009

Linux Tips

use scp to copy files from lab to my home:
scp qz2126@adgate.cu-genome.org:~/oct2.RData ./

Thursday, October 15, 2009

QSUB Tips

1, transfer variable
use -V, you can transfer all variables to the job, and use -v, you can specify a variable to transfer:
qsub -V -cwd -l mem=3G,time=72:00:00 -o $qoutF -e $qerrF $qsubF
qsub -cwd -v sparks=$sparksDir -o $qoutF -e $qerrF $qsubF

2, big jobs, for titan@lab
qrsh -l mem=30G,time=24:: -now n

3, binds to a specified queue/node
qrsh -q all.q@gaianode-8-85.local -now n


BLAST Tips

1, fastacmd

get DB info:
fastacmd -d $PDBBLST -I T
get sequence
fastacmd -d $PDBBLST -s 1a2k_A
get sequence with taxonomy info
fastacmd -d $BLASTDB/nr.fa -s XP_642131.1 -TT