-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbam_scaffolding.stats.pl
executable file
·41 lines (32 loc) · 1.32 KB
/
bam_scaffolding.stats.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
#!/usr/bin/env perl
use strict;
use warnings;
use Bio::DB::Sam;
use constant USAGE =><<EOH;
usage: $0 file.bam reference.fasta out.file
Evaluate BAM files before scaffolding
v20160919
EOH
die USAGE if (scalar(@ARGV) !=3 or $ARGV[0] eq '-h' or $ARGV[0] eq '--help');
die "Error: invalid BAM/SAM file\n" unless (defined $ARGV[0] and -s $ARGV[0]);
die "Error: invalid reference.fasta file\n" unless (defined $ARGV[1] and -s $ARGV[1]);
die "Error: invalid out.file\n" unless (defined $ARGV[2] and $ARGV[2]=~/^\S+$/);
die "Error: out.file existed: $ARGV[2]\n" if (-e $ARGV[2]);
my $bamobj=Bio::DB::Sam -> new (-bam => "$ARGV[0]", -fasta => "$ARGV[1]");
my @seqids=$bamobj->seq_ids;
open (OUTPUT, "> $ARGV[2]") || die "Error: can not write out.file\n";
foreach my $seq (@seqids) {
my @alignment=$bamobj->get_features_by_location(-seq_id => "$seq");
foreach my $idvalign (@alignment) {
my $query_name=$idvalign->name;
my $query_start = $idvalign->query->start;
my $query_end = $idvalign->query->end;
my $seqid = $idvalign->seq_id;
my $start = $idvalign->start;
my $end = $idvalign->end;
my $strand = $idvalign->strand;
my $cigar = $idvalign->cigar_str;
print OUTPUT $query_name, "\t", $query_start, "\t", $query_end, "\t", $seqid, "\t", $start, "\t", $end, "\t", $strand, "\t", $cigar, "\n";
}
}
close OUTPUT;