-
Notifications
You must be signed in to change notification settings - Fork 2
/
bioperlIt.pl
51 lines (37 loc) · 918 Bytes
/
bioperlIt.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
#!/usr/bin/env perl
use strict;
use warnings;
use Bio::SeqIO;
use Bio::Seq;
use Getopt::Long;
my $inFile = "humanFasta.withReference.fa";
my $outFile = "humans.fa";
GetOptions('i=s' => \$inFile,
'o=s' => \$outFile);
if (-f $outFile && -s $outFile) {
die "$outFile exists. Not gonna clobber it!\n";
}
open(FOO, $inFile);
my %seqs;
my $id;
while (<FOO>) {
$_ =~ s/\s+//g;
if (substr($_, 0, 1) eq '>') {
$id = substr($_, 1);
$id =~ s/\s+//g;
} else {
my $s = $_;
$s =~ s/[^GATC]//g;
if ($s ne '') {
$seqs{$id} .= $_;
}
}
}
my $out = Bio::SeqIO->new(-file => ">$outFile", format=>'FASTA');
#while (my $seq = $seqio_object->next_seq() ) {
foreach (keys %seqs) {
my $seq = Bio::Seq->new( -display_id => $_,
-seq => $seqs{$_});
$out->write_seq($seq);
}
$out->close();