tag:blogger.com,1999:blog-21289662.post1951637107107601515..comments2023-09-26T01:39:21.395-07:00Comments on Bioinformatics: Loopless programming (for calculating methylation types)brentphttp://www.blogger.com/profile/12236821145627337774noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-21289662.post-35030043334728777852010-02-01T23:41:31.970-08:002010-02-01T23:41:31.970-08:00This comment has been removed by a blog administrator.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-21289662.post-63875098856391063482010-01-25T05:02:40.712-08:002010-01-25T05:02:40.712-08:00The main benefit is that my function generalizes t...The main benefit is that my function generalizes to ndarray i.e. the input could represent an alignment i.e. be a rank-2 numpy array. The other benefit is that it works on numpy arrays as the "find" method is broken in char arrays.<br /><br />In [1]: "AGCG".find('GC')<br />Out[1]: 1<br />In [2]: arr = np.array('AGCG', dtype='c').view(np.char.chararray)<br />In [3]: arr.find('GC')<br />Out[3]: array([-1, -1, -1, -1])<br /><br />char array does not do the right thing because it takes each element from arr e.g. 'A' and calls it's method e.g. 'find' withe the given argument e.g. 'GC', which fails "G".find("GC") returns -1Anonymoushttps://www.blogger.com/profile/12551269207203881043noreply@blogger.comtag:blogger.com,1999:blog-21289662.post-57581687237952521162010-01-24T13:13:27.146-08:002010-01-24T13:13:27.146-08:00ah, i see. is there a benefit over the
pure pytho...ah, i see. is there a benefit over the <br /><a href="http://python.pastebin.com/m58274a5d" rel="nofollow">pure python version</a><br />?<br />i guess yours could more easily handle multiple ktup's with numpy broadcasting.brentphttps://www.blogger.com/profile/12236821145627337774noreply@blogger.comtag:blogger.com,1999:blog-21289662.post-82624797221999454132010-01-24T12:20:04.008-08:002010-01-24T12:20:04.008-08:00It allows to find occurrences of words in a sequen...It allows to find occurrences of words in a sequence e.g. all start codons in a sequence of letters<br />>>> sequence = np.array('ATGCGCGTAGCTATGAGAGCATCGAT', dtype='c')<br />>>> find(sequence, 'ATG')<br />(array([ 0, 12]),)<br /><br />The first ATG starts at index 0 the second at index 12. The output from "find" can be used to index an array.<br /><br />>>> sequence[find(sequence, 'ATG')]<br />array(['A', 'A'],<br /> dtype='|S1')Anonymoushttps://www.blogger.com/profile/12551269207203881043noreply@blogger.comtag:blogger.com,1999:blog-21289662.post-53827609521421179332010-01-24T11:04:08.808-08:002010-01-24T11:04:08.808-08:00@diffusing thoughts . cool. could you show an exam...@diffusing thoughts . cool. could you show an example usage? i'm not quite sure i follow.brentphttps://www.blogger.com/profile/12236821145627337774noreply@blogger.comtag:blogger.com,1999:blog-21289662.post-58280956024903605822010-01-23T19:46:53.280-08:002010-01-23T19:46:53.280-08:00I like your approach. In a similar spirit this lit...I like your approach. In a similar spirit this little function finds the first index of every k-tuple in a numpy array. http://python.pastebin.com/f46f7dae7Anonymoushttps://www.blogger.com/profile/12551269207203881043noreply@blogger.com