[Tutor] help

Python python at venix.com
Sat Dec 9 19:04:36 CET 2006


On Sat, 2006-12-09 at 20:19 +0500, Kamran Haider wrote:
> Hi
> 
> I have got some python related queries. I am working on an MRes
> project
> which involves a bit of programing in python. Actually, I am using a
> python program developed by someone, which gives pairwise genetic
> distances between a set of sequences (I don't know how...) and outputs
> a
> simple text file of the following format...
> 
> s1,s2,s3,s4,s5
> 4,7,2,3
> 8,6,4
> 3,6
> 7
> where s1, s2, s3...represent sequences and the  second line describes
> the pairwise distance between s1 and all other sequences,thid line is
> for the distance between s2 and other sequences.
> and so on.
> 1. I want to read this line into a data structure(most probably by
> making a list of lists like [[s1,s2,4],[s1,s2,7],[s1,s3,2] and so on)
> which gives each pair and the corresponding pairwise distances. 
I think a dictionary will server you better.
{(s1,s2):4, (s1,s3):7, (s1,s4):2, }
> Of course, I would do this by writing a function that reads this file
> into a data structure which gives the all the pairs of sequences and
> theircorresponding distance values, but I am not sure how to do
> this.  
Well ask for help as you break this down.  You should wind up with quite
a few functions, not just one.  Using a dictionary should be no harder
than a list of lists.

> 2. Secondly, I want to write another function which takes up three
> arguments, the data structure returned by the previous function and
> the names of two sequences. It then returns the corresponding value.
With the dictionary, this function is trivial
def distance(seqdistance, s1, s2):
	return seqdistance[(s1,s2)]

Do you need to handle reversing the sequences?  Presumably 
	distance(s1,s2) == distance(s2,s1)

> 
> Please help
> Kamran
> 
> 
> 
> 
> ______________________________________________________________________
> Express yourself instantly with MSN Messenger! MSN Messenger Download
> today it's FREE! 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-- 
Lloyd Kvam
Venix Corp



More information about the Tutor mailing list