Bio 599: Lecture 20 (NAU Fall 2012)

Bio 599: Lecture 20 (NAU Fall 2012)

Writing a first program


Greg Caporaso

November 01, 2012


  1. 2.

    Flow  control   •  Define  the  steps  that  a  program

     will  take,   o@en  based  on  the  value  of  some  variable  or   the  result  of  some  opera-on  
  2. 5.

    Interac-ng  with  users  to  get  input  and   generate  output

      •  O@en  will  take  input  from  users  as  a  series  of   command  line  op-ons   •  Output  can  be  wriGen  to  file   •  User  can  then  read  the  file,  or  pass  it  to  some   downstream  program  in  a  workflow.  That   downstream  program  would  parse  the  file   (i.e.,  read  it  into  memory).    
  3. 6.

    You  don’t  have  to  re-­‐invent  the  wheel:   languages  have

     pre-­‐exis-ng  tools   •  Python  standard  library   – random,  os,  optparse   •  Third-­‐party  libraries   – Qiime,  PyCogent,  numpy,  matplotlib,  ipython,  …  
  4. 7.

    Comments   •  Blocks  of  text  that  are  not  executed

      – Useful  to  keep  notes  for  yourself  or  other   developers   •  Can  comment  out  blocks  of  code  if  you  don’t   want  them  to  run  –  useful  for  development   and  debugging  
  5. 8.

    Objects:  new  (user-­‐definable)  types   •  A  variable  that  can

     contain  other  variables  and   define  methods  (i.e.,  func-ons  that  operate  on   the  object)   •  Examples:  DnaSequence,  ProteinSequence,   Gene-cCode,  OTU  table,  …  
  6. 9.

    Tip  on  ge\ng  started:  read  other   people’s  code  

    •  Browse  some  projects  on  GitHub  –  good  ones   could  be  QIIME,  Ipython,  Matplotlib.    
  7. 10.

    This  work  is  licensed  under  the  Crea-ve  Commons  AGribu-on  3.0

     United  States  License.  To  view  a   copy  of  this  license,  visit   hGp://  or  send  a  leGer  to  Crea-ve  Commons,  171   Second  Street,  Suite  300,  San  Francisco,  California,  94105,  USA.     Feel  free  to  use  or  modify  these  slides,  but  please  credit  me  by  placing  the  following  aGribu-on   informa-on  where  you  feel  that  it  makes  sense:  Greg  Caporaso,