[Tutor] nested lists of data
Rich Krauter
rmkrauter at yahoo.com
Mon Oct 25 15:45:08 CEST 2004
Scott Melnyk wrote:
> Hello Rich!
> Question about the program, I would like it pulled out only if it is
> in ALL the transcripts for a given gene. Does this not pull out exons
> that match in any two transcripts?
>
> So if there are four transcripts it would have to be in all four to be
> pulled out.
>
> I had received a past demo with lists from Kent Johnson which was the
> first I had heard of sets
> First some raw data:
>
[sets examples cut]
> Which is what I have based my plans on. Sorry to be new to this and a
> bit slow in picking it up,
No apologies necessary - and you are right about what you think it does;
you seem to have picked it up pretty quickly to me. :)
[code snippets cut]
> i think it would pull out any intersection between two transcripts.
That's right - sorry, I misunderstood what you needed to do. Try
something like this instead:
def getintersections(fname='D:/rk/exons.txt'):
exonSets = {}
f = open(fname)
for line in f:
if line.startswith('ENS'):
parts = line.split()
gene = parts[0]
transcript = parts[1]
exons = parts[2:]
exonSets.setdefault(gene,
sets.Set(exons)).intersection(sets.Set(exons))
return exonSets
Hope that helps.
Rich
More information about the Tutor
mailing list