Question: Split and store fasta sequences in a specific directory (Perl)
0
gravatar for Damian_Civ
8 months ago by
Damian_Civ0
Damian_Civ0 wrote:

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!!

ADD COMMENTlink modified 8 months ago by finswimmer12k • written 8 months ago by Damian_Civ0
3
gravatar for finswimmer
8 months ago by
finswimmer12k
Germany
finswimmer12k wrote:

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 COMMENTlink written 8 months ago by finswimmer12k

Thank you very much. A simple and effective solution

ADD REPLYlink written 8 months ago by Damian_Civ0
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: 1043 users visited in the last hour