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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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


New User

Jun 28, 2011, 2:43 AM

Post #1 of 2 (5537 views)
Usage of substrings Can't Post

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 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..:

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*$/) {
@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/);

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??????



Jun 29, 2011, 3:07 PM

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