Hi all, I've a file with 12 column with the following format: read_no,read_name,read_len,read_position_begin,read_position_end,reference_seq_no,reference_position_begin,reference_position_end,reversed,no_of_match,paired,alignment_score Example of the file:
223445 BG2A093.x1 51 7 51 4 75 96 0 1 0 44 223446 BG2A073.x1 51 7 51 4 43 95 0 1 0 44 223447 BG2A033.x1 51 7 51 4 44 92 0 1 0 42 223448 BG2A693.x1 51 7 51 4 45 93 1 1 0 43 223449 BG2A045.x1 51 7 51 4 47 95 1 1 0 47 223501 BG2A034.x1 51 7 51 4 47 95 0 1 0 46 223442 BG2A021.x1 51 7 51 4 48 96 0 1 0 45
What I'm trying to do is to add a number next to column no.7, so that whenever there is an duplication in column 7 and column 8 to the next line. So the result will be something like this:
223445 BG2A093.x1 51 7 51 4 1 75 96 0 1 0 +44 223446 BG2A073.x1 51 7 51 4 2 75 95 0 1 0 4 +3 223447 BG2A033.x1 51 7 51 4 1 44 92 0 1 0 +42 223448 BG2A693.x1 51 7 51 4 1 45 93 1 1 0 +43 223449 BG2A045.x1 51 7 51 4 1 47 95 1 1 0 +47 223501 BG2A034.x1 51 7 51 4 2 47 95 0 1 0 +46 223442 BG2A021.x1 51 7 51 4 1 48 96 0 1 0 +45
I've try some perl scripts and came up something like this:
#!/usr/local/bin/perl -w my $pre_ref_pos_b; my $pre_ref_pos_e; my $count while (<>) { chomp; my ($r_no,$r_name,$r_len,$r_pos_b, $r_pos_e, $ref_seq_no, $ref_pos_ +b, $ref_pos_e, $rev, $no_match, $paired, $aln_score) = split; while (defined($pre_ref_pos_b) && defined($pre_ref_pos_e) eq $ref_p +os_b && $ref_pos_e) { $count++; print $r_name,$count,$r_ref_pos_b,$ref_pos_e\n; } $pre_ref_pos_b = $ref_pos_b; $pre_ref_pos_e = $ref_pos_e; } }
The problem is I've no idea how the lines of data being kept in the memory, and how should I put in the program so that it will reset the count whenever the the ref_pos_b and ref_pos_e is different from the proceeding lines. Your help is really appreciate, I'm learning the perl, and I'm still very very new to it. Best regads.

In reply to Compute previous lines data by joomanji

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.