-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsplitMultiFasta.pl
More file actions
executable file
·53 lines (37 loc) · 1.19 KB
/
Copy pathsplitMultiFasta.pl
File metadata and controls
executable file
·53 lines (37 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl
=head1 NAME
splitMultiFasta.pl - splits a single multifasta file into multiple singlefasta files
=head1 USAGE
splitMultiFasta.pl -i|--multifasta <multifasta> -o|--outdir <outdir>
=head1 DESCRIPTION
Splits a single multifasta file into multiple singlefasta files.
Concatenates fasta id and fasta description with _
Also converts any / into _ in id or description
=head1 AUTHOR
Joran Martijn (joran.martijn@icm.uu.se)
=cut
use strict;
use warnings;
use Getopt::Long;
use Bio::SeqIO;
use Pod::Usage;
my ($multifasta,$outdir);
GetOptions("i|multifasta=s" => \$multifasta,
"o|outdir=s" => \$outdir,
);
pod2usage (-msg => "Not enough arguments") unless $outdir && $multifasta;
my $in = Bio::SeqIO->new(-format => 'fasta',
-file => $multifasta);
while (my $seq = $in->next_seq) {
# retrieve seqname
my $id = $seq->id;
my $desc = $seq->desc;
# make filename
my $singlefasta = $id . '_' . $desc . '.fasta';
$singlefasta =~ s/[\s+\/]/_/g;
print $singlefasta, "\n";
# make outfile
my $out = Bio::SeqIO->new(-format => 'fasta',
-file => ">$outdir/$singlefasta");
$out->write_seq($seq);
}