CLASS 8

The lecture slides and the relevant code for the class are here: http://goo.gl/CCgs0V

In this class we covered basic image processing to locate the position of a rat in a 3 chamber environment. We used this to estimate the time spent by the rat in each compartments (by processing many pictures / video). We also covered a list of resources that will be useful for further learning (Class8_2.pdf)

We first subtract the image of the cage with rat, from the image of just the case. Then we used a basic thresholding algorithm to fetch the position of the animal more precisely. This is now marked in a red dot.

Top to bottom, Background, image with rat, Subtracted image (output of images2.py) Top to bottom, Abs difference, Abs difference and thresholding of 40 intensity (output of images3.py) Localizing the rat as a red dot (output of images4.py) Trace of the rat movement (output of images6.py) Use the script images7.py to quantify the time spent in each chamber

Class 7

In this class we learn how to handle strings. Specifically we looked at how DNA style strings can be manipulated.

All the slides and material used in the class is here http://goo.gl/R1vlrF

Class 7 first half was based on this tutorial.

We learn how to count length of DNA strands. To make their complements. To make its pre-mRNA, and then prune its introns. We translate it to the respective protein sequence.

We also see advanced plotting using animation for the grid cells example from Class 6. See grid_cells_2.py We use a colored line to trace the movement of the rat in the arena, while simultaneously plotting the spikes of the cell. NOTES

1) How to split strings while retaining the delimiter string?
– There is no simple operation like dna.split(‘A’) that will accomplish this.

dna = ‘GATTACA’
delimiter = ‘A’
words = [ ]
for x in dna.split( delimiter ):
words.append( x + delimiter )
words_2 = [ x + delimiter for x in dna.split( delimiter ) ] # This is the relevant line

One has to re-create the list over again. Also note words and words_2 do the exact same thing. But words_2 is more elegant.

2) How to change a particular nucleotide at some position? (Emulating a single nucleotide mutation.)
– Generally it is not advised (or even possible) to change strings.
– The solution we arrived in the Class is correct.

dna = ‘GATTACA’
mutation = dna[:4] + ‘C’ + dna[5:] #mutation at the second A

HOMEWORK

1) Read, and do – Slide 17 and 18 – Python pickling and unpicling. Read codontable dictionary from parameters.py and dump this as codontable.pkl, and then read from it.

2) Slide 16, Read ‘protein.txt’, and find the corresponding location of mRNA in ‘mRNA.txt’ as shown in the class.

3) Using DNA sequence in parameters.py print the original DNA sequence with coding bases in uppercase and non-coding bases in lowercase. Introns are stated in the slides.

Class 6 Homework

The lecture slides for Class 6 the code used, are available here: http://goo.gl/NWylEy

Homework (Please write if you need clarification or help)

1)
Reading: Exercise on slide 12 of Class6_spreadsheets2.pdf, See /code/analyze_imgdata5.py

2)
The guessing game programmed in the class (see: /code/python_game.py) has a bug – when you guess the correct number in the last trial, the program says, ‘You guessed right!’, and yet the program exists stating that ‘You lost! No soup for you!’, Identify where this bug is, and correct it.

3)
Write a program that takes a filename for input, and gives the following:

A) The number of words in this file.
B) The number of occurrences of ‘and’, ‘a’, ‘an’, and ‘the’ in the text.
C) Make a bar plot of values from B, with appropriate x labels, and file name as the plot title.

4)
On the meadows of Austria, live wild sheep, with no predators or external threats. The population of the sheep can takes values between 0.0 and 1.0 – representing the ratio between existing population and the maximum theoretical possible population.

The population of sheep, the next year is given by,

x(n+1) = R * x(n) * ( 1 – x(n) )

Where x(n) is the current year’s population.
Where R is a rate of reproduction.

The equation above incorporates, that the next years population depends on
– current years population (reproduction) when populations are small and
– over crowding (starvation) when population is reaching maximum possible population : theoretical “carrying capacity” of the environment.

Part1
Plot as points, the population (y axis) for the first 53 years (x axis). For the following cases:
(Subplot1) starting population = 0.2, R = 2.8, color = ‘k’
(Subplot1) starting population = 0.2, R = 3.3, color = ‘g’
(Subplot1) starting population = 0.2, R = 3.5, color = ‘b’
(Subplot1) starting population = 0.2, R = 3.8. color = ‘r’

(Subplot2) same as Subplot1, but with starting population = 0.4
(Subplot3) same as Subplot1, but with starting population = 0.6
(Subplot4) same as Subplot1, but with starting population = 0.8

Part2
For 300 random starting populations, find the population of sheep at the end of 87 years.

Make a plot for R (x-axis) versus population at the end of 87 years (300 points on Y-axis for each R value), when is R varying between 2.4 and 4 at a 0.01 resolution. [R = 2.4, 2.41, 2.42, … 3.99, 4.0]

CLASS 5

The lecture slides from the Class 5 here: http://goo.gl/kIjnGk

Homework
(See Homework folder above)

1)
i) Complete the Exercise in ‘Spreadsheets.pdf’ slide number 16, See folder code, file analyze_imgdata1.py for help

ii) Use above, to generate a scatter plots corresponding to all the datasets,
– Age versus size
– Age versus intensity
(Homework / imgdata_result1.pdf is how your result will look like) 2)
In Homework folder, find ‘Phonebook.csv’ file. (This has been copied from http://www.nencki.gov.pl/ksiazka-telefoniczna)

Part1. Write a function that returns a list of persons in a given room. HINT: Use for loop and string matching.

Part2. Write a function that returns a dictionary with room numbers as keys and a list of persons in that room as its value.

HINT:
Use dict.has_key()
For example:
test_dict = { ‘1’ : [‘James Bond’, ‘006’], ‘2’ : [‘Her Majesty’], ‘3’ : [‘Moneypenny’, ‘M’] }
test_dict.has_key(‘1′) returns True
test_dict.has_key(’10’) returns False

Part3. Write a function, that returns the telephone number, and room number, give a given full name of person.

In all the above, account for corner cases – when invalid room numbers are sent to the function, it should not break your program – but instead should print ‘Room does not exist!’

Assignment – In case you have not already submitted your assignment, please do so before Wednesday (11th March) 5PM. Please submit how much ever you manage to complete.

To remind you, the assignment problem is the homework assignment – Bacteria growth from Class4 [https://nenckipython.wordpress.com/2015/03/02/class-4/].
Major hints to this assignment were provided in Class 5 and the slides for this are titled ‘Class4_HW.pdf’ in the above folder.

Can you fly ?* * Don’t try this at home.

Class 4

Please find the slides from the class 4 here: http://goo.gl/LUBoC1

(Also included are programs written in Class 4)

This class was based on Software Carpentry’s lessons:

– Analyzing Data from Multiple Files (v 5.2, v5.3)
– Making Choices (v5.3)

Homework:

1) Complete exercise on slide 9 of Loops,  Class4_part1.pdf
2) Complete exercise on slide 9 of Conditionals, Class4_part2.pdf
– A certain strain of bacteria has a lag time of 5 minutes.
– Its exponential phase lasts for 12 minutes. In this time, each cell doubles after every minute.
– Stationary phase lasts for 1 hour, The cells maintain their population numbers.
– In the death phase, 7% of all surviving cells die after every minute.
Part 1.
Write a function that returns the highest number of cells the colony will ever have (This is equal to number of cells in stationary phase), for a given initial number (population count) of seed bacteria?
Part 2.
Write a function that accepts initial number (population count) of seed bacteria, and time of measurement in minutes, and returns
i) The phase of bacterial growth the colony is at the time of measurement? (Lag versus Exponential versus Stationary versus Death) and
ii) The number of cells alive at the time of the measurement.
HINT: Use if conditions for part 1, and use for loop in death phase of part 2.
Part 3.
Write a function, that for a given initial number (population) of cells, returns the time in minutes at which the colony dies? HINT: read documentation on ‘while loops
Part 4.
Make a plot similar to that shown below. With, X-axis as time versus Y-axis number of cells in log scale, for a given initial number (population) of seed cells. (Refer documentation on Log scale plots)
Cheers!
Chaitanya