Sorry for the very long email. and I my brain is dead to create some related generic snippet. Thus, I shrunk the string and lists into as short as I could. apologies again. srini
--- Srinivas Iyyer <[EMAIL PROTECTED]> wrote: > Dear Tutors, > I have a huge string and 2 lists. List A consists > of > tabed elements, where first tab represents entry > somewhere in string(ndat). > ndat has 'Contig27915_RC' and List A [nbat]has > 'Contig27915_RC\tXM_945977'. List B [nmlist]has > elements, for instance ['XM_945977\tNM_152513']. > Now > my task, is to take each element in nbat(listA) > search > in string ndat and nmlist, if found in nmlist, > replace > with its tabed counterpart in ndat string. > > How did I choose to solve: > 1. I could not think in the most smartest way as > said > easily above. Say take element from nbat, see if > modified version of it > available in nmlist, if found replace that modifed > element in string. > > So I chose to take element from listA (nbat), search > in string ndat. If found replace with it tabed > element(Contig27915_RC\tXM_945977 => XM_945977) and > store that in a new list. Now loop over this new > list > for each element check if a new version available in > nmlist. If so replace and print. > > One of the proble is that, Contig27915_RC is seen > associated with many XM entries in nbat. However, > with the above script I could replace only once in > xta. I could not print Contig27915_RC with many XM_ > guys in nbat. How can this be done. > > Finally, this whole process seems to be more > cumbersome to me. Could any one tip me with a new > way > of dealing this 3 way mapping. > > Thanks > > Script: > > xt = '' > for m in nbat: > cols = m.split('\t') > old = cols[0] > new = cols[1] > if ndat.find(old): > xt = ndat.replace(old,new) > > xta = xt.split('\n') > >>> for x in xta: > ... for m in nmlist: > ... cols = m.split('\t') > ... colold = cols[0] > ... colnew = cols[1] > ... if x == colold: > ... print x+'\t'+colnew > ... > XM_945977 NM_152513 > > > -XTA result --- snip--- > Contig25622_RC > Contig13475_RC > Contig40179_RC > XM_945977 <- <- <- ['Contig27915_RC\tXM_945977'] > Contig44682_RC > Contig35934_RC > -------------- > > > > > > > ndat = > """Pro25G\nvariant_gridline\nG3PDH_570\nPro25G_onG3PDH570_20bp\nPro25G_onG3PDH570_10Ts\nr60_1\nr60_3\nr60_n9\nr60_a22\nr60_a104\nr60_a107\nr60_a135\nr60_a97\nr60_a20\nr60_n11\nContig45645_RC\nContig44916_RC\nD25272\nJ00129\nContig29982_RC\nContig26811\nD25274\nContig36292\nContig42854\nContig34839\nContig8376_RC\nContig42014_RC\nD49958\nContig25622_RC\nContig13475_RC\nContig40179_RC\nContig27915_RC\nContig44682_RC\nContig35934_RC\nContig29373_RC\nAF155648\nContig46975_RCx""" > > > nbat = ['Contig45645_RC\tNM_022469', > 'Contig44916_RC\tNM_080764', 'J00129\tNM_005141', > 'Contig29982_RC\tNM_173833', 'D25274\tNM_006908', > 'D25274\tNM_018890', 'D25274\tNM_198829', > 'D49958\tNM_201591', 'D49958\tNM_005277', > 'D49958\tNM_201592', 'Contig13475_RC\tNM_212555', > 'Contig40179_RC\tNM_138570', > 'Contig27915_RC\tXM_934912', > 'Contig27915_RC\tXM_934911', > 'Contig27915_RC\tXM_934908', > 'Contig27915_RC\tXM_934906', > 'Contig27915_RC\tXM_934902', > 'Contig27915_RC\tXM_934901', > 'Contig27915_RC\tXM_934899', > 'Contig27915_RC\tXM_934897', > 'Contig27915_RC\tXM_934896', > 'Contig27915_RC\tXM_945989', > 'Contig27915_RC\tXM_945987', > 'Contig27915_RC\tXM_945986', > 'Contig27915_RC\tXM_945985', > 'Contig27915_RC\tXM_945983', > 'Contig27915_RC\tXM_945982', > 'Contig27915_RC\tXM_945980', > 'Contig27915_RC\tXM_945978', > 'Contig27915_RC\tXM_945977'] > > nmlist = ['XM_929405\tNM_001039615', > 'XM_934896\tNM_152513', 'XM_934897\tNM_152513', > 'XM_934899\tNM_152513', 'XM_934901\tNM_152513', > 'XM_934902\tNM_152513', 'XM_934904\tNM_152513', > 'XM_934906\tNM_152513', 'XM_934908\tNM_152513', > 'XM_934911\tNM_152513', 'XM_934912\tNM_152513', > 'XM_945977\tNM_152513', 'XM_945978\tNM_152513', > 'XM_945980\tNM_152513', 'XM_945982\tNM_152513', > 'XM_945983\tNM_152513', 'XM_945984\tNM_152513', > 'XM_945985\tNM_152513', 'XM_945986\tNM_152513', > 'XM_945987\tNM_152513', 'XM_945989\tNM_152513', > 'XM_085261\tNM_001039958', > 'XM_938609\tNM_001039958', > 'XM_373868\tNM_001009931', > 'NM_001012239\tNM_173683', > 'XM_929314\tNM_001609', 'XM_940521\tNM_001609', > 'XM_932741\tNM_001262', 'XM_945305\tNM_001262', > 'XM_928890\tNM_152830'] > > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam > protection around > http://mail.yahoo.com > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor