Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

ashnator's scratchpad

by ashnator (Sexton)
on Sep 09, 2008 at 06:24 UTC ( [id://709977]=scratchpad: print w/replies, xml ) Need Help??

#!/usr/bin/perl use strict; use warnings; my $qfn1 = "File1.txt"; my $qfn2 = "File2.txt"; my %positions; { open(my $fh, '<', $qfn1) or die("Cannot open file \"$qfn1\": $!\n"); while (<$fh>) { chomp; #line added my ($key, $pos) = split /\s+/; if (!$positions{$key}) { $positions{$key} = [$pos]; } else { my $ref = $positions{$key}; push @$ref,$pos; } } } 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} .= $_; } } } for my $key ( sort keys %positions ) { my $ref = $positions{$key}; foreach my $value (@$ref) { if ( ! exists( $sequences{$key} )) { warn "KEY $key in File1 not found in File2\n"; next; } if ( length( $sequences{$key} ) < $positions{$key} ) { warn "KEY $key: File2 string length too short for File1 positi +on value\n"; next; } my $index = rindex( $sequences{$key}, "ATG", $positions{$key} ); if ( $index < 0 ) { warn sprintf( "KEY %s: No ATG in File2 string prior to positio +n %d\n", $key, $positions{$key} ); next; } $index += 3 while ( ($index + 3) < $positions{$key} ); print "$key $positions{$key} " . substr($sequences{$key}, $index, +3) . "\n"; } }
My Input file look like this:-
File 1:- 155369268 17 A 155369268 60 C 269212605 49 G File 2:- >gi|155369268|ref|NM_001100917.1| some text AAACAATGTCGATTCTATGATGCGAACGCAGCATTTCAGGGACTGGAATGGGAGCTTACGGTTTTTTACG ACAGAATCATCAATATCTTGGAAGAAAAAGAATGTTAAGAAATAACAAAACAATAATTATTAAGTACTTT >gi|155369268|ref|XM_001716884.1| some text AGACAAGCTTGTCCTGATGTTCCTTGCCCTGGCAGATGTTCAGGACCATGGGAGCTTACGGTTTTTTACG CTAAATGGCCCAAGCTTTCGGGGCTGTCATTGTCTGTTTGTCATTCAAGGGCCCAAGCTGAAGAGGGGGT >gi|269212605|ref|XM_401716884.1| some text AGACAAGCTTGTCCTGATGTTCCTTGCCCTGGCAGATGTTCAGGACCTTCCTTTGATTCAACCCTATGAC CTAATTGGCCCAAGCTTTCGGGGCTGTCATTGTCTGTTTGTCATTCAAGGGCCCAAGCTGAAGAGGGGGT
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-19 11:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found