split the sequences

R

Rita

Hi All,
I am posting my program code here and it is working ,But i am sure ther
will be another way to do it.this program taking one sequence from
<Data> and putting in MFOLD server and making structure of it. and
result is storing in result.out
any suggeation will be appriciated.Thanks

use warnings;
use strict;
use Bio::SeqIO;

my $outputfile = 'result.out';
open (OUTPUT, '>', $outputfile) || die "Can't open \"$outputfile\" $!";


my $filename1 = <DATA>;
open (FILE1,$filename1 )||die "Cannot open file \"$filename1\"\n\n $!";
<FILE1>;
while(my $line =<FILE1>){
(my ($id,$hit_name,$hairpin_sequence) = (split /\t/, $line)[0,2,4]);

my $seqio = Bio::SeqIO-> new(-file =>'>temp1',-format=>'fasta');
$hairpin_sequence = Bio::Seq-> new(-seq => $hairpin_sequence,
-display_id=>$hit_name);
$seqio->write_seq($hairpin_sequence);

system (" mfold SEQ='temp1'");
open( my $rpt, 'temp1.out') or die("Can't open temp1.out: $!");

print OUTPUT "Hit Name-$hit_name\t,Sequence name-$id\n";

while(<$rpt>) {
print OUTPUT3;
}
close($rpt) or die ;
}
close FILE1;
close OUTPUT;
 
P

Paul Lalli

Rita said:
I am posting my program code here and it is working ,

I don't believe you.
But i am sure ther
will be another way to do it.this program taking one sequence from
<Data> and putting in MFOLD server and making structure of it. and
result is storing in result.out
any suggeation will be appriciated.Thanks

use warnings;
use strict;
use Bio::SeqIO;

my $outputfile = 'result.out';
open (OUTPUT, '>', $outputfile) || die "Can't open \"$outputfile\" $!";

You have been told, repeatedly, that it is better to use lexical
filehandles instead of global barewords. Why do you bother asking for
advice if you refuse to follow it? What is the point of this post?

open my $OUTPUT, '>', $outputfile or die "Can't open '$outputfile':
$!";
my $filename1 = <DATA>;

There is no __DATA__ token in this code. This isn't reading anything.
open (FILE1,$filename1 )||die "Cannot open file \"$filename1\"\n\n $!";

You have been told, repeatedly, to use the three-argument form of open.
Why do you ignore the advice you ask for?

open my $FILE1, '<', $filename1 or die "Cannot open file '$filename1':
$!";

Are you intending to throw away the first line in the file? A comment
to that effect for such a non-standard thing to do would be a good
idea.
while(my $line =<FILE1>){
(my ($id,$hit_name,$hairpin_sequence) = (split /\t/, $line)[0,2,4]);

my $seqio = Bio::SeqIO-> new(-file =>'>temp1',-format=>'fasta');
$hairpin_sequence = Bio::Seq-> new(-seq => $hairpin_sequence,
-display_id=>$hit_name);

You just assigned $hairpin_sequence to be the fifth field in $line.
Now you're reassigning it to be a Bio::Seq object. You never used it
between assignments. What are you trying to do?
$seqio->write_seq($hairpin_sequence);

system (" mfold SEQ='temp1'");
open( my $rpt, 'temp1.out') or die("Can't open temp1.out: $!");

So, here you do use lexical filehandles, but still don't use the
three-argument form of open. If you're going to do the wrong thing,
you could at least do it consistently.
print OUTPUT "Hit Name-$hit_name\t,Sequence name-$id\n";

You really want a comma *after* the tab? That seems bizarre.
while(<$rpt>) {
print OUTPUT3;

What the heck is OUTPUT3? That was never declared. This has got to be
giving you either "print on closed filehandle" or "use of bareword
forbidden while strict" warnings or errors. I don't know which, but
one of them.

COPY AND PASTE your code. Do not retype. I know you've been asked
that before too. Again you ask for advice, and ignore the advice your
given.
}
close($rpt) or die ;

I know you've been told to print out *why* a system call fails. Use
the $! variable.

Was this whole loop designed to just copy temp1.out to whatever OUTPUT3
is supposed to be?

use File::Copy;
copy 'temp1.out', \*OUTPUT3 or die "could not copy: $!";
close FILE1;
close OUTPUT;

Earlier you checked your close()'s for failures (which is good.) Here
you do not. Why?

Here you're again trying to read from the non-existant __DATA__ token,
and throw away the results.
Query Name (Start,End) Hit Name (Start,End) Sequence

These are all syntax errors. Was this the part that was supposed to be
under __DATA__?
Your code above shows that you are reading a filename from <DATA>.
None of this looks like a filename.

Why do you keep expecting us to put time into helping you when you
refuse to either take our advice or put any time into thinking about
your post before you make it?

Paul Lalli
 
R

Rita

Paul said:
I don't believe you. believe me it is.

You have been told, repeatedly, that it is better to use lexical
filehandles instead of global barewords. Why do you bother asking for
advice if you refuse to follow it? What is the point of this post?

but someone in my office whenever i use lexical filehandles he says it
doesnot make any deffrence so you can use like this ,and i saw in books
too like this so...
open my $OUTPUT, '>', $outputfile or die "Can't open '$outputfile':
$!";
now I changed in my code ,thanks.
There is no __DATA__ token in this code. This isn't reading anything.

in my program ,I am using filename and here i just gave you some data
You have been told, repeatedly, to use the three-argument form of open.
Why do you ignore the advice you ask for?

open my $FILE1, '<', $filename1 or die "Cannot open file '$filename1':
$!";


Are you intending to throw away the first line in the file? A comment
to that effect for such a non-standard thing to do would be a good
idea.

yes,I want to ignore the file Header.
while(my $line =<FILE1>){
(my ($id,$hit_name,$hairpin_sequence) = (split /\t/, $line)[0,2,4]);

my $seqio = Bio::SeqIO-> new(-file =>'>temp1',-format=>'fasta');
$hairpin_sequence = Bio::Seq-> new(-seq => $hairpin_sequence,
-display_id=>$hit_name);

You just assigned $hairpin_sequence to be the fifth field in $line.
Now you're reassigning it to be a Bio::Seq object. You never used it
between assignments. What are you trying to do?
No ,Here i am putting every sequence in temp1 file so it can be use by
MFOLD(It take only one sequence)
Was this whole loop designed to just copy temp1.out to whatever OUTPUT3
is supposed to be?

No,It is going by MFOLD too and making structure.
 
P

Paul Lalli

Rita said:
but someone in my office whenever i use lexical filehandles he says it
doesnot make any deffrence so you can use like this ,and i saw in books
too like this so...

The someone in your office is wrong. And many of those books are
written with pre-Perl 5.6 syntax and style. Work towards the best
available, not the lowest common denominator.

The differences that lexical filehandles make:
* They are subject to 'use strict', so they notify you if you made a
typo - like with OUTPUT3 below.
* They are scoped to the enclosing block, so you can't accidentally
have two sections of unrelated code using the same filehandle because
you forgot you already used that name
* They automatically close your file at the end of their scope, rather
than the end of the program.

Tell the someone in your office to go buy Perl Best Practices and read
it. Twice.
now I changed in my code ,thanks.

in my program ,I am using filename and here i just gave you some data
so i use this but by mistake at place of _DATA_ i write <DATA>, Sorry.

One more time, this is why we ask you to COPY AND PASTE a working code
example. Do not make changes from what you have verified works to what
you post to this group. What you run and what we see should be
identical.
yes,I want to ignore the file Header.
while(my $line =<FILE1>){
(my ($id,$hit_name,$hairpin_sequence) = (split /\t/, $line)[0,2,4]);

my $seqio = Bio::SeqIO-> new(-file =>'>temp1',-format=>'fasta');
$hairpin_sequence = Bio::Seq-> new(-seq => $hairpin_sequence,
-display_id=>$hit_name);

You just assigned $hairpin_sequence to be the fifth field in $line.
Now you're reassigning it to be a Bio::Seq object. You never used it
between assignments. What are you trying to do?
No ,Here i am putting every sequence in temp1 file so it can be use by
MFOLD(It take only one sequence)

I have no idea what this has to do with my statement. You assigned
$hairpen_sequence to the fifth element of the split. Two statements
later, you reassigned $hairpen_sequence to be an object. It was never
used in between. That is, you have basically:

my $foo = 'stuff';
print "Hello world";
$foo = FooBar->new();

Why are you assigning $foo to 'stuff' to begin with?
No,It is going by MFOLD too and making structure.

No. Not your outer loop. The inner loop. The one that just ended at
the time of my comment. The one that does only:
while (<$rpt>){
print OUTFILE3;
}

Which doesn't at all explain how this takes the shape of a filename
that you intended to read from __DATA__.

Paul Lalli
 
R

Rita

Paul said:
Rita said:
The differences that lexical filehandles make:
* They are subject to 'use strict', so they notify you if you made a
typo - like with OUTPUT3 below.
* They are scoped to the enclosing block, so you can't accidentally
have two sections of unrelated code using the same filehandle because
you forgot you already used that name
* They automatically close your file at the end of their scope, rather
than the end of the program.

Tell the someone in your office to go buy Perl Best Practices and read
it. Twice. Sure ,Thanks.
in my program ,I am using filename and here i just gave you some data
so i use this but by mistake at place of _DATA_ i write <DATA>, Sorry.

One more time, this is why we ask you to COPY AND PASTE a working code
example. Do not make changes from what you have verified works to what
you post to this group. What you run and what we see should be
identical. From Next time,I will.
while(my $line =<FILE1>){
(my ($id,$hit_name,$hairpin_sequence) = (split /\t/, $line)[0,2,4]);

my $seqio = Bio::SeqIO-> new(-file =>'>temp1',-format=>'fasta');
$hairpin_sequence = Bio::Seq-> new(-seq => $hairpin_sequence,
-display_id=>$hit_name);

You just assigned $hairpin_sequence to be the fifth field in $line.
Now you're reassigning it to be a Bio::Seq object. You never used it
between assignments. What are you trying to do?
No ,Here i am putting every sequence in temp1 file so it can be use by
MFOLD(It take only one sequence)

I have no idea what this has to do with my statement. You assigned
$hairpen_sequence to the fifth element of the split. Two statements
later, you reassigned $hairpen_sequence to be an object. It was never
used in between. That is, you have basically:

my $foo = 'stuff';
print "Hello world";
$foo = FooBar->new();

Why are you assigning $foo to 'stuff' to begin with?


Here first i split the hairpin Sequence from file than I put that 1
sequnce from the file in temp1 and then used that temp1 in MFOLD.and i
put it in loop so everytime it split one sequence ,put that sequence in
temp1 and will using by MFOLD.and savin the output in OUTPUT.If i won't
do it then what will be value of temp1?


Which doesn't at all explain how this takes the shape of a filename
that you intended to read from __DATA__.

I dont understand ,what you want to ask here ,But this is my input
datas.
Thanks.
 
P

Paul Lalli

Rita said:
Paul said:
while(my $line =<FILE1>){
(my ($id,$hit_name,$hairpin_sequence) = (split /\t/, $line)[0,2,4]);

my $seqio = Bio::SeqIO-> new(-file =>'>temp1',-format=>'fasta');
$hairpin_sequence = Bio::Seq-> new(-seq => $hairpin_sequence,
-display_id=>$hit_name);
Here first i split the hairpin Sequence from file than I put that 1 sequnce
from the file in temp1 and then used that temp1 in MFOLD.

Oh. I see it now. You're using $hairpin_sequence as the string that
it is within the call to Bio::Seq->new(), and then assigning the return
value of that call back to $hairpin sequence. That is astonishlingly
bad design. You have one variable that is alternatively a string and
then an object. Use different variables for different structures.

I don't know what "hairpin sequence" actually means, so I don't know
which variable name you should change, but you should definately change
one.
I dont understand ,what you want to ask here ,But this is my input
datas.

Your code had:
my $filename1 = <DATA>;
open (FILE1,$filename1 )||die "Cannot open file \"$filename1\"\n\n $!";


You were trying to read a filename from <DATA>. But the text that you
tried to put into __DATA__ was not a filename, it was the contents of
the actual file. Therefore, your code example should have been using
<DATA> everywhere it was using <FILE1> (and you should not have opened
FILE1 at all).

Again, if you had copied and pasted your code after running it, you
would have found all these errors.

Paul Lalli
 
R

Rita

Paul said:
Again, if you had copied and pasted your code after running it, you
would have found all these errors.

use warnings;
use strict;
use Bio::SeqIO;

my $outputfile = 'result.out';
open my $OUTPUT, '>', $outputfile or die "Can't open \"$outputfile\"
$!";
my $filename1 = <DATA>;
open my $FILE1,'<',$filename1 or die "Cannot open file \"$filename1\"\n
$!";
<$FILE1>;
while(my $line =<$FILE1>){
(my ($id,$hit_name,$hairpin_sequence) = (split /\t/, $line)[0,2,4]);

my $seqio = Bio::SeqIO-> new(-file =>'>temp1',-format=>'fasta');
my $hairpin_seq = Bio::Seq-> new(-seq => $hairpin_sequence,
-display_id=>$hit_name);
$seqio->write_seq($hairpin_seq);

system (" mfold SEQ='temp1'");
open( my $rpt,'>', 'temp1.out') or die("Can't open temp1.out: $!");
print $OUTPUT "Hit Name-$hit_name\tSequence name-$id\n";
while(<$rpt>) {
print $OUTPUT;
}
close($rpt) or die $! ;
}
close ($FILE1) or die $!;
close ($OUTPUT) or die $!;

__DATA__
Query Name (Start,End) Hit Name (Start,End) Sequence
012971 (119,132) fru-mir-137 (42,55) ATGGTTAAAGTACATATAAAAACAATGATT
012971 (119,132) dre-mir-137-2 (72,85) ATGGTTAAAGTACATATAAAAACAAT
012971 (119,132) dre-mir-137-1 (48,61) ATGGTTAAAGTACATATAAAAACAAT
012971 (119,132) gga-mir-137 (51,64) ATGGTTAAAGTACATATAAAAACAATGATT
012971 (119,132) rno-mir-137 (56,69) ATGGTTAAAGTACATATAAAAACAATGATT
012971 (119,132) hsa-mir-137 (56,69) ATGGTTAAAGTACATATAAAAACAATGATT
012971 (119,132) mmu-mir-137 (42,55) ATGGTTAAAGTACATATAAA

I use your all advice ,hope now it will be good,But now my output is
not storing in 'result.out'. It is printing output of this line
print $OUTPUT "Hit Name-$hit_name\tSequence name-$id\n";
but not the print $OUTPUT;
Thanks.
 
P

Paul Lalli

Rita said:
I use your all advice ,hope now it will be good,

That's a lie. You did not use all my advice. You completely ignored
the first line right here. You haven't copied and pasted what you just
posted into a file and run it.

As suggested by another poster, my continuing to help you in spite of
you not following all my requests is only hurting matters.

I'm done with this thread. Good luck to you.

Paul Lalli
 
A

A. Sinan Unur

That's a lie. ....
I'm done with this thread.

Just plonk her move on, please ;-) You are a very kind person, and I have
been genuinely impressed with your patience, but she ain't gonna change.

Sinan
 
R

Rita

Paul said:
That's a lie. You did not use all my advice. You completely ignored
the first line right here. You haven't copied and pasted what you just
posted into a file and run it.

I dont understand now what i did.i copied and pasted my program
here."And now it is not giving that output what I want i dont know bcoz
of lexical File Handle of bcoz of 3 argument in open " But i changed my
program as you said.
As suggested by another poster, my continuing to help you in spite of
you not following all my requests is only hurting matters.

I'm done with this thread. Good luck to you.

I know i do some mistakes but i dont know why all are in my opposition
party,I tried my best.
 
P

Paul Lalli

A. Sinan Unur said:
Just plonk her move on, please ;-) You are a very kind person, and I have
been genuinely impressed with your patience, but she ain't gonna change.

You're right, unfortunately. The truly annoying part for me right now
is that her latest issue is actually a rather understandable error to
make, and also easily correctable. But she's long used up my remaining
good will.

Paul Lalli
 
X

xhoster

Rita said:
but someone in my office whenever i use lexical filehandles he says it
doesnot make any deffrence so you can use like this ,and i saw in books
too like this so...

If you trust the advice of someone in your office more than you trust
our advice, why are you asking your questions here, rather than asking
them to someone in your office?

Xho
 
R

Rita

Paul said:
That's a lie. You did not use all my advice. You completely ignored
the first line right here. You haven't copied and pasted what you just
posted into a file and run it.

As suggested by another poster, my continuing to help you in spite of
you not following all my requests is only hurting matters.

I'm done with this thread. Good luck to you.

oops,sorry i just saw my mistake .actually the problam is I am working
on linux system so I correct the program there and forgate to change in
windows one.
Now , I can understand how I hurt your feelings .I am really sorry
about it.

use warnings;
use strict;
use Bio::SeqIO;

my $outputfile = 'result.out';
open my $OUTPUT, '>', $outputfile or die "Can't open \"$outputfile\"
$!";

while(my $line =<DATA>){
(my ($id,$hit_name,$hairpin_sequence) = (split /\t/, $line)[0,2,4]);

my $seqio = Bio::SeqIO-> new(-file =>'>temp1',-format=>'fasta');
my $hairpin_seq = Bio::Seq-> new(-seq => $hairpin_sequence,
-display_id=>$hit_name);
$seqio->write_seq($hairpin_seq);

system (" mfold SEQ='temp1'");
open( my $rpt,'>', 'temp1.out') or die("Can't open temp1.out: $!");
print $OUTPUT "Hit Name-$hit_name\tSequence name-$id\n";
while(<$rpt>) {
print $OUTPUT;
}
close($rpt) or die $! ;
}
close ($OUTPUT) or die $!;

__DATA__
Query Name (Start,End) Hit Name (Start,End) Sequence
012971 (119,132) fru-mir-137 (42,55) ATGGTTAAAGTACATATAAAAACAATGATT
012971 (119,132) dre-mir-137-2 (72,85) ATGGTTAAAGTACATATAAAAACAAT
012971 (119,132) dre-mir-137-1 (48,61) ATGGTTAAAGTACATATAAAAACAAT
012971 (119,132) gga-mir-137 (51,64) ATGGTTAAAGTACATATAAAAACAATGATT
012971 (119,132) rno-mir-137 (56,69) ATGGTTAAAGTACATATAAAAACAATGATT
012971 (119,132) hsa-mir-137 (56,69) ATGGTTAAAGTACATATAAAAACAATGATT
012971 (119,132) mmu-mir-137 (42,55) ATGGTTAAAGTACATATAAA
Here is Program with your advice.Just help me one more time ,I will
really appriciated that
thay why my this program doesn't storing the output from <rpt>.i think
i am using '>' wrong mode but i tried '<','<<','<+'.but noone is
working.
Thanks
 
C

Ch Lamprecht

Rita said:
system (" mfold SEQ='temp1'");
open( my $rpt,'>', 'temp1.out') or die("Can't open temp1.out: $!");
print $OUTPUT "Hit Name-$hit_name\tSequence name-$id\n";
while(<$rpt>) {
print $OUTPUT;
}
close($rpt) or die $! ;
}

perldoc -f open
..
..
..
If three or more arguments are specified then the mode of
opening and the file name are separate. If MODE is '<' or
nothing, the file is opened for input. If MODE is '>', the file
is truncated and opened for output, being created if necessary.


HTH
Christoph
 
J

J. Gleixner

Rita wrote:
[...]
system (" mfold SEQ='temp1'");
open( my $rpt,'>', 'temp1.out') or die("Can't open temp1.out: $!");
print $OUTPUT "Hit Name-$hit_name\tSequence name-$id\n";
while(<$rpt>) {
print $OUTPUT;
}
close($rpt) or die $! ;
}
close ($OUTPUT) or die $!;
thay why my this program doesn't storing the output from <rpt>.i think
i am using '>' wrong mode but i tried '<','<<','<+'.but noone is
working.

Read the documentation, instead of just trying various characters.

perldoc -f open
perldoc perlopentut

I'm guessing, but possibly you want to put the output of mfold into
temp1.out?? If so:

open( my $rpt,'>', 'temp1.out')
or die"Can't open temp1.out: $!";
open( my $mfold, "mfold SEQ='temp1' |" )
or die "Can't run mfold SEQ=temp1: $!";
while( <$mfold> )
{
print $rpt;
}
close( $rpt );
close( $mfold );

Could also simply redirect the output, using system().

# the single quote probably isn't needed...
system( "mfold SEQ='temp1' > temp1.out" ) == 0
or die "Running mfold SEQ='temp1' > temp1.out failed: $?";

If you need to check for errors, then take a look at: IPC::Open3.
 
R

Rita

J. Gleixner said:
Rita wrote:
[...]
system (" mfold SEQ='temp1'");
open( my $rpt,'>', 'temp1.out') or die("Can't open temp1.out: $!");
print $OUTPUT "Hit Name-$hit_name\tSequence name-$id\n";
while(<$rpt>) {
print $OUTPUT;
}
close($rpt) or die $! ;
}
close ($OUTPUT) or die $!;
thay why my this program doesn't storing the output from <rpt>.i think
i am using '>' wrong mode but i tried '<','<<','<+'.but noone is
working.

Read the documentation, instead of just trying various characters.

perldoc -f open
perldoc perlopentut

I'm guessing, but possibly you want to put the output of mfold into
temp1.out?? If so:

No, I want to put the Value of temp1 in outputfile in result.out
everytime when loop works.
Thanks
 
J

J. Gleixner

Rita said:
J. Gleixner said:
Rita wrote:
[...]
system (" mfold SEQ='temp1'");
open( my $rpt,'>', 'temp1.out') or die("Can't open temp1.out: $!");
print $OUTPUT "Hit Name-$hit_name\tSequence name-$id\n";
while(<$rpt>) {
print $OUTPUT;
}
close($rpt) or die $! ;
}
close ($OUTPUT) or die $!;
thay why my this program doesn't storing the output from <rpt>.i think
i am using '>' wrong mode but i tried '<','<<','<+'.but noone is
working.
Read the documentation, instead of just trying various characters.

perldoc -f open
perldoc perlopentut

I'm guessing, but possibly you want to put the output of mfold into
temp1.out?? If so:

No, I want to put the Value of temp1 in outputfile in result.out
everytime when loop works.

Sorry. but templ doesn't have a value. Where do you assign the value of
templ?

Is templ.out a file and you want its contents written to result.out?

open( my $rpt,'<', 'temp1.out') or die "Can't open temp1.out: $!";
print $OUTPUT "Hit Name-$hit_name\tSequence name-$id\n";
while(<$rpt>) {
print $OUTPUT;
}
close($rpt) or die "Can't close templ.out: $!";
 
R

Rita

J. Gleixner said:
Rita said:
J. Gleixner said:
Rita wrote:
[...]

Is templ.out a file and you want its contents written to result.out?
yes,But It is in loop so every time temp1.out has diffrent output and
i want to store all the output in 'result.out'.
open( my $rpt,'<', 'temp1.out') or die "Can't open temp1.out: $!";
print $OUTPUT "Hit Name-$hit_name\tSequence name-$id\n";
while(<$rpt>) {
print $OUTPUT;
}
close($rpt) or die "Can't close templ.out: $!";
Thanks,But i alredy tried it.it is not working.in output file i am
getting output from this line
print $OUTPUT "Hit Name-$hit_name\tSequence name-$id\n";
But not of this line.

print $OUTPUT;
 
C

Ch Lamprecht

yes,But It is in loop so every time temp1.out has diffrent output and
i want to store all the output in 'result.out'.


use strict;
use warnings;

my $outputfile = 'result.out';
open my $OUTPUT, '>', $outputfile or die "Can't open \"$outputfile\"
$!";
open( my $rpt,'<', 'temp1.out') or die "Can't open temp1.out: $!";
print $OUTPUT "Hit Name- \tSequence name- \n";
while(<$rpt>) {
print $OUTPUT;
}
close($rpt) or die "Can't close templ.out: $!";


Hi Rita,

do you want to try the lines above ? Would you first check the content
of temp1.out to make sure there is something to read.

earlier in the thread:
oops,sorry i just saw my mistake .actually the problam is I am working
on linux system so I correct the program there and forgate to change in
windows one.

Maybe you'd better have samba installed...


Christoph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top