Question: homemade blat: insert query from keyboard to find an oligo in an hashtable
gravatar for nico_ce90
4.2 years ago by
nico_ce900 wrote:

i wrote a script that given a sequence extracts a 'n' dimension hashtable of oligos, and tells how many times and where a certain oligo is located. 

I want to insert from keyboard an oligo and extract the positions, but ican't write it down. Any suggestions?

Thank you very much!

That's my script, that when asked to insert query returns the name of the file i opened first....

use strict;

my $f;
my $nomefile;
my $line;

my %oligo = ();
my %pos = ();
my $piece;
my $query;
my $sequenza;
my $i;

$nomefile = $ARGV[0];

open $f, "< $nomefile" or die "cannot open $nomefile: $!";


$sequenza = <$f>;


while($line = <$f>)
    if(substr($line, 0, 1) ne ">")
        $sequenza = $sequenza.$line;

$sequenza = uc $sequenza;


for($i = 0; $i < length($sequenza) - 4; $i++)

 $piece = substr($sequenza, $i, 4);

 if(exists $oligo{$piece})
     $oligo{$piece} = $oligo{$piece} + 1;
     push(@{$pos{$piece}} , $i + 1);
    $oligo{$piece} = 1;
    push(@{$pos{$piece}} , $i + 1);

foreach $piece (sort keys %oligo)


print("Insert query:\n");
$query = <>;


$query = uc $query;

if(exists $oligo{$query})
 print("$query\t compare $oligo{$query} volte\t in posizione @{$pos{$query}}\n");
    print("$query does not appear in the sequence");


ADD COMMENTlink modified 4.2 years ago • written 4.2 years ago by nico_ce900

Thank you very much for your kind answer, it was very simple, I'm new in using Perl but I'm enjoying it very much! Can I ask a little enlightment please?

How can I make it work with a query not the length used to create the index (for example a query >n or a multiple of n)?


ADD REPLYlink modified 9 weeks ago by RamRS25k • written 4.2 years ago by nico_ce900
gravatar for Jean-Karim Heriche
4.2 years ago by
EMBL Heidelberg, Germany
Jean-Karim Heriche21k wrote:

Use <STDIN> to read from STDIN. When @ARGV is not empty, <> reads from the files in @ARGV. If you still want to keep using <>, then empty @ARGV first e.g. $nomefile = shift @ARGV;

ADD COMMENTlink modified 9 weeks ago by RamRS25k • written 4.2 years ago by Jean-Karim Heriche21k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2145 users visited in the last hour