Question: Fastq to Fasta file
0
gravatar for joseantonio271196
2.2 years ago by
joseantonio2711960 wrote:

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;
windows fastq perl fasta • 1.1k views
ADD COMMENTlink modified 2.2 years ago by Daniel3.7k • written 2.2 years ago by joseantonio2711960
1

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 REPLYlink written 2.2 years ago by WouterDeCoster36k

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 REPLYlink written 2.2 years ago by joseantonio2711960

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 REPLYlink written 2.2 years ago by Daniel3.7k

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

ADD REPLYlink written 2.2 years ago by WouterDeCoster36k

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 REPLYlink modified 2.2 years ago • written 2.2 years ago by mastal5112.0k

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

ADD REPLYlink written 2.2 years ago by venu5.8k
1
gravatar for Daniel
2.2 years ago by
Daniel3.7k
Cardiff University
Daniel3.7k wrote:

[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 COMMENTlink modified 2.2 years ago • written 2.2 years ago by Daniel3.7k
0
gravatar for Macspider
2.2 years ago by
Macspider2.7k
Vienna - BOKU
Macspider2.7k wrote:

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 COMMENTlink modified 2.2 years ago • written 2.2 years ago by Macspider2.7k
3

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 REPLYlink written 2.2 years ago by genomax62k

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 REPLYlink written 2.2 years ago by joseantonio2711960
0
gravatar for joseantonio271196
2.2 years ago by
joseantonio2711960 wrote:

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 COMMENTlink modified 2.2 years ago by genomax62k • written 2.2 years ago by joseantonio2711960

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 REPLYlink written 2.2 years ago by Tonor420

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 REPLYlink modified 2.2 years ago • written 2.2 years ago by Daniel3.7k
0
gravatar for mastal511
2.2 years ago by
mastal5112.0k
mastal5112.0k wrote:

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 COMMENTlink written 2.2 years ago by mastal5112.0k

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 REPLYlink written 2.2 years ago by joseantonio2711960
1

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 REPLYlink modified 2.2 years ago • written 2.2 years ago by mastal5112.0k

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 REPLYlink modified 2.2 years ago • written 2.2 years ago by Tonor420
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 817 users visited in the last hour