As the title, I am trying to Extract Cds Fastas From A Gff Annotation ,please tell me where I was wrong .
Here is my code.
#!/usr/bin/perl-w
use strict;
use warnings;
my $fasta_file = "/Users/huli/Documents/IRGSP-1.0_genome.fasta";
my $gff_file = "/Users/huli/Documents/IRGSP-1.0_representative_2015-03-31/transcripts_output.gff";
my $outputfile = "/Users/huli/Documents/IRGSP-1.0_representative_2015-03-31/fasta_outputfile.fasta";
open (FASTA,"<", $fasta_file) or die "$!";
open (GFF,"<", $gff_file) or die "$!";
open (OUT,">", $outputfile) or die "$!";
my @array1 = $fasta_file; # useless assignment of scalar to array
my @array2 = $gff_file; # did you mean @array = <FASTA> ?
my %hash;
while(@array1 = <FASTA>){ # wrong combined use of iterator + while and # array context of <>
chomp;
if (/>/){
my $_ = my $key; # mask $_ ?? now $_ is undef
$key =~ s/>/ /g;
}else{
$hash{my $key} .= $_;
}
}
while (@array2 = <GFF>){
chomp;
@array2 = split("\t", $_);
my $temp = substr($hash{$array2[0]}, $array2[3]-1, $array2[4]-$array2[3]);
print OUT ">$array2[8]\n $temp\n";
}
close FASTA;
close GFF;
close OUT;
I highlighted some obvious mistakes, you'll have gotten some warnings about redefined variables. Based on these mistakes, your codes does nothing most likely.
Thanks for your commend, I will amend my codes.
If you paste the error that are you getting we could help you easily :)
well, there are to many errors here, it just a little hard to paste.
Do you really need this? I think defining as
my @array1; my @array2;
is enough there. Be cause you are using FH in while loop. or modify these two lines toand in while loop use simple
while(@array1)
and so.Thank you a lot , I think I just get something in my brain, thank you so much.
Well, I amended my code, and here it is:
and here are the errors:
I just learned perl for a short time, so when you guys give me answer, please give me some detailed answer. Thanks for your help. And could you tell me it is a right way to write a hash like me do?
Try to define
$key
variable outside the loop (my $key;
), and then$key = $_
.And just a suggestion, for working with biological data, I would give a try to
BioPerl
, it has the most suitable modules for this kind of scripts.Thanks for your answers,here are my new codes, and errors .
This is a part of my errors, I know I need amend 22 lines, this line
$hash{$key} .= $_;
but I don't know how to amend it. I hope your guys can help me, thanks a lot.