Please keep all communications in the group so that all others can see
your question and therefore you have a higher chance to get help.
Just in case you do not know, a good way to see whether your program
works as you expected is that run it in the command line with perl
followed by the name of program.
In your code, I saw several syntax error without running it. Please
allow me to point them out.
Below is your code with line number in the head of each line (you can
get that by running "cat -n lengthmail.pl").
1 #!/usr/bin/perl
2 # generate DNA of length size
3 use strict;
4 use warnings;
5 #Declare and initialize the variables
6 my $file = ("GAC.txt"); #/tmp/file.txt
7 # Get a file handle (IO::File object) you can write to
8 my $file_handle = $file;
9 my$maximum_length = 260;
10 my$minimum_length = 130;
11 # an array , initialized to the empty list, to store DNA in
12 my @length_DNA = ();
13 @length_DNA = make_length_DNA($minimum_length, and $maximum_length);
14 #print the results , one per line
15 print " with lengths between $minimum_length and $maximum_length:\n\n";
16
17 for each my $file (@length_DNA ==1;@length_DNA<11; $count++));{
18 if ($minimum_length ==130, and $maximum_length ==260)
19 {
20 print"$DNA of length\n";
21 }}
22 print "\n";
23
24 exit;
In line 6, you try to assign a file name to a scalar variable,
however, What you are doing is assigning the size of an array to
$file, so what $file will get is the size of array which is 1 but not
"GAC.txt" as you expected. (Hint, remove the parentheses);
line 13, make_length_DNA seems like a subroutine, however, you have
not defined in your script. PERL definitely will complain about this.
line 17, 1) You should use "for" not "for each" if you put some
conditions in the parenthese; 2) use '=' for assignment. @length_DNA
==1 is testing the equality of the values of the variables around '=='
sign; 3) Also, your loop is going to be an infinite loop, because the
for loop terminate condition you are putting there is @length_DNA<11,
however, the only variable keep changing after each iteration is the
$count variable. I mean the @length_DNA have never got a chance to
change so it always be true. I guess you want to a for loop like this
"for (my $count = 0; $count < @length_DNA; $count++){...}
Zhigang
On Tue, Nov 29, 2011 at 4:01 AM, indira mekala <ind...@gmail.com> wrote:
> sir/madame,
>
>
> i have written a per program, which sorts out the sequences of base pair of
> length more than 130 among a whole length of all the sequences, sir is the
> programme right?
>
>
>
>
> #!/usr/bin/perl
> # generate DNA of length size
> use strict;
> use warnings;
> #Declare and initialize the variables
> my $file = ("GAC.txt"); #/tmp/file.txt
> # Get a file handle (IO::File object) you can write to
> my $file_handle = $file;
> my$maximum_length = 260;
> my$minimum_length = 130;
> # an array , initialized to the empty list, to store DNA in
> my @length_DNA = ();
> @length_DNA = make_length_DNA($minimum_length, and $maximum_length);
> #print the results , one per line
> print " with lengths between $minimum_length and $maximum_length:\n\n";
>
> for each my $file (@length_DNA ==1;@length_DNA<11; $count++));{
> if ($minimum_length ==130, and $maximum_length ==260)
> {
> print"$DNA of length\n";
> }}
> print "\n";
>
> exit;
>
>
> ---------- Forwarded message ----------
> From: Zhigang Wu <zhiga...@email.ucr.edu>
> Date: Mon, Nov 28, 2011 at 11:43 PM
> Subject: Re: regular expression question (escaping)
> To: ucr-perl-bi...@googlegroups.com
>
>
> Thanks for your quick responses.
> Yes, Sofia, your solution is definitely correct.
> By taking Jason's hint, below is the working code (I have removed the
> unnecessary quotes for those words contained in qw).
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> my $number = 10;
> my @seqs = qw (AAAAAAAAAAAAAAAAAAAAA ATCGTGAGGTGTCCAAGT);
> for my $seq (@seqs){
> my $flag = 0;
> for my $nt (qw /A T C G/ ){
> if ($seq =~ /\Q$nt\E{\Q$number\E,}/){
> $flag = 1;
> }
> }
> if (! $flag){
> print $seq,"\n";
> }
> }
>
>
>
>
> On Mon, Nov 28, 2011 at 9:46 AM, Sofia Robb <sofi...@gmail.com> wrote:
>> Hi,
>>
>> Perl definitely thinks your $nt{$number,} is a hash.
>>
>> You need to make perl not interpret your statement to be a hash.
>> Here is the first solution I came up with, but there are probably plenty
>> more. I took away the need for a variable to denote the nucleotide that
>> you
>> are looking for.
>>
>> #!/usr/bin/perl
>> use warnings;
>> use strict;
>> my $number = 10;
>> my @seqs = qw ('AAAAAAAAAAAAAAAAAAAAA' 'TTTTTTTTTTTTTTTT'
>> 'ATCGTGAGGTGTCCAAGT');
>> for my $seq (@seqs){
>> my $flag = 0;
>> #for my $nt (qw / 'A' 'T' 'C' 'G'/ ){
>> if ($seq =~ /A{$number}|T{$number}|G{$number}|C{$number,}/){
>> $flag = 1;
>> }
>> #}
>>
>> if (! $flag){
>> print $seq,"\n";
>> }
>> }
>>
>>
>> On Mon, Nov 28, 2011 at 9:22 AM, Zhigang Wu <zhiga...@email.ucr.edu>
>> wrote:
>>>
>>> Hi All,
>>> I have a little question on regular expression. What I wanna to do is
>>> to refrain from reporting any sequences which contain more than
>>> defined number of poly nucleotides. Below is the code I wrote to
>>> achieve this goal. Specifically, the array @seq contains three
>>> sequences and the $number is defined to have value 10. My expected
>>> result is that since both sequence 'AAAAAAAAAAAAAAAAAAAAA' and
>>> 'TTTTTTTTTTTTTTTT' has more than 10 As so that they won't be printed
>>> out after the filter process. However, the regular expression I wrote
>>> $nt{$number,} is not working as I expected. PERL keeps complaining
>>> "Global symbol "%nt" requires explicit package name", which seems like
>>> that PERL recognized "$nt{$number,}" as an Hash data structure. I
>>> tried to put the double quotes around $nt and $number
>>> "$nt"{"$number",}. The result is not what I want, PERL did not
>>> complain any syntax error though. How can I get it work? Any thoughts
>>> and comments are welcome.
>>>
>>>
>>> #!/usr/bin/perl
>>> use warnings;
>>> use strict;
>>> my $number = 10;
>>> my @seqs = qw ('AAAAAAAAAAAAAAAAAAAAA' 'TTTTTTTTTTTTTTTT'
>>> 'ATCGTGAGGTGTCCAAGT');
>>> for my $seq (@seqs){
>>> my $flag = 0;
>>> for my $nt (qw / 'A' 'T' 'C' 'G'/ ){
>>> if ($seq =~ /$nt{$number,}/){
>>> $flag = 1;
>>> }
>>> }
>>> if (! $flag){
>>> print $seq,"\n";
>>> }
>>> }
>>> --
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------------------------------
>>> PhD Candidate in Plant Biology
>>> Department of Botany and Plant Sciences
>>> University of California, Riverside
>>
>>
>>
>>
>
>
>
> --
>
>
>
> ---------------------------------------------------------------------------------------------
> PhD Candidate in Plant Biology
> Department of Botany and Plant Sciences
> University of California, Riverside
>
--
---------------------------------------------------------------------------------------------
PhD Candidate in Plant Biology
Department of Botany and Plant Sciences
University of California, Riverside