in reply to Question: homemade blat: insert query from keyboard to find an oligo in an hashtable
First, you can change that line to $query = <STDIN>; and the program will read what you type in instead of doing the magic of reading from the file contained in @ARGV.
Second, you could empty the @ARGV array at the top of your program by saying $nomefile = shift @ARGV;. shift would remove the first (and in your case the only) filename from the command line and that would solve the problem when using the empty diamond <> operator later in the program.
Even though the second method would solve your problem, it is probably still better to use <STDIN> when reading a response from the command line anyway. That way, you will avoid any problems in your program.
I tried to understand what your program does and attempted to solve it using the Bio::SeqIO module which provides a good way to deal with fasta files. Documentation for BioPerl is here.
My example program and sample fasta data file are below.
The data file I tested with was:#usr/bin/perl use strict; use warnings; use Bio::SeqIO; # 'shift' removes items from @ARGV my $nomefile = shift; print "Insert query:\n"; chomp(my $query = uc <STDIN>); my $test = Bio::SeqIO->new( -file => $nomefile, -format => 'fasta'); print "\nResults for $nomefile\n\n"; while (my $seq = $test->next_seq()) { my @pos; my $id = $seq->id; my $fasta = uc $seq->seq; while ($fasta =~ /(?=$query)/g) { push @pos, $-[0] + 1; } if (@pos) { printf "%s compare %d volte in posizione @pos with ID %s\n", $query, scalar @pos, $id; } else { print "$query does not appear in the sequence with ID $id\n"; + } }
Output I got from this sample data in response to the query was:>chr1 AACCCCCCCCTCCCCCCGCTTCTGGCCACAGCACTTAAACACATCTCTGC CAAACCCCAAAAACAAAGAACCCTAACACCAGCCTAACCAGATTTCAAAT TTTATCTTTAGGCGGTATGCACTTTTAACAAAAAANNNNNNNNNNNNNNN NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN GCCCATCCTACCCAGCACACACACACCGCTGCTAACCCCATACCCCGAAC CAACCAAACCCCAAAGACACCCCCCACAGTTTATGTAGCTTACCTCNNNN >chrM GATCACAGGTCTATCACCCTATTAACCACTCACGGGAGCTCTCCATGCAT TTGGTATTTTCGTCTGGGGGGTGTGCACGCGATAGCATTGCGAGACGCTG GAGCCGGAGCACCCTATGTCGCAGTATCTGTCTTTGATTCCTGCCTCATT CTATTATTTATCGCACCTACGTTCAATATTACAGGCGAACATACCTACTA AAGTGTGTTAATTAATTAATGCTTGTAGGACATAATAATAACAATTGAAT GTCTGCACAGCCGCTTTCCACACAGACATCATAACAAAANAATTTCCACC
Insert query: tatt TATT does not appear in the sequence with ID chr1 TATT compare 5 volte in posizione 20 55 152 155 177 with ID chrM
I hope this helps answer your question. If you don't understand some of the code I wrote, ask and I'll try to explain. There are probably some new things there that you may not have seen yet.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Question: homemade blat: insert query from keyboard to find an oligo in an hashtable
by nikkk (Novice) on Dec 05, 2015 at 10:46 UTC | |
by Cristoforo (Curate) on Dec 05, 2015 at 18:03 UTC | |
by nikkk (Novice) on Dec 06, 2015 at 10:10 UTC | |
by nikkk (Novice) on Dec 10, 2015 at 16:44 UTC | |
by Cristoforo (Curate) on Dec 15, 2015 at 16:27 UTC |