Split and store fasta sequences in a specific directory (Perl)
1
0
Entering edit mode
6.0 years ago
Damian_Civ • 0

Hello all, I would like to know whether there is a way to split a multi fasta file into several individual files and store all of them in one specific folder using IO::File, IO::File::WithPath; and Bio::SeqIO from Perl. I was trying to do it and I achieved split the multi fasta file into several files according to the sequences number, but I didn't get store all of them in a specific folder. All of them are stored directly at the path where I run the script. Am I doing something wrong with the command lines or maybe I need to use another module?

use IO::File::WithPath;
use Bio::SeqIO;

my $io = IO::File->new('path_new_folder_to_store_fasta_sequences', '>:utf8');
my $infile = "path_fasta_file";

my $seq_in = Bio::SeqIO->new( -file   => $infile, -format => "fasta", );

while (my $inseq = $seq_in->next_seq) {

my $id = $inseq->id();
my $seq = $inseq->seq();

$io  = IO::File->new(">$id.fasta");
print $io ">$id\n$seq\n";

}

Thanks in advance!

fasta IO_File Bio_SeqIO Perl • 1.4k views
ADD COMMENT
3
Entering edit mode
6.0 years ago

You define your outputfile with this line:

$io  = IO::File->new(">$id.fasta");

Add your folder name right before the filename should work.

fin swimmer

ADD COMMENT
0
Entering edit mode

Thank you very much. A simple and effective solution

ADD REPLY

Login before adding your answer.

Traffic: 1184 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