Hi everybody, I need help with a Perl/CGI task.

I reported my code below; I simplified it without using real data so to make it shorter

Essentially I have an hash of many sequences (only reported 2 in the example below)

In my hash the keys are the names of the sequences, while the values are the nucleotide sequences (DNA)

I want to iterate through the hash and filter it to make another hash only with those sequences which have

at least one of the patterns AGGAG or TTTTT; also if one, or both this patterns are present, I want to highlight them

in the sequences with 2 different colours. Until here, everything is fine. However some of my real sequences are very long (1000 nucleotides)

so I would like to print each sequence with 50 or 60 characters per line in my cgi page, to look more tidy.

In the code below I filtered the first hash with a regex and I added coloured tags to those 2 patterns I am looking for

The problem is that the unpack function messes up with the presence of the tags, which are included in the

characters count when unpacking and printing; therefore each line end up being of different length, or, even worse, some tag break because

they span 2 lines if they are in the location at which the unpacking is going to the next line

I have been trying to sort this out but I can not find a solution

I am a beginner, and I would like to find a simple solution, if there is one; without using extra modules, if possible

also because I do not have admin privileges in the Unix machine I am using

Many thanks

#!/usr/bin/perl use strict; use warnings; use Bio::SeqIO; use CGI; my $cgi = new CGI; print $cgi->header(); print <<__EOF; <html> <head> <style type='text/css'> <!-- body { background: lightgrey; color: black; font-family: Courier; margin:20px; } h1 { color: black; font-family: Verdana; font-size: 150%; } h2 { color:red; font-family: Courier; } .sd { color:red; } .terminator { color: royalblue; } --> </head> </style> <h1> Sequences with <span class="sd"> SD sequence</span> or <span class="t +erminator">terminator structure</span>: </h1> <body> __EOF my %hash; my $name1= "name1"; my $name2= "name2"; $hash{$name1} = "ATATTATCCCCCTATATATGGAGGGAGAGGGGGGGGGGGGGGGGGGGGGGGGG +GGAGAGAGGAGATTTTTTTTTTTTTTTT" $hash{$name2} = "ATATATTATATATATTATATTCGCGCGCGCGGCGCGCGCGGCGCGCGCGTTTT +TTTTTTTTTTAGGAGAGAGAGGGAGGAGGAGAGGGGAGT" foreach my $key (keys %hash) { if ($hash{$key} =~ s!(aggag)!<span class="sd">$1</span>!gi) { + $hash2{$key} = $hash{$key}; } if ($hash{$key} =~ s!(ttttt)!<span class="terminator">$1</span>!ig) + { $hash2{$key} = $hash{$key}; } my %hash2; foreach my $key (keys %hash2) { print "<p> <b>$key</b><input type='radio' name='selected_intergenic' v +alue='$hash2{$key}'/> </p>"; print "<p>$_</p>\n" for unpack '(A50)*', $hash2{$key}; } print <<__EOF; <br /> </body> </html> __EOF

In reply to Print N characters per line in Cgi Script with Html Tags by Diesel

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.