38
Practical: EidPB WS2016/17 Einführung in die Programmierung für Bioinforma2ker Introduc2on to Programming for Bioinforma2cs Prof. B. Rost, Dr. L. Richter Ins2tut für Informa2k I12

Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

EinführungindieProgrammierungfürBioinforma2ker

Introduc2ontoProgrammingforBioinforma2cs

Prof.B.Rost,Dr.L.Richter

Ins2tutfürInforma2kI12

Page 2: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

VorlesungstermineTermin Thema Termin Thema

24.10.2016 Organisation 12.12.2016 tba

31.10.2016 Linux/Java 19.12.2016 tba

07.11.2016 Linux/Java 09.01.2017 tba

14.11.2016 Shell/Java 16.01.2017 tba

22.11.2016 tba 23.01.2017 Fragestunde

29.11.2016 tba 30.01.2017 Fragestunde

5.11.2016 tba 07.02.2016 Prüfung

Es wird zwei Arbeitsblätter mit Bewertung geben. Wer aus beiden Blättern insgesamt 50% der Punkte erreicht, bekomment einen Notenbonus von 0,3 bei Bestehen der Abschlussprüfung.

Page 3: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

SystemStatus

●  Gettheseizure(usespace)ofaharddisk:df: diskfreeshowstheavailablespaceonfilesystemsandtheusedspace

●  spaceconsump2onoffilesanddirectories:du: diskusageshowsyouthespaceconsump2onoffiles,manyop2onstoimprovethereadability

●  mountedfilesystems(drives):mount

Page 4: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

SystemStatusII

●  Displaytheenvironmentvariables:env:environmentdisplaysthenameandthevaluesoftheenvironmentvariablesofyourshell

●  showthesytem2me:date

●  2meconsump2onofaprogram:time

●  logged-inuserandprocesses:who ●  terminalseNngs:stty ifyourterminalismisconfigured:stty sane

Page 5: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

Processes●  process:Ac2vitywhichgetscompu2ng2mefromtheopera2ngsystem

●  characterizedby:ownnID,parent-ID,consumedcpu2me,used(virtual)memory,status

●  canruninfrontorasbackground

●  canrunwithoutcontrolterminal(demonprocess)

Page 6: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

Processes2●  ps:reportprocessstatusps[op2ons]

●  Op2ons:-u UIDprozessesforuserUID, w/oUIDforallusers-a allprocesseshavingaterminal-x showsprocessesw/ocontrolterminal-l verboseinforma2ons(long)-f displayastree

Page 7: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

Prozesses3●  kill:killprocesseskill-SignalPID

●  Op2ons:Signal 15(terminate,controlledstop), 9(abort,immediatestop)

●  killallProgNamefinishesallprocessesofprogramProgName,assumedyouhavepermissiontodoso

●  top: toolforonlinedisplayofac2veprocesses

Page 8: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

Piping

●  Manytoolsuseasstandardoutputdevicethescreenandasstandardinputdevicethekeyboard

●  Thesestandardchannelscanberedirectedandcombinedintoaseriesofconnectedprocessingsteps

Page 9: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

SimpleIn/OutputRedirec2on

●  Redirectscreenoutputintoafile:myProgram>myPutputFile

●  Redirec2onofkeyboardinputfromafile:myProgram<mInputFile

●  Combina2onofboth:mProgram>mOutputFile<mInputFile

Page 10: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

Piping

●  Pipesisamechanismprovidedbytheopera2ngsystemtoautoma2callyconnectprogramsintoaseries:Prog1 | Prog2 | Prog3i.e.putputofprogram1isdirectlyusedasinputforprogram2andtheoutputofprogram2isusedbyprogram3

●  Goal:manysmallbutspecializedtoolscanbeconnectedtofullfillcomplextasks

Page 11: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

Filtering

●  Inaseriesofconnectedprogramsnormallythereisaprocessingateachstep.I.e.certaindataaremodifiedorfilteredsothisisalsocalledfiltering.

Page 12: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

grep●  grep:getregularexpression●  Searchforpa`ernsininput:-  Pa`ernareregularexpressions-  regularexpressionsimilartothoseinPerl

●  Input:filesorstandardinput

●  Op2ons:-c countsoccurrences(count)-r searchdirectoriesrecursively-e specifyapa`ern-v alllinesthatdonotmatch....

Page 13: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

find●  findfindfiles●  searchesthefilesystemstar2ngatacertainpointfor(specified)files

●  thedesiredfilesaspecifiedbycondi2ons

●  Condi2ons/Op2ons:-name,-type,-size,-c2me,-m2me,-depth.-follow,etc.

Page 14: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

locate/which

●  locate:findingfiles-  usesitsowndatabase-  thedatabaseisregularlyupdatedbyacronjob-  supportssearchpa`ern,too-  fasterthanfind,butdependsfromitsdatabase

●  which:findsexecutableprograminthesearchpath,programsarefoundiftheyresideinadirectorylistedinthePATHvariable

Page 15: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

Archiving●  (g)zip:compressingoffiles(g)unzip:resp.foruncompressing

●  tar:tapearchivetar -directive [options]-  combinewithg(un)ziptocompressarchives-  mostimportantdirec2ves:c,x,tc createanewarchivex extractanexis2ngarchivet listthecontentsofanexis2ngarchive

-  Ex.:tar-czfarchiv.tgzdirectory/tocreateancompres-sedarchivecontainingdirectoryinthefilearchiv.tgztar-xzfarchiv.tgzunpackanduncompressarchiv.tgztodirectorydirectory

Page 16: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

ExamplesforPiping

●  find /usr/local/include -name "*.h" | grep gnu |wc –l countsthenumberofheaderfileshaving“gnu” inthefilename“grep gnu *” wouldsearchthefilecontentsfor “gnu”

●  cd ; ls .* | wc –l countshiddenfilesinyourhomedirectory

Page 17: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

ExamplesforPiping2

●  cat /etc/passwd/ | grep system | less searches /etc/passwd foralllinecontaining“system”anddisplaythemwiththepagerless

●  cd; find -type f | grep -c mp3 countsallmp3fileinyourhomedirectory

Page 18: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

Addi2onalTools

●  teefileName:readfromstandardinputandwritestostandardoutputandtothefilefileNameyoucan“tap”thepipelineatthispoint

●  sort:inputlinesaresortednumericallyoralphanumerically(default),dependingontheselectedop2on(n:numerically,r:reverse)

Page 19: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

MoreExamples

●  cat /etc/passwd | cut -f1,5 -d:●  find . -name *.pl | wc

●  cd; du -h --max-depth=3 | sort -rn | less

●  cd; grep -lvir gnu * | wc –l searchesfilesinyourhomefortheoccurenceof “gnu” andcountsthelines

Page 20: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

ViI

●  verypowerfultexteditor●  availableon(nearly)allUNIXmachines

●  nowadays:vim(viimproved)

●  nowgraphicaluserinterfaceneeded●  needsli`leresource

●  s2llworkswhensystemsrespondsslowly

Page 21: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

Vi–SourcesforHelp

●  h`p://www.vim.org●  manpage

●  Helpsystem:“:help”

●  vimtutor

Page 22: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

Vi–ModesandBasics

●  commandmode(normalmode)●  commandlinemode(exmode)

●  insertmode

●  visualmode(vimonly)●  commandmode->insertmode:insert/editcommand

●  insertmode->commandmode:ESCAPE,CTRL-C

●  commandlinemodecommandmode:RETURN

Page 23: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

Vi–naviga2on

●  naviga2on:cursorkeysorh,j,k,l(leg,down,upright)

●  gg:startofdocument,G:endofdocument

●  0beginofline,wnextword,eendofword,$endofline

●  precededbyrepeaternumberlike:5w,2j

Page 24: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

Vi–edit

●  Insert:i–agercursor,I–startofline●  Erase:x–eraseatcursor,X–erasebeforecursor

●  Append:a–appendatcursor,A–appendatendofline

●  o:appendinnewlineager,O:appendinnewlinebeforecursor

●  r:replacesinglecharacter,c+posi2oner:change

●  u:undo,“.”:repeatlastcommand

Page 25: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

Morecomplexcommands

●  fullcommandsyntax:[“register][counter]command[cursor positioner]

●  saveandexit:ZZor:wq●  exitwithoutsave:“:q!”(forcequit)

Page 26: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

MakeLifeeasier

●  :set showcmd toshowyourtypedcommands!●  :set nu displaylinenumers!

●  :syntax on toenablesyntaxhighligh2ng!

●  :set hls / nohls toenablesearchhighligh2ng!

Page 27: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

VersionControl

●  Whatisversioncontrol●  Whycontrolisnecessaryanduseful

●  Versioncontroltools:cvs,svn,gith`p://cvs.nongnu.org/h`p://subversion.apache.org/h`p://git-scm.com/documenta2on

Page 28: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

TheShell

●  commandinterpreterbetweenyouandtheopera2ngsystem

●  manyflavours:sh,csh,tscsh,ksh,zsh,.....

●  Linux:bash

●  offers:simpledatastructures,jobcontrol,history,controlstructures

●  wildcardexpansion

●  commandlineedi2ng

Page 29: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

ShellStart-Up

●  asaloginshell(typicallywhenyouloginin)thefollowingconfigura2onfilesaresearchedinthegivenorder: /etc/profile ~/.bash_profile(fromherefirstmatchisexecuted) ~/.bash_login ~/.profile

●  otherwise:~/.bashrc

Page 30: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

ExitStatus/ReturnValue

●  otherthaninmostprogramminglanguagesunix(andshell)commandsreturn0onproperexecu2onbutavaluedifferentfrom0toindicateanerrorstate

●  theexitstatusisstoredinthevariable‘?’

●  youcanprintitwith‘echo$?’

Page 31: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

ShellProgrammingin10seconds

●  Sofarcovered:Singleinstruc2ons,instruc2onsequences(piping)

●  S2llmissing:Variables,controlstructures

●  Theseareprovidedbytheshell

●  determineyourshell:echo $SHELL!

Page 32: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

ShellProgrammingII●  makeascriptexecutable:#!/bin/bash(she-bangline)andsetx-bitorbashyourScriptfile!

●  Howtodefineavariable:VariableName=Value(nowhitespacearound=)VariableName:[a-zA-Z_][a-zA-Z0-9_]*Value:unquotedstringwithoutwhitespaceorquotedstringifitcontainswhitespaceor$VariableName!

Page 33: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

ShellProgrammingIII

●  simpleoutput:echo!●  forma`edoutput:printf!

●  enabletracemodewithset–x,evenmoreverbosewith–v

●  specialvariables:-  $#numberofarguments(commandline&func2on)-  $*,$@listofallcommandlinearguments-  “$*”onestring,“$@”listofprotectedstrings

Page 34: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

ShellProgrammingIV

●  shiftreturnfirstposi2onalparameter(dele2ng)●  arithme2cswithin$(( )),operatorslikeinC

●  Exitstatus:Exitsstatus0indicatessuccess!$?holdstheexitstatusofthelastcommandexitnreturnsimmediatelyexitstatusn!

Page 35: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

ShellProgrammingV

●  if-elif-else-fi●  ifpipeline[pipeline...]thencommand-if-true-1[elifpipeline][pipeline...]thencommand-if-true-2[elsecommands-in-all-other-cases]fi

Page 36: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

ShellProgrammingVI

●  test[expression] or[[expression]]!●  -d fileisthisadirectory?!

●  -e filedoesfileexists?!

●  -h fileisthisasymboliclink?●  -s fileisnotempty?

●  -x fileisexecutable?

●  ...!

Page 37: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

ShellProgrammingVII

●  Loops:forandwhileloops●  foriinlistdocommands...done!

●  whilecondi2on/untilcondi2ondo commandsdone!

Page 38: Einführung in die Programmierung für Bioinformaker€¦ · Practical: EidPB WS2016/17 Vorlesungstermine Termin Thema Termin Thema 24.10.2016 Organisation 12.12.2016 tba 31.10.2016

Practical: EidPB WS2016/17

Thankyouforyoura`en2on