-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfilter_loci.pl
More file actions
executable file
·83 lines (60 loc) · 1.8 KB
/
filter_loci.pl
File metadata and controls
executable file
·83 lines (60 loc) · 1.8 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use File::Path;
use File::Copy;
use File::Basename;
my @DIR;
my $cutoff;
my $N;
my $blacklist=0;
my @contents;
parseArgs();
#Use File::Basename to capture some info
my ($filepath, $dirpath) = fileparse( $DIR[0] );
#If user toggled "blacklist loci" on, then some configuration...
$blacklist =~ "1" and my $bname = "blacklist";
$blacklist =~ "1" and rmtree "$dirpath/$bname";
$blacklist =~ "1" and mkdir "$dirpath/$bname";
#Iterate through files
@DIR = glob "@DIR";
foreach my $file (@DIR){
$N=0;
@contents="";
open (FILE, "$file");
while (<FILE>){
chomp $_;
push @contents, $_;
}
$N +=()= "@contents" =~ /\>/g;
if ( $blacklist eq "1"){
if ( $N < $cutoff ){
move("$file","$dirpath/$bname/");
}
}else{
if ( $N < $cutoff ){
unlink "$file";
}
}
close FILE;
}
##############################################SUBROUTINES###########################################
sub parseArgs{
my $usage="\nfilter_loci.pl takes a directory full of fasta files, each representing a single locus, and deletes any loci with insufficient coverage across samples, using a user-specified cut off value.
Usage: $0 --i=/path/to/*.fasta --x=# [--b]
Mandatory Variables
-i, --input - Path to fasta files
-x, --cutoff - Integer indicating the minimum number of samples to retain a locus
Options
-b, --blacklist - Retain dropped loci in a blacklisted_loci directory
";
my $results = GetOptions
(
'input|i=s{1,}' => \@DIR,
'cutoff|x=i' => \$cutoff,
'blacklist|b!' => \$blacklist,
);
@DIR or die "\nDerp: Input directory not defined!\n\n$usage";
$cutoff or die "\nDerp: Minimum coverage required to retain a locus not defined!\n\n$usage";
}