-
Notifications
You must be signed in to change notification settings - Fork 7
/
fasta_oneliner.pl
executable file
·60 lines (50 loc) · 1.18 KB
/
fasta_oneliner.pl
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
54
55
56
57
58
59
60
#!/usr/bin/perl
## Pombert Lab 2020
my $version = '0.2a';
my $name = 'fasta_oneliner.pl';
my $updated = '2021-04-21';
use strict;
use warnings;
use Getopt::Long qw(GetOptions);
use File::Basename;
## Usage definition
my $USAGE = <<"OPTIONS";
NAME ${name}
VERSION ${version}
UPDATED ${updated}
SYNOPSIS Convert FASTA sequences into single string FASTA
COMMAND ${name} \\
-f *.fasta \\
-o FASTA_OL
OPTIONS:
-f (--fasta) FASTA files to convert
-o (--output) Output folder [Default = FASTA_OL]
OPTIONS
die "\n$USAGE\n" unless @ARGV;
## Defining options
my @fasta;
my $out = "FASTA_OL";
GetOptions(
'f|fasta=s@{1,}' => \@fasta,
'o|output=s' => \$out,
);
## Checking output directory
unless (-d $out){
mkdir ($out,0755) or die "Can't create folder $out: $!\n";
}
## Converting fasta files
while (my $fasta = shift@fasta){
open FASTA, "<", "$fasta" or die "Can't open $fasta: $!\n";
my($name, $dir) = fileparse($fasta);
my $header;
my $seq;
while (my $line = <FASTA>){
chomp $line;
if ($line =~ /^>/){ $header = $line; }
else{ $seq .= $line; }
}
open OUT, ">", "$out/$name" or die "Can't create $out/$name: $!\n";;
print OUT "$header\n"."$seq\n";
close FASTA;
close OUT;
}