Hi ,

I have interesting problem as I have a file 'A' which looks like

>BIG_CLUSTER96  ENSTNIP00000002777      TETRAODON8      1       105     136     [B]Ank[/B]     NGCTPLHYAASKDRYEIALMLLENGADPNATD
>BIG_CLUSTER96  ENSTNIP00000002777      TETRAODON8      1       141     169     [B]Ank [/B]    TPLHRASAKGNYRLIQLLLRQSASTNIQD
>BIG_CLUSTER96  ENSTNIP00000002777      TETRAODON8      1       172     202     [B]Ank [/B]    GNTPLHLACDEERVEAAKLLVEHGASIYIEN
>BIG_CLUSTER96  ENSTNIP00000002777      TETRAODON8      1       40      71      [B]Ank  [/B]   RRTALHWACSAGHTDIVEFLLDVGAEVNLQDD
>BIG_CLUSTER96  ENSTNIP00000002777      TETRAODON8      1       74      103     [B]Ank  [/B]   WTPLHIAASAGREDIVRALISKGAQLNSVN

as you see the first coloumn and second coloumn is same , and the bold word is also same so what i want to con catenate the string shown in red colour , to gether but in a given acsending order based on the number given in green colour , please help

Something like this?

a = """>BIG_CLUSTER96  ENSTNIP00000002777      TETRAODON8      1       105     136     Ank     NGCTPLHYAASKDRYEIALMLLENGADPNATD
>BIG_CLUSTER96  ENSTNIP00000002777      TETRAODON8      1       141     169     Ank     TPLHRASAKGNYRLIQLLLRQSASTNIQD
>BIG_CLUSTER96  ENSTNIP00000002777      TETRAODON8      1       172     202     Ank     GNTPLHLACDEERVEAAKLLVEHGASIYIEN
>BIG_CLUSTER96  ENSTNIP00000002777      TETRAODON8      1       40      71      Ank     RRTALHWACSAGHTDIVEFLLDVGAEVNLQDD
>BIG_CLUSTER96  ENSTNIP00000002777      TETRAODON8      1       74      103     Ank     WTPLHIAASAGREDIVRALISKGAQLNSVN
"""
data = [line.split() for line in a.splitlines() if line]
print data
extract = sorted((int(info[4]), info[-1]) for info in data)
print extract
print ' Result '.center(60,'*')
print ''.join(seq for order, seq in extract)
print '-'*40
print 'All these as one liner'
print ''.join(seq
              for order, seq in sorted((int(info[4]), info[-1])
                                       for info in (line.split()
                                                    for line in a.splitlines()
                                                    if line)))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.