0% found this document useful (0 votes)
53 views9 pages

23 Alias Function Wrapper - Odp

1. Aliases provide shortcuts for commonly used shell commands and can be defined in files like .bashrc or .bash_profile. Functions allow running more complex sets of shell commands and can be defined within the shell or in files. 2. Wrappers are programs that control and expand the functionality of another program, like a Python script that calls MATLAB. 3. Pipelines automate workflows and are important for efficiency, consistency and record keeping when running analyses or experiments.

Uploaded by

Santiago Salas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views9 pages

23 Alias Function Wrapper - Odp

1. Aliases provide shortcuts for commonly used shell commands and can be defined in files like .bashrc or .bash_profile. Functions allow running more complex sets of shell commands and can be defined within the shell or in files. 2. Wrappers are programs that control and expand the functionality of another program, like a Python script that calls MATLAB. 3. Pipelines automate workflows and are important for efficiency, consistency and record keeping when running analyses or experiments.

Uploaded by

Santiago Salas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
You are on page 1/ 9

Aliases, functions, wrappers, pipelines

Virginie Orgogozo
April 6 2012

Alias
shortcut for a commonly used shell command
~/.bash_profile or ~/.bashrc file:
()

In the shell:

alias cdp='cd ~/pcfb/sandbox'

$cdp

alias cx='chmod u+x'


alias ag='agrep -B -y -d > '

$cxscript2.py
$agCYGexamples/FPexcerpt.fta
$myjobs

alias myjobs=ps -ax | grep orgogozo

$hgpcfb

alias hg='history | grep'

$alias

(list your defined aliases)

For the changes in your .bashrc file to be used in the shell:


- open a new shell window
or: - $source.bashrc

Functions
For a more complex set of shell commands
In the shell:
$pdftkGenomeBiolPaper.pdfcat2endoutputDoe2012.pdf
$firstpageGenomeBiolPaper.pdfDoe2012.pdf
~/.bash_profile or ~/.bashrc file:
()
function firstpage() { pdftk $1 cat 2-end output $2 ;}
$listall

listall() {
ls -la
echo Above are all the directories of the following
folder:
pwd
date
}

You can also write a function in the shell only


virginie@Darwin:~$repeater(){
>echo"$1iswhatyousaidfirst"
>echo"$@iseverythingyousaid"
>}

Defines
the
function

virginie@Darwin:~$repeaterhelloeverybody!Howare
you?
helloiswhatyousaidfirst
helloeverybody!Howareyou?iseverythingyousaid
virginie@Darwin:$

Usage of
the
function

Use a function when you want to use the same command


multiple times with different filenames in the middle
virginie@Darwin:~$phymlsequencesA.fta1i1100WAG
08eBIONJyy
virginie@Darwin:~$phymlsequencesB.fta1i1100WAG
08eBIONJyy
virginie@Darwin:~$phymlCG5679.fta1i1100WAG08
eBIONJyy
virginie@Darwin:~$phymlASCRE.fta1i1100WAG08
eBIONJyy
(...)
virginie@Darwin:~$myphyml(){
>phyml$11i1100WAG08eBIONJyy
>}
virginie@Darwin:~$myphymlsequencesA.fta
virginie@Darwin:~$myphymlsequencesB.fta&&myphyml
CG5679.fta&&myphymlASCRE.fta

Defines
the
function
Usage of
the
function

Use a function to rename multiple files


file1.txt
file2.txt
file3.txt
...

u_file1.dat
u_file2.dat
u_file3.dat
...

renamer(){
EXT="dat"
PRE="u_"
(if the number of arguments is ..., then...)
if[$#lt1]
then
echo"Renameafile.txtlistas$PREfile.
$EXT"
else
forFILENAMEin"$@"
do
ROOTNAME="${FILENAME%.*}"

cp"$FILENAME""$PRE$ROOTNAME.$EXT"
echo"Copying$FILENAMEto
$PRE$ROOTNAME.$EXT"
done
fi
}
Copy and paste this text from pcfb/scripts/shellfunctions.sh in your shell

virginie@Darwin:~$cd~/pcfb/examplesspectra/
virginie@Darwin:~/pcfb/examples/spectra$ls
LEDBlue.txtLEDGreen.txtLEDRed.txtLEDYellow.txt
virginie@Darwin:~/pcfb/examples/spectra$renamer*.txt
CopyingLEDBlue.txttou_LEDBlue.dat
CopyingLEDGreen.txttou_LEDGreen.dat
CopyingLEDRed.txttou_LEDRed.dat
CopyingLEDYellow.txttou_LEDYellow.dat
virginie@Darwin:~/pcfb/examples/spectra$ls
LEDBlue.txtLEDRed.txtu_LEDBlue.datu_LEDRed.dat
LEDGreen.txtLEDYellow.txtu_LEDGreen.datu_LEDYellow.dat
virginie@Darwin:~/Documents/WWW/BioInfoCourses/pcfb/examples/spectr
a$

Use a loop to repeat operations


virginie@Darwin:~$forkin{1..10}
>do
>echo$k
>done
1
2
3
4
5
6
7
8
9
10
virginie@Darwin:~$
virginie@Darwin:~$foriin{A..Z};domkdir$i
authors;mv$i*.pdf$iauthors;done

Wrappers
Program that controls and expands the functionality of another program

Ex: python script that calls MATLAB or another program

Pipelines
Automated workflow
Very important for efficiency, consistency and record

You might also like