If I understand your problem, you want to convert

AB AAAA_BBBBB DE AC2-(EC 2.7.00.1) (Adaptor-associated DE protein 1). //

into:

AB AAAA_BBBBB DE AC2-(EC 2.7.00.1) (Adaptor-associated protein 1).

(i.e, collapse all the lines beginning with the same "tag" for each "//" separated block).

if this is what you intend, try this script

#!/usr/bin/perl use strict; use warnings; $/ = "//\n"; while (my $block = <DATA>){ chomp $block; my @tags; ## keep the order of the tags my %vals; foreach my $line (split /\n/, $block){ $line =~ /(..)\s+(.+)$/; my ($tag,$val) = ($1,$2); if (!defined $vals{$tag}){ push @tags,$tag; $vals{$tag}=$val; }else{ $vals{$tag}.=" $val"; } } for my $tag (@tags){ print "$tag\t$vals{$tag}\n"; } print "//\n"; } __DATA__ AB AAAA_BBBBB DE AC2-(EC 2.7.00.1) (Adaptor-associated DE protein 1). // ID CCCCC_DDDDD DE Serine/threonine-protein kinase (EC 2.7.99.1) (Tyrosine DE binding protein) (p35BP). PR AAAAAAAAAAAAAAAAAAAAAAA. // ID RRRRR_GGGGG AC Q6Q8; DE Serine/threonine-aaaaaa kinase (Tyrosine DE kinase 1) (Apoptosis-associated tyrosine kinase) (AATYK) (Brain DE binding protein) (p35BP). PR xxxxxxxxxxxxxx. CD zzzzzzzzzzzzzz. //

Outputs:

AB AAAA_BBBBB DE AC2-(EC 2.7.00.1) (Adaptor-associated protein 1). // ID CCCCC_DDDDD DE Serine/threonine-protein kinase (EC 2.7.99.1) (Tyrosine bindin +g protein) (p35BP). PR AAAAAAAAAAAAAAAAAAAAAAA. // ID RRRRR_GGGGG AC Q6Q8; DE Serine/threonine-aaaaaa kinase (Tyrosine kinase 1) (Apoptosis- +associated tyrosine kinase) (AATYK) (Brain binding protein) (p35BP). PR xxxxxxxxxxxxxx. CD zzzzzzzzzzzzzz. //

Hope this helps!

citromatik


In reply to Re: swissprot parsing DE by citromatik
in thread swissprot parsing DE by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.