Hey guys, I need to use perl to turn a fastq file to a fasta file. I'm using Padre (Perl) and Windows 10. I cannot use Bioperl or any other crazy stuff, gotta stick with Padre. So far I have this code. But I am stuck, any ideas? Up to print and before while-> chomp, etc. I could get it to work in the command line, but now it doesn't.
#!/usr/bin/perl
use warnings;
($file)=@ARGV;
$file = reading($file);
print $file;
sub reading {
my $jose= shift @_;
print "this is ", $jose, "\n";
open(my $arriba, "<", $jose) or die "xxx you $jose is xxx!\n";
print <$arriba>;
print "\n";
while ($jose = <$arriba>) {
chomp;
if ($line =~ /^\s*$/){
elsif ($line =~ /^\s*@/){
elsif ($line =~ /^+/){
next;
}
}
print $file;
Trying to do just that, but I'm kinda stuck there and been stuck there for a few hours now. I'm not expecting someone to just write the script for me, but make some useful comments as to how I might proceed.
You've created a subroutine, but not closed it, and then you've never actually called it. And then also, you've not closed your if{} statements. What are you using to write your program in? Most code editors will highlight open brackets that aren't closed. vim is good on the command line, but https://atom.io/ is pretty good as a whole environment. Check that out and it should help you see.
In addition to 'use warnings;' you should also be using 'use strict;'
Your code as it is should be giving error messages about unmatched curly {,
because you haven't written closing } for any of the clauses in your if elsif statements.
You have too many variables called $file;
If you want to be able to tell which lines in your script aren't working as you intended, it would be more
helpful to have the results of different steps assigned to variables with different names.
Your line ($jose = <$arriba>) should probably be (my $line=<$arriba>).
Regarding your updated script, you have to read the whole error. If I run the script you've put here this is what I get:
daniel-desktop:~/Projects/temp$ ./temp.pl
syntax error at ./temp.pl line 18, near ")
chomp"
syntax error at ./temp.pl line 20, near ")
else"
Unmatched right curly bracket at ./temp.pl line 23, at end of line
Unmatched right curly bracket at ./temp.pl line 24, at end of line
Execution of ./temp.pl aborted due to compilation errors.
So the first step is to fix those things. To do this, read up on how while loop and if statements are supposed to look, because you're not doing it right and missing tonnes of structure i.e. brackets. Basically what you want is:
Since it looks like homework, we won't help you haha :D
Just joking. But check out your curly brackets, you might find something missing. ;)
Also, as Daniel wrote in the comments, you didn't call the subroutine!
Learn how to work in Vi, or in some highlighting text editor. If you open the file in Vi and there type:
ESC + :setf perl
you will see the highlight in the text which will help you closing brackets when you don't. It's not cheating, the longer the code the more helpful this gets.
P.S. and remember to remove the F-words before handing it out to the teacher!
I think I made most of the changes you suggested making sure about the brackets but it still tells me "aborted due to compilation errors. Kinda going crazy here.
#!/usr/bin/perl
use warnings;
use strict;
my $file =@ARGV;
$file = reading($file);
print $file;
sub reading {
my $jose= shift @_;
print "this is ", $jose, "\n";
open(my $arriba, "<", $jose) or die "xxx you $jose is xxx!\n";
print <$arriba>;
print "\n";
}
while (my $line)
chomp;
if ($line == /^\s*$/)
else ($line = /^\s*@/)
else ($line = /^+/)
next;
}
}
print $file;
You should be getting more specific error messages, such as what lines different errors are on.
Starting with the beginning of your code, 'my $file = @ARGV;' You are calling an array in scalar context.
Put a print statement 'print $file;' immediately after this step, to see whether this code is giving you the result you wanted or not.
Yeah, I'm getting two syntax errors (lines 17 and 19) and two unmatched right curly brackets (lines 21 and 22) at the end of the line. But, everytime I try fixing them, I just keep getting errors in some other line.
That's the way debugging your code goes. You keep fixing errors until it all works fine.
You have a problem with the syntax of the if else statements. Each of the clauses should have a pair of curly { open and close braces, even if you still haven't thought of what code to put inside the braces;
And in perl it's if/elsif/else, you can have more than one elsif condition, but you can only have one else as part of the same if/else block.
where is sub_reading supposed to end? at the moment it is before the while
$line? doesn't seem to have any value/input
I think you should start off simply trying to open a file, and output it to another file. When that works, then start deciding what lines you want to output.
That suggests this is a homework question? If so, homework has the objective to make you think and learn...
Trying to do just that, but I'm kinda stuck there and been stuck there for a few hours now. I'm not expecting someone to just write the script for me, but make some useful comments as to how I might proceed.
You've created a subroutine, but not closed it, and then you've never actually called it. And then also, you've not closed your if{} statements. What are you using to write your program in? Most code editors will highlight open brackets that aren't closed. vim is good on the command line, but https://atom.io/ is pretty good as a whole environment. Check that out and it should help you see.
For Windows, Notepad++ and Sublime Text are pretty nice editors.
In addition to 'use warnings;' you should also be using 'use strict;'
Your code as it is should be giving error messages about unmatched curly {, because you haven't written closing } for any of the clauses in your if elsif statements.
You have too many variables called $file; If you want to be able to tell which lines in your script aren't working as you intended, it would be more helpful to have the results of different steps assigned to variables with different names.
Your line ($jose = <$arriba>) should probably be (my $line=<$arriba>).
FYI, there is already a perl script to do this, check it out here