CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Usage of substrings

 



kumarsaurabh20
New User

Jun 28, 2011, 2:43 AM

Post #1 of 2 (2390 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


miller
User

Jun 29, 2011, 3:07 PM

Post #2 of 2 (2365 views)
Re: [kumarsaurabh20] Usage of substrings [In reply to] Can't Post

Since you're already pulling the entire file into memory, just use the index function.

- Miller

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives