Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read file in array 1

Status
Not open for further replies.

mama12

Programmer
Oct 18, 2005
22
NL
Hi all,
what is the beste script in Perl to read a file (DNA Sequence)in array and mutate this file between 7% and 10 %
 
At the risk of sounding desperately unfashionable, I think mama2 is being rude to TWB, who has spent many of his Sunday hours trying to be helpful to a stranger. Apart from anything else, mis-spelling his name as "torjan" seems an odd way of indicating appreciation.

mama12: give it a try. You might learn something and, who knows? you might even enjoy it. Coding is an intrinsic part of modern genetics research and you need to put some effort in if you are going to get anywhere: you can't make a satisfying career by merely piggybacking on others.

I hope that the future of genetics lies in more polite hands.

Sincerely,

fish

["]As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.["]
--Maur
 
Yes - i totally agree with shif ;-)

All that code should transcend any language barriers... i would have expected she could be a bit more grateful than that!


Kind Regards
Duncan
 
The code looks good Trojan. Just a couple thoughts: one thing that I notice is you could implement a hash of arrays (%lookup) in which the keys are each character from $charset, and the values would be an array of the remaining characters. Something like:
Code:
my %lookup = map {my $temp = $_; $_, [map {lc} grep {$_ ne $temp} split('', $charset)]} split('', $charset);
Yuck, that's ugly. But it would save at least one substr call per interation and there's no need for a loop to determine the replacement character. Second, using a lookup hash like that would result in 12 (numChars * (numChars-1)) lc() calls, where the code above would result in numberOfStrings * numberOfSubstitutions * numberOfRatios calls to lc().

Using %lookup,
Code:
foreach my $index (keys %indexes) {
  my $char = substr($_,$index,1);
  my $newchar;
  do {
    $newchar = substr($charset, rand(4), 1);
  } while ($char eq $newchar);
  substr($_,$index,1) = lc $newchar;
}
can be boiled down to
Code:
foreach my $index (keys %indexes) {
      my $char = substr($_,$index,1);
      substr($_,$index,1,$lookup{$char}[int(rand(@{$lookup{$char}}))]);
}
 
Hi torjan,

I did it, the script is working now, i did little changes on it and it is working now,sorry that I did not let u know.

Kind Regards

mama12
 
this is not a typo. it is someone's name. not difficult to read. Trojan is 6 letters. i make damn sure if i am asking someone a question a) i get their name right & b) i am polite. sorry, i just don't agree with you

... no offence


Kind Regards
Duncan
 
Torjan is top of my MPV list!

shif

["]As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.["]
--Maur
 
I wish my momma named me Trojan when I was born, even though it's a popular brand of condoms in the USA, it's still a cool name. [upsidedown]
 
UK: change name by deed poll - £20 - bargain!

fish (yes, honestly).

["]As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.["]
--Maur
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top