-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcatSeqs.pl
executable file
·65 lines (49 loc) · 1.16 KB
/
concatSeqs.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
61
62
63
64
65
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std;
use File::Spec;
my %opts;
getopts('d:h',\%opts);
&varcheck;
opendir(my $dh, $opts{'d'}) || die "Can't open directory";
while (my $filename = readdir $dh) {
next if $filename =~ /read/i;
next if $filename !~ /\.txt$/;
my $defline = $filename;
$defline =~ s/\.txt//;
my $seq = "";
open(my $fh,File::Spec->catfile($opts{'d'},$filename));
foreach my $line (<$fh>) {
next if $line =~ /^\s*#/;
chomp $line;
next if $line =~/^\s+$/;
$line =~ s/[\s\t\d]//g;
$seq .= $line;
}
print ">$defline\n$seq\n";
}
closedir $dh;
sub varcheck {
&usage if ($opts{'h'});
my $errors = "";
if (!$opts{'d'}){
$errors .= "You have not provided a value for the -d flag\n";
}
elsif(!(-d $opts{'d'})) {
$errors .= "Can't open $opts{'d'}\n";
}
if ($errors ne "") {
print "\n$errors";
&usage;
}
}
sub usage{
my $scriptName = $0;
$scriptName =~ s/\/?.*\///;
print "\nusage: perl $scriptName <-f file>\n";
print <<PRINTTHIS;
Concatenates individual sequence files that are in non-fasta format. The title of the file will be used for the seqeunce definition.
PRINTTHIS
exit;
}