Firstly, I'd like to thank everyone for their help. I ended up throwing something together using dictionaries (because I understood those best out of what I had), that was a lot faster than my initial attempt, but have run into a different problem, that I was hoping for help with. So, what I have is all the subsequences that I was looking for in separate entries in the dictionary, and where each of them is found as the value. If a subsequence binds to more than one other item, I want to have the locations of the items all together.
<br>The closest I've been able to manage to get to what I want is this:<br><br>dict_of_bond_location = {}<br>dict1 = {'AAA':['UUU'], 'AAU':['UUG', 'UUA'], 'AAC':['UUG'], 'AAG':['UUC', 'UUU'], 'CCC':['GGG']}
<br>dict2 = {'AAA':[1], 'AAU':[2], 'AAC':[3], 'AAG':[0, 4], 'GGG':[10]}<br>dict3 = {'UUU':[3, 5], 'UUG':[0], 'UUA':[1], 'UUC':[2], 'GGG':[14]}
<br><br><br>for key in dict2:<br> if key in dict1:<br> matching_subseq = dict1.get(key)<br> for item in matching_subseq:<br> if item in dict3:<br> location = dict3.get(item)<br> dict_of_bond_location.setdefault(key, []).append(location)
<br>print dict_of_bond_location<br><br>which gives this:<br>{'AAU': [[0], [1]], 'AAG': [[2], [3, 5]], 'AAA': [[3, 5]], 'AAC': [[0]]}<br><br>but what I want is <br>'AAU':[0, 1], 'AAG':[2, 3, 5], 'AAA':[3. 5], 'AAC':[0]
<br> <br>the setdefault(key, []).append(location) thing sort of does what I want, but I don't want the result to be a list of lists...just one big list. The production of a new dictionary is not necessary, but it made sense to me a few hours ago. Anyway, is there a fast and dirty way to add lists together, if the lists are not named (I think that's essentially what I want?)
<br><br>Thanks again,<br><br>Lauren<br><br><br><br><div><span class="gmail_quote">On 19/06/07, <b class="gmail_sendername"><a href="mailto:tutor-request@python.org">tutor-request@python.org</a></b> <<a href="mailto:tutor-request@python.org">
tutor-request@python.org</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Send Tutor mailing list submissions to<br>
<a href="mailto:tutor@python.org">tutor@python.org</a><br><br>To subscribe or unsubscribe via the World Wide Web, visit<br> <a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor
</a><br>or, via email, send a message with subject or body 'help' to<br> <a href="mailto:tutor-request@python.org">tutor-request@python.org</a><br><br>You can reach the person managing the list at<br>
<a href="mailto:tutor-owner@python.org">tutor-owner@python.org</a><br><br>When replying, please edit your Subject line so it is more specific<br>than "Re: Contents of Tutor digest..."<br><br><br>Today's Topics:
<br><br> 1. Re: iterating over a sequence question.. (Luke Paireepinart)<br> 2. Re: Help converting base32 to base16 (Alan Gauld)<br> 3. Re: Finding all locations of a sequence (fwd) (Danny Yoo)<br> 4. Re: sockets ( Linus Nordstr?m )
<br> 5. Re: sockets (Alan Gauld)<br> 6. Re: Finding all locations of a sequence (fwd) (Alan Gauld)<br> 7. Re: cannot pickle instancemethod objects (hok kakada)<br> 8. Re: Python and XSI (Vishal Jain)<br><br><br>----------------------------------------------------------------------
<br><br>Message: 1<br>Date: Mon, 18 Jun 2007 13:37:21 -0500<br>From: "Luke Paireepinart" <<a href="mailto:rabidpoobear@gmail.com">rabidpoobear@gmail.com</a>><br>Subject: Re: [Tutor] iterating over a sequence question..
<br>To: "Simon Hooper" <<a href="mailto:simon@partex.co.uk">simon@partex.co.uk</a>>, <a href="mailto:tutor@python.org">tutor@python.org</a><br>Message-ID:<br> <<a href="mailto:dfeb4470706181137x737f84b9l358a84c8c2043b16@mail.gmail.com">
dfeb4470706181137x737f84b9l358a84c8c2043b16@mail.gmail.com</a>><br>Content-Type: text/plain; charset="iso-8859-1"<br><br>On 6/18/07, Simon Hooper <<a href="mailto:simon@partex.co.uk">simon@partex.co.uk</a>
> wrote:<br>><br>> Hi Luke,<br>><br>> * On 17/06/07, Luke Paireepinart wrote:<br>> > a more expanded version that accounts for either list being the longer<br>> > one, or both being the same length, would be:
<br>> ><br>> > >>> if len(t) > len(l): x = len(t)<br>> > else: x = len(l)<br>> > >>> print [(l[i%len(l)],t[i%len(t)]) for i in range(x)]<br>> > [(1, 'r'), (2, 'g'), (3, 'b'), (4, 'r'), (5, 'g')]
<br>><br>> Being the duffer that I am, I'm very pleased with myself that I came up<br>> with a similar solution (albeit as a function rather than a list<br>> comprehension) :)<br>><br>> You do not need the if statement either,
<br><br><br>Yeah, I never knew about the max() function!<br>I noticed someone else used it in one of their solutions.<br>I'm pretty sure I've seen it a lot before, just didn't remember it.<br>-Luke<br>-------------- next part --------------
<br>An HTML attachment was scrubbed...<br>URL: <a href="http://mail.python.org/pipermail/tutor/attachments/20070618/1cf0ac67/attachment-0001.html">http://mail.python.org/pipermail/tutor/attachments/20070618/1cf0ac67/attachment-0001.html
</a><br><br>------------------------------<br><br>Message: 2<br>Date: Mon, 18 Jun 2007 21:12:02 +0100<br>From: "Alan Gauld" <<a href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>><br>Subject: Re: [Tutor] Help converting base32 to base16
<br>To: <a href="mailto:tutor@python.org">tutor@python.org</a><br>Message-ID: <<a href="mailto:f56oul$lah$1@sea.gmane.org">f56oul$lah$1@sea.gmane.org</a>><br>Content-Type: text/plain; format=flowed; charset="iso-8859-1";
<br> reply-type=original<br><br><br>"Jason Massey" <<a href="mailto:jason.massey@gmail.com">jason.massey@gmail.com</a>> wrote<br><br>> Nice entry at wikipedia:<br>><br>> <a href="http://en.wikipedia.org/wiki/Base_32">
http://en.wikipedia.org/wiki/Base_32</a><br>><br><br>Thanks for the link, I should have thought of oooking there!<br>I've heardof Base64 for encoding email but never come<br>across Base32 - any of the versions!<br>
<br>Alan G.<br><br><br><br>------------------------------<br><br>Message: 3<br>Date: Mon, 18 Jun 2007 16:54:53 -0400 (EDT)<br>From: Danny Yoo <<a href="mailto:dyoo@cs.wpi.edu">dyoo@cs.wpi.edu</a>><br>Subject: Re: [Tutor] Finding all locations of a sequence (fwd)
<br>To: <a href="mailto:tutor@python.org">tutor@python.org</a><br>Message-ID: <<a href="mailto:Pine.LNX.4.63.0706181653280.18230@cs.wpi.edu">Pine.LNX.4.63.0706181653280.18230@cs.wpi.edu</a>><br>Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
<br><br>Hi everyone,<br><br>Can someone help Lauren? I apologize for this, but I am very time<br>constrained at this moment, and won't be able to reply back for at least a<br>few hours. His question is below. Thanks!
<br><br><br>---------- Forwarded message ----------<br>Date: Mon, 18 Jun 2007 16:41:39 -0400<br>From: Lauren <<a href="mailto:laurenb01@gmail.com">laurenb01@gmail.com</a>><br>To: Danny Yoo <<a href="mailto:dyoo@cs.wpi.edu">
dyoo@cs.wpi.edu</a>><br>Subject: Re: [Tutor] Finding all locations of a sequence<br><br>Ok, these may be useful. I do have a potentially embarrassing problem,<br>however I will preface this with I'm practically computer illiterate. Ok
<br>after I download the one you wrote (which I think I understand better than<br>the one listed previous...famous last words, I'm sure), but when I ask to<br>import the ahocorasick module, it says it can't find it :( Is it possible to
<br>get step by step instructions on how to open the module? Do I need something<br>other than the latest download for it?<br>Again, I'm not good at this programming thing, so I'm sure I'm missing<br>something obvious
<br><br>Thank you for your help,<br><br>Lauren<br><br>On 18/06/07, Danny Yoo <<a href="mailto:dyoo@cs.wpi.edu">dyoo@cs.wpi.edu</a>> wrote:<br>><br>><br>><br>>> Ok, what I have is a RNA sequence (about 5 million nucleotides
<br>>> [characters] long) and have (4100) subsequences (from another sequence)<br>>> and the sub-sequences are 6 characters long, that I want to find in it.<br>><br>> Hi Lauren,<br>><br>> I am positive that this problem has been tackled before. Have you talked
<br>> to any of your fellow bioinformaticists? It might not be effective to ask<br>> on Python-tutor because, for typical problems, regexes are sufficient.<br>> For your particular scenario, regexes may not be, so you may want to ask
<br>> specialists like those on the Biopython mailing lists:<br>><br>> <a href="http://biopython.org/wiki/Mailing_lists">http://biopython.org/wiki/Mailing_lists</a><br>><br>> It may seem like a simple extension of regular expression search, but as
<br>> you may have noticed, feeding 4100 regex searches across that RNA sequence<br>> is going to take some time. And trying to feed all of those subsequences<br>> as a single regular expression (using ORs) is probably not going to work
<br>> too well either: the engine has limitations on how large the pattern can<br>> be before it starts behaving very badly.<br>><br>><br>> To scale to this problem, we need to do something different. What you're
<br>> probably looking for is more typically known as the keyword matching<br>> problem, and there are algorithms specifically used for keyword matching.<br>> For example, take a look at Nicholas Lehuen's Pytst package, which
<br>> implements ternary search trees:<br>><br>> <a href="http://nicolas.lehuen.com/index.php/category/Pytst">http://nicolas.lehuen.com/index.php/category/Pytst</a><br>><br>> I've also written a different package that uses the "Aho-Corasick"
<br>> automata matcher, but to tell the truth I've let the code stale a bit, and<br>> can't support it (too busy with other work). But if you're interested in<br>> tinkering with it, it's here:<br>
> <a href="http://hkn.eecs.berkeley.edu/~dyoo/python/ahocorasick/">http://hkn.eecs.berkeley.edu/~dyoo/python/ahocorasick/</a><<a href="http://hkn.eecs.berkeley.edu/%7Edyoo/python/ahocorasick/">http://hkn.eecs.berkeley.edu/%7Edyoo/python/ahocorasick/
</a>><br>> .<br>><br>><br>> If you're going to do more string-matching stuff, I'd recommend a look<br>> into "Algorithms on Strings, Trees, and Sequences".<br>><br>> <a href="http://www.cambridge.org/uk/catalogue/catalogue.asp?isbn=0521585198">
http://www.cambridge.org/uk/catalogue/catalogue.asp?isbn=0521585198</a><br>><br>> It's one of the better books on bioinformatics string algorithms, and it<br>> specifically covers this class of sequence-searching problems.
<br>><br><br><br><br>--<br>Lauren<br><br><a href="mailto:Laurenb01@gmail.com">Laurenb01@gmail.com</a><br><br><br>------------------------------<br><br>Message: 4<br>Date: Tue, 19 Jun 2007 01:19:45 +0200<br>From: " Linus Nordstr?m " <
<a href="mailto:linusno@gmail.com">linusno@gmail.com</a>><br>Subject: Re: [Tutor] sockets<br>To: <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>Message-ID:<br> <<a href="mailto:1eb3a0e10706181619r762bdacdqf64424148d0749dd@mail.gmail.com">
1eb3a0e10706181619r762bdacdqf64424148d0749dd@mail.gmail.com</a>><br>Content-Type: text/plain; charset=ISO-8859-1; format=flowed<br><br>gusse i use this thread as my own little help thread.. :)<br><br>im having problem whit recv. It will not break the loop if ther are
<br>nothing more to recive. It dose recv all tit should, but then it go<br>another round in the loop and get stuck on recv, as far as print<br>debugging has showed, Dont realy know waht ells information i could<br>write sown to make my problem anny clrearer, so ask if anythin is
<br>unclear :)<br><br>And on another note, is there a way to use the self. less, it might be<br>just me but it looks rather ugly :)<br><br>def recive(self):<br> all_data = []<br> while 1:<br> self.buf
= self.s.recv(4096)<br> if not self.buf: break<br> all_data.append(self.buf)<br> return all_data<br><br><br>On 6/18/07, Linus Nordstr?m <<a href="mailto:linus@linusnordstrom.com">linus@linusnordstrom.com
</a>> wrote:<br>> Hello<br>> I'm trying to rewrite a chat-program i did in school this spring in<br>> python, the school program was in java. All this to leran python.<br>><br>> Anyway. I m trying to send a message using udp to a server that
<br>> conntains the message 3 0 0 0, it has to be in network byte order and<br>> unsigned. I have tried to send it like a string "3000" but get an<br>> error message from the server saying that it did recive 4 bytes, but
<br>> that it was an unknown message<br>><br>> So what i am wondering is if there are anny special byte arrays, or<br>> some thing i should use. or if there are anny other way than to send<br>> the message than a string.
<br>><br><br><br>------------------------------<br><br>Message: 5<br>Date: Tue, 19 Jun 2007 00:34:28 +0100<br>From: "Alan Gauld" <<a href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>>
<br>Subject: Re: [Tutor] sockets<br>To: <a href="mailto:tutor@python.org">tutor@python.org</a><br>Message-ID: <<a href="mailto:f574q7$tlr$1@sea.gmane.org">f574q7$tlr$1@sea.gmane.org</a>><br>Content-Type: text/plain; format=flowed; charset="iso-8859-1";
<br> reply-type=original<br><br>"Linus Nordstr?m" <<a href="mailto:linusno@gmail.com">linusno@gmail.com</a>> wrote<br><br>> im having problem whit recv. It will not break the loop if ther are<br>
> nothing more to recive.<br><br>Take a look at the client side of the address book<br>example in my network profgramming topic. It shows<br>an example of breaking out of a recv loop.<br><br>Another option is to use the select module services
<br><br>> And on another note, is there a way to use the self. less,<br>> it might be just me but it looks rather ugly :)<br><br>No, it's good practice, it distinguishes between class level<br>variables and local variables. The use of self/this etc is usually
<br>required in industrial coding standards for C++ and Java<br>(eg Dept of defense/Government etc) for the same reason,<br>even though those languages don't require it. As in many<br>things python is simply enforcing what is already considered
<br>good practice elsewhere.<br><br>HTH,<br><br>--<br>Alan Gauld<br>Author of the Learn to Program web site<br><a href="http://www.freenetpages.co.uk/hp/alan.gauld">http://www.freenetpages.co.uk/hp/alan.gauld</a><br><br><br>
<br><br>------------------------------<br><br>Message: 6<br>Date: Tue, 19 Jun 2007 00:37:46 +0100<br>From: "Alan Gauld" <<a href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>><br>Subject: Re: [Tutor] Finding all locations of a sequence (fwd)
<br>To: <a href="mailto:tutor@python.org">tutor@python.org</a><br>Message-ID: <<a href="mailto:f5750e$u4o$1@sea.gmane.org">f5750e$u4o$1@sea.gmane.org</a>><br>Content-Type: text/plain; format=flowed; charset="iso-8859-1";
<br> reply-type=original<br><br><br>> From: Lauren <<a href="mailto:laurenb01@gmail.com">laurenb01@gmail.com</a>><br>> To: Danny Yoo <<a href="mailto:dyoo@cs.wpi.edu">dyoo@cs.wpi.edu</a>><br>> Subject: Re: [Tutor] Finding all locations of a sequence
<br>><br>> after I download the one you wrote (which I think I understand<br>> better than<br>> the one listed previous...famous last words, I'm sure), but when I<br>> ask to<br>> import the ahocorasick module, it says it can't find it :(
<br><br>You will need to ocate and download the module too.<br>Either store it along with your program or in the site-packages<br>folder in your python installation.<br><br>> get step by step instructions on how to open the module?
<br><br>You just import it.<br>You can read more about that in my modules and functions topic<br>if that helps.<br><br>--<br>Alan Gauld<br>Author of the Learn to Program web site<br><a href="http://www.freenetpages.co.uk/hp/alan.gauld">
http://www.freenetpages.co.uk/hp/alan.gauld</a><br><br><br><br><br><br>------------------------------<br><br>Message: 7<br>Date: Tue, 19 Jun 2007 12:19:31 +0700<br>From: hok kakada <<a href="mailto:hokkakada@khmeros.info">
hokkakada@khmeros.info</a>><br>Subject: Re: [Tutor] cannot pickle instancemethod objects<br>To: tutor-python <<a href="mailto:tutor@python.org">tutor@python.org</a>><br>Message-ID: <<a href="mailto:200706191219.32263.hokkakada@khmeros.info">
200706191219.32263.hokkakada@khmeros.info</a>><br>Content-Type: text/plain; charset="utf-8"<br><br>?????? ??? 13 ?????? 2007 19:09, Kent Johnson ??????????????<br>> hok kakada wrote:<br>> >> What kind of object is matcher? Does it have any attributes that are
<br>> >> functions? (Not methods you defined for the class, but functions or<br>> >> methods that you assign to attributes of self.)<br>> ><br>> > Actually, I use the translate-toolkit from<br>
> > <a href="http://translate.sourceforge.net/snapshots/translate-toolkit-1.0.1rc1/">http://translate.sourceforge.net/snapshots/translate-toolkit-1.0.1rc1/</a><br>> > in translate/search/match.py:<br>> > if comparer is None:
<br>> > comparer = lshtein.LevenshteinComparer(max_length)<br>> ><br>> > self.comparer = comparer<br>> ><br>> > I just found the problem that it is because of the LevenshteinComparer.
<br>> > Once I assign self.comparer = None, the I can dump the matcher<br>> > successfully. However, I still don't understand what could be wrong with<br>> > LevenshteinComparer.<br>><br>> I think the problem is this code in LevenshteinComparer.__init__():
<br>><br>> if Levenshtein:<br>> self.distance = self.native_distance<br>> else:<br>> self.distance = self.python_distance<br>><br>> which assigns an instance method to an instance attribute; this is the
<br>> instancemethod that can't be pickled.<br>Ok...but how can we deal with it?<br><br>Kind Regards,<br>da<br><br><br>------------------------------<br><br>Message: 8<br>Date: Tue, 19 Jun 2007 12:08:36 +0400<br>From: "Vishal Jain" <
<a href="mailto:vishal.thebigv@gmail.com">vishal.thebigv@gmail.com</a>><br>Subject: Re: [Tutor] Python and XSI<br>To: <a href="mailto:tutor@python.org">tutor@python.org</a><br>Message-ID:<br> <<a href="mailto:5f3b7ddd0706190108y7ebe22ax2e859fb3760d1ee2@mail.gmail.com">
5f3b7ddd0706190108y7ebe22ax2e859fb3760d1ee2@mail.gmail.com</a>><br>Content-Type: text/plain; charset="iso-8859-1"<br><br>Yes XSI is a 3D package from Avid. Also knows as Softimage|XSI<br><br>By everything failed I mean that XSI isnt registering Python resulting in I
<br>cant select scripitng langauge as Python inside XSI. After running the said<br>script the command prompt says "Python:Registered" but no error messages.<br><br>Yes XSI supports only ActiveX Scripts.<br><br>If everything goes good I expect to select scripting langauge as Python
<br>inside XSI and start scripting. But apparently eveything went good as per<br>the manuals and docs except my luck :(<br><br>I did search google but will search more as per your guidlines. And I am a<br>beginner too in Python. I never coded before.
<br><br>Thanks a lot for ur suggestions and concern.<br><br>By the way are you the same Alan Gauld who posts in XSI Base and CG Talk??<br><br>Vishal<br><br>Message: 6<br>Date: Mon, 18 Jun 2007 16:09:35 +0100<br>From: "Alan Gauld" <
<a href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>><br>Subject: Re: [Tutor] Python and XSI<br>To: <a href="mailto:tutor@python.org">tutor@python.org</a><br>Message-ID: <<a href="mailto:f5677j$e1f$1@sea.gmane.org">
f5677j$e1f$1@sea.gmane.org</a>><br>Content-Type: text/plain; format=flowed; charset="iso-8859-1";<br> reply-type=original<br><br>"Vishal Jain" <<a href="mailto:vishal.thebigv@gmail.com">vishal.thebigv@gmail.com
</a>> wrote<br><br>> I am trying to get Python registered with XSI but<br>> everything described in docs failed.<br><br>OK, I'm assuming that XSI is the 3D Graphics software from Avid?<br><br>Can you tell us which docs and what exactly 'failed' means?
<br>What did you do and what actually happened?<br>Any error messages?<br><br>> C:\Python25\Lib\site-packages\win32comext\axscript\client\pyscript.py<br><br>ISTR that as being the script for registering Python as an<br>
Active Scripting language for WSH and the IE ActiveX engine.<br><br>I assume from that, that XSI uses active scripting?<br><br>What did you expect to happen after running it?<br>And what did happen?<br><br>> still no luck. Is anybody else also facing the same situation? I am
<br>> not very<br>> sure how many people here uses Python for XSI but still hoping to<br>> get some<br><br>I had to do a Google search...<br>You might have more luck on the main comp.lang.python list or<br>maybe even in the pyGame list. This group is for beginners to Python
<br>and XSI looks a tad advanced for most beginners, going by the couple<br>of pages I browsed. OTOH there is usually somebody here with an<br>interest in most things...<br><br>--<br>Alan Gauld<br>Author of the Learn to Program web site
<br><a href="http://www.freenetpages.co.uk/hp/alan.gauld">http://www.freenetpages.co.uk/hp/alan.gauld</a><br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: <a href="http://mail.python.org/pipermail/tutor/attachments/20070619/ded2eb30/attachment.htm">
http://mail.python.org/pipermail/tutor/attachments/20070619/ded2eb30/attachment.htm</a><br><br>------------------------------<br><br>_______________________________________________<br>Tutor maillist - <a href="mailto:Tutor@python.org">
Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a><br><br><br>End of Tutor Digest, Vol 40, Issue 46<br>*************************************<br>
</blockquote></div><br><br clear="all"><br>-- <br>Lauren<br><br><a href="mailto:Laurenb01@gmail.com">Laurenb01@gmail.com</a>