Fastq to Fasta file
4
0
Entering edit mode
8.0 years ago

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;
fasta fastq perl windows • 2.9k views
ADD COMMENT
1
Entering edit mode

I need to use perl to turn a fastq file to a fasta file.(...) I cannot use Bioperl or any other crazy stuff, gotta stick with Padre.

That suggests this is a homework question? If so, homework has the objective to make you think and learn...

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

For Windows, Notepad++ and Sublime Text are pretty nice editors.

ADD REPLY
0
Entering edit mode

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>).

ADD REPLY
0
Entering edit mode

FYI, there is already a perl script to do this, check it out here

ADD REPLY
1
Entering edit mode
8.0 years ago
Daniel ★ 4.0k

[Answer instead of comment because of length]

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:

while (a < b) {
    something
}

and

if (a < b){
    something
}else{
    somethingelse
}
ADD COMMENT
0
Entering edit mode
8.0 years ago

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!

ADD COMMENT
3
Entering edit mode

P.S. and remember to remove the F-words before handing it out to the teacher!

There is no need for them on Biostars either.

ADD REPLY
0
Entering edit mode

Thanks for all the help. Will try and get back to you all. I actually think our teacher will find it quite funny and he won't mind! Hahaha

ADD REPLY
0
Entering edit mode
8.0 years ago

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;
ADD COMMENT
0
Entering edit mode

Best to use tabs to indent your code - that way you can see where you have a missing or an extra bracket

Also - if else else?

ADD REPLY
0
Entering edit mode

check my answer here: A: Fastq to Fasta file

And note that it's better to update your original question than put an update as an answer because people won't see it.

ADD REPLY
0
Entering edit mode
8.0 years ago
mastal511 ★ 2.1k

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.

ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
1
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

if else else?

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.

Perl open and read file: https://perlmaven.com/open-and-read-from-files

ADD REPLY

Login before adding your answer.

Traffic: 2314 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6