in reply to Re^2: Key value pair in hash inside while loop
in thread Key value pair in hash inside while loop

What is the expected output?

I can see the matching part at line 180:

180 G 179 181 230 180 181 U 180 182 229 181 182 U 181 183 228 182 183 C 182 184 227 183 184 U 183 185 226 184 185 U 184 186 225 185 186 A 185 187 0 186 187 U 186 188 0 187 188 U 187 189 0 188 189 U 188 190 0 189 190 G 189 191 0 190 191 C 190 192 224 191 192 A 191 193 223 192 193 C 192 194 222 193 194 C 193 195 221 194 195 U 194 196 220 195 196 A 195 197 0 196 197 C 196 198 218 197 198 U 197 199 217 198

which corresponds to the following match:

3-Match: GTTCTTATTTGCACCTACT 6 180

What do you want to do with it?

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^4: Key value pair in hash inside while loop
by newtoperlprog (Sexton) on Aug 28, 2014 at 17:16 UTC

    Hi,

    Thank you for your reply. The expected output would be listed like below:

     GTTCTTATTTGCACCTACT    180

    for simplicity I have truncated the data file 2 at 300 number, but in actuality, the list may have 3k - 4k numbers.

    Regards

      If that's all you want for output, the following would do that.
      #!/usr/bin/perl use strict; use warnings; use Inline::Files; my %data; while (<A>) { chomp; my (undef, $fragment, undef, $pos) = split /\t/; $data{$pos} = $fragment; } <B>; # throw away header '300 dG = -62.54 ...' while (<B>) { my $pos = (split /\t/)[0]; print "$data{$pos} $pos\n" if $data{$pos}; } __A__ 1-Match: GGTGTTGTATGCCTTTAAA 5 3545 2-Match: GGAAAGTCAAGCCCATCTA 9 3254 3-Match: GTTCTTATTTGCACCTACT 6 180 4-Match: GATGAGGAACAGCAACCTT 5 844 __B__ 300 dG = -62.54 [initially -70.70] gi178893_M23263_rna_300-1 1 G 0 2 0 1 2 A 1 3 0 2 3 A 2 4 0 3 4 U 3 5 0 4 5 U 4 6 0 5 6 C 5 7 0 6 7 C 6 8 0 7 8 G 7 9 34 8 9 G 8 10 33 9 ........ ........ 179 A 178 180 231 179 180 G 179 181 230 180 181 U 180 182 229 181 ........ ........

        Thanks Cristoforo,

        I modified the code as suggested by you but I thing the program is giving me error of uninitialized values.

        #!/usr/bin/perl -w + use strict; use warnings; my $matchfile = "match_super.dat"; my $ctfile = "M23263_rna_300-1.dat_1.ct"; my @match;my %data;my $fragment; my $pos; open (A, "<", $matchfile) or die "Check the file $!\n"; while (my $line = <A>) { chomp $line; (undef, $fragment, undef, $pos) = split(/\t/, $line); $data{$pos} = $fragment; } close (A); my ($num1, $base, $num2, $num3, $connect, $num4); open (B, "<", $ctfile) or die "Check the file $!\n"; while (my $ctline = <B>) { chomp $ctline; if ($ctline =~ /^(\d+\s+dG.*)/) { # print "$1\n"; next; + next; } $pos = (split /\s+/)[0]; print "$data{$pos} $pos\n" if $data{$pos}; } close (B);
        Error: Use of uninitialized value $pos in hash element at ./second_str_map.pl + line 29, <B> line 298. Use of uninitialized value $_ in split at ./second_str_map.pl line 28, + <B> line 299. Use of uninitialized value $pos in hash element at ./second_str_map.pl + line 29, <B> line 299. Use of uninitialized value $_ in split at ./second_str_map.pl line 28, + <B> line 300. Use of uninitialized value $pos in hash element at ./second_str_map.pl + line 29, <B> line 300. Use of uninitialized value $_ in split at ./second_str_map.pl line 28, + <B> line 301. Use of uninitialized value $pos in hash element at ./second_str_map.pl + line 29, <B> line 301.