Hi, i really need your help. I have one file containing a long string of DNA, and another file containing the start and stop positions of genes in the DNA. like this :
1 1800 1900 2254
etc. in which the first number is the start position and the second is the stop position. I need to map these positions to the DNA string and replace them with X's. I dont know whether I should be treating the start/stop positons file as a hash or array?? - there are lots of values so i couldn't declare them if i used a hash. Error messages say that $finish isn't declared within the second foreach loop. Heres the code so far:
#! /usr/local/bin/perl -w use strict; open (INPUT, "<positions.input") or die "unable to open file"; open (INPUT2, "<dna.file") or die "unable to open file"; open (OUTFILE, ">$$.output"); @dna = <INPUT2>; $dna = join ('', @dna); $dna =~ s/\s//g; @dna = split ('', $dna); $count = 0; $base = ("A"| "C"| "G" | "T"); foreach $base (@dna) { ++$count; } while (<INPUT>) { $line = $_; chomp ($line); @orfs = (); @orfs = split (/\s+/, $line); my @start = $orfs[0]; my @finish = $orfs[1]; } foreach $start (@orfs) { $start = substr ($dna, 0, $start); substr ($dna, $start +1, $finish - $start) =~ s/A-Z/X/g; $dna =~ s/(.{60})/$1\n/g; print "$dna\n"; print OUTFILE "$dna\n"; } close INPUT; close INPUT2; close OUTFILE; exit;
this is my attempt, i realise it is bad and can't think of a good way to do this. THANX. lol

Edit kudra, 2002-04-24 Added to title


In reply to in need of wisdom: handling DNA strings by lolly

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.