Introduction to Coding in Python

January 15th, 2015

Created by Wayne Decatur for Feng Lab Group meeting

Why code in Python?

Maybe a better question at this point is “why code?”

winter 2013 HHMI magazine
inside cover pages
my image
my image with code example

How to approach that?

Easy `find and replace` won't work because changes all `T's` and may change useful information.

Regular expression may have worked if I figured out how to do backward assertion?

Pseudocode for the problem


Go through all the lines input and decide what to do with them.

Want to skip lines beginning with >.

For all the other lines, we want replace 't' with 'u' elsewhere.
					
Python can make you fly

Python is a Very High Level Language


import random


numbers = range (1,50)
chosen = []

while len(chosen) < 6:
	number = random.choice(numbers)
	numbers.remove(number)
	chosen.append(number)

chosen.sort()

print "This week's numbers are", chosen
print "The bonus ball is", random.choice(numbers)
					

Code example borrowed from here.

Sidebar: Running Python for today

Reminder that approach used here today was just to save on installation issue. See here for an example of how it can hinder getting started.

For exploring and initial development cloud-approach is fine. Suggest though as you move towards real development of useful programs, you code in a text editor or IDE on your machine and then run in the cloud or even on your machine, depending on how nomadic you are or computing power/recources needed.

Why do I say do the code development locally? - main reason is reliability. You can easily undo and are more likely to have active backup mechanisms available on your computer or through linking with Dropbox etc., just like you would when you do work on a Microsoft Word document or presentation. Later you'd be smart to integrate git/github into your code development workflow, but that serves a different purpose (organizing development and collaboration) other than direct recovery of your most recent edits.

  • sites go down for spells
  • companies fold
  • internet not always accessible
  • Bottom line: get started, then work out your coding and running style/workflow. Won't be same for all things obviously. Examples from a nomad- mostly PythonAnywhere; large jobs in the cloud unless no money than can use lab desktop (at the cost of convenience).

    Putting it all together

    Starting with this example , can you write a program to convert DNA fasta to mRNA?

    example, DNA_to_RNAsimple.py

    THE END