
kumarsaurabh20
New User
Jun 28, 2011, 2:43 AM
Post #1 of 2
(1434 views)
|
|
Usage of substrings
|
Can't Post
|
|
Hi, I have been trying to write a script for finding a pattern (a seq of characters like ATAGATAGAT) with the exact position on a file. The file is a big seq of characters. I also want to extract 100 charcaters up and downstream of that pattern. I tried with the following code...so its showing me the positions..but my prob is I am not able to extract the up and downstream characters..i know we can do this using substring function but I dont know how to apply that in my code.... here is my code..: #!/usr/bin/perl use strict; use warnings; use BeginPerlBioinfo; my @file_data = (); my $query = ''; my $dna = ''; my @locations = (); @file_data = get_file_data("sample.txt"); $dna = extract_sequence_from_fasta_data(@file_data); do { print "Search for what Restriction Site?:"; $query = <STDIN>; chomp $query; if ($query =~ /^\s*$/) { exit; } @locations = match_positions($query, $dna); if (@locations) { print "Searching for $query\n"; print "A restriction site for $query at locations:\n"; print join(" ", @locations), "\n"; } else { print " A restriction site for $query is not in the DNA:\n"; } print "\n"; } until ($query =~ /quit/); exit; sub match_positions { my($query, $dna) = @_; use strict; use BeginPerlBioinfo; my @positions = (); while ($dna =~ m/$query/ig){ push(@positions, pos($dna) - length($&) + 1); } return @positions; Could anyone help me here?????? ciao
|