Dear Monks
I have written a program to take a character in File 1 to be used to replace a character at that place in File2. Meanwhile
I am not getting the right output.
My Code is :-
#!/usr/bin/perl use strict; use warnings; $location=""; my $qfn1 = "File1.txt"; my $qfn2 = "File2.txt"; my %positions; { open(my $fh, '<', $qfn1) or die("Cannot open file \"$qfn1\": $!\n"); while (<$fh>) { my ($key, $pos) = split /\s+/; $positions{$key} = $pos; $location = $3; } } my %sequences; { open(my $fh, '<', $qfn2) or die("Cannot open file \"$qfn2\": $!\n"); my $key; while (<$fh>) { if ( s/^>// ) { $key = ( split /\|/ )[1]; } else { chomp; $sequences{$key} .= $_; } } if ( ! exists( $sequences{$key} )) { warn "KEY $key in File1 not found in File2\n"; next; } my $dna = $sequences{$key}; my $index = rindex($dna,$positions{$key}); my $position = $index; my $current_base = substr($dna, $position, 1); my $newbase = $location; substr($dna,$position,1,$newbase); my $Location = $position + 1; print "$sequences{$key}"; }
My Input Files look like this:-
File 1:- 155369268 5 C 169212695 7 T File 2:- >gi|155369268|ref|NM_001100917.1| After all AAACAATGTCGATTCTATGATGCGAACGCAGCATTTCAGGGACTGGATGAGGAGCTTACGGTTTTTTACT ACAGAATCATCAATATCTTGGAAGAAAAAGAATGTTAAGAAATAACAAAACAATAATTATTAAGTACTTT >gi|169212695|ref|XM_001716884.1| Its the code AGACAAGCTTGTCCTGATGTTCCTTGCCCTGGCAGATGTTCAGGACCTTCCTTTGATTCAACCCCTCCAC CTAAATGGCCCAAGCTTTCGGGGCTGTCATTGTCTGTTTGTCATTCAAGGGCCCAAGCTGAAGAGGGGGT
I am looking for an output in the same format as File2 but with a replaced character.
Like Suppose in case 155369268 my 5th position changes from A to C. My 169212695 7th position changes from G to T.
So the output would be like this:-
>gi|155369268|ref|NM_001100917.1| After all AAACCATGTCGATTCTATGATGCGAACGCAGCATTTCAGGGACTGGATGAGGAGCTTACGGTTTTTTACT ACAGAATCATCAATATCTTGGAAGAAAAAGAATGTTAAGAAATAACAAAACAATAATTATTAAGTACTTT >gi|169212695|ref|XM_001716884.1| Its the code AGACAATCTTGTCCTGATGTTCCTTGCCCTGGCAGATGTTCAGGACCTTCCTTTGATTCAACCCCTCCAC CTAAATGGCCCAAGCTTTCGGGGCTGTCATTGTCTGTTTGTCATTCAAGGGCCCAAGCTGAAGAGGGGGT
good bye

20081224 Janitored by Corion: Restored content


In reply to Character replacement by ashnator

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.