-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSeqFile.pm
99 lines (94 loc) · 2.04 KB
/
SeqFile.pm
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package SeqFile;
use strict;
use warnings;
use Bio::SeqIO;
use Getopt::Long qw(GetOptionsFromString);
sub new{
my $class = shift;
my $self = shift;
bless $self,$class;
$self->Chunk;
#if(!$self->{'chunk'}){
# my $f = join(".",$self->{'prefix'},0,$self->{'format'});
# Copy($self->{'file'},$f);
# push(@{$self->{'files'}},$f);
#}
return $self;
}
sub Chunk{
my $self = shift;
my $seqI = new Bio::SeqIO(-file => $self->{'file'}, -format => $self->{'format'});
my $count = 0;
my $seqO;
my @files;
my $seq;
if($self->{'chunk'} == 0){
my $f = join(".",$self->{'prefix'},$count,$self->{'format'});
$seqO = new Bio::SeqIO(-file => ">$f", -format => 'fasta');
push(@files,$f);
}
for(my $i = 0; $seq = $seqI->next_seq; $i++){
if($self->{'chunk'} != 0 && (($i % ($self->{'chunk'})) == 0)){
my $file = join(".",$self->{'prefix'},$count,$self->{'format'});
$count++;
push(@files,$file);
$seqO = new Bio::SeqIO(-file => ">$file", -format => 'fasta');
}
$seqO->write_seq($seq);
}
$seqO = '';
$seqI = '';
$self->{'files'} = \@files;
}
sub GetFileCount{
my $self = shift;
return scalar @{$self->{'files'}};
}
sub GetFiles{
my $self = shift;
return @{$self->{'files'}};
}
sub FilterSeqs{
my $self = shift;
my $i = shift;
my $filter = shift;
my $seqI = new Bio::SeqIO(-file => $self->{'files'}[$i], -format => 'fasta');
my $seqO = new Bio::SeqIO(-file => ">".$self->{'files'}[$i].".temp",-format => 'fasta');
while(my $seq = $seqI->next_seq){
$seqO->write_seq($seq) if !$filter->{$seq->id};
}
$seqO = '';
$seqI = '';
$self->Overwrite($self->{'files'}[$i].".temp",$self->{'files'}[$i]);
}
sub Overwrite{
my $self = shift;
my $cmd;
if($^O eq 'MSWin32'){
$cmd = join(' ','move',@_);
}
else{
$cmd = join(' ','mv',@_);
}
`$cmd`;
}
sub PrintParams{
my $self = shift;
foreach my $k (keys %{$self}){
print join "\t", $k, $self->{$k},$/;
}
}
sub Copy{
my $cmd;
if($^O eq 'MSWin32'){
$cmd = join(' ','copy',@_);
}
else{
$cmd = join(' ','cp',@_);
}
`$cmd`;
}
1;
=cut
Functions as fasta handler and parser
=cut