-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_bac_locations_from_mummer_coords.pl
executable file
·164 lines (136 loc) · 5.06 KB
/
get_bac_locations_from_mummer_coords.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/perl
=head1
get_bac_locatons_from_mummer_coords.pl
=head1 SYNOPSIS
get_bac_locatons_from_mummer_coords.pl -i [MUMmer show-coords file]
=head1 COMMAND-LINE OPTIONS
-i MUMmer show-coords file
-h Help
=cut
use strict;
use File::Slurp;
use Getopt::Std;
use Getopt::Std;
our ($opt_i, $opt_h);
getopts('i:h');
if ($opt_h){
help();
exit;
}
if (!$opt_i) {
print "\nMUMmer show-coords filename is required\n\n\n";
help();
}
my $input_file = $opt_i;
my $input_coords_contents = read_file($input_file) or die "Could not open show-coords input file: $input_file\n";
my @input_lines;
my %query_sequences;
@input_lines = split (/\n/, $input_coords_contents);
foreach my $line (@input_lines) {
chomp($line);
my @coord_line_array = split(/\t/,$line);
if ((!$coord_line_array[14]) || $coord_line_array[0] =~ /\D/) {
next;
}
my $reference_name = $coord_line_array[13];
my $query_name = $coord_line_array[14];
my $reference_start = $coord_line_array[0];
my $reference_end = $coord_line_array[1];
my $query_start = $coord_line_array[2];
my $query_end = $coord_line_array[3];
my $reference_alignment_length = $coord_line_array[4];
my $query_alignment_length = $coord_line_array[5];
my $percent_identity = $coord_line_array[6];
my $reference_length = $coord_line_array[7];
my $query_length = $coord_line_array[8];
my $query_orientation = $coord_line_array[12];
if ($query_sequences{$query_name}) {
if ($query_orientation eq 1) {
if ($reference_start < $query_sequences{$query_name}{'end'}){
$query_sequences{$query_name}{'alignment_overlaps'} = 1;
}
}
else {
if ($reference_end < $query_sequences{$query_name}{'end'}){
$query_sequences{$query_name}{'alignment_overlaps'} = 1;
}
}
if ($reference_start < $query_sequences{$query_name}{'start'}) {
$query_sequences{$query_name}{'start'} = $reference_start;
}
if ($reference_end > $query_sequences{$query_name}{'end'}) {
$query_sequences{$query_name}{'end'} = $reference_end;
}
if (!$query_orientation == $query_sequences{$query_name}{'orientation'}) {
$query_sequences{$query_name}{'mixed_orientations'} = 1;
}
$query_sequences{$query_name}{'length'} += $reference_alignment_length;
}
else {
my %query_info;
$query_info{'reference_name'} = $reference_name;
$query_info{'start'} = $reference_start;
$query_info{'end'} = $reference_end;
$query_info{'orientation'} = $query_orientation;
$query_info{'mixed_orientations'} = 0;
$query_info{'length'} = $reference_alignment_length;
$query_info{'aligns_to_beginning'} = 0;
$query_info{'aligns_to_end'} = 0;
$query_info{'query_length'} = $query_length;
$query_info{'alignment_overlaps'} = 0;
$query_sequences{$query_name} = {%query_info};
}
if ($query_start == 1 || $query_end == 1) {
$query_sequences{$query_name}{'aligns_to_beginning'} = 1;
}
if ($query_start == $query_length || $query_end == $query_length) {
$query_sequences{$query_name}{'aligns_to_end'} = 1;
}
}
# for my $query_name ( keys %query_sequences ) {
# print $query_sequences{$query_name}{'reference_name'}."\t";
# print $query_sequences{$query_name}{'start'}."\t";
# print $query_sequences{$query_name}{'end'}."\t";
# print $query_sequences{$query_name}{'length'}."\t";
# print $query_name."\t";
# print $query_sequences{$query_name}{'orientation'}."\t";
# print $query_sequences{$query_name}{'mixed_orientations'}."\t";
# print $query_sequences{$query_name}{'aligns_to_beginning'}."\t";
# print $query_sequences{$query_name}{'aligns_to_end'}."\t";
# print $query_sequences{$query_name}{'alignment_overlaps'}."\n";
# }
#foreach my $key ( #
# sort { $hash{$a}->{Make} cmp $hash{$b}->{Make} } #
# keys %hash
# )
foreach my $query_name ( sort {$query_sequences{$a}->{'reference_name'} cmp $query_sequences{$b}->{'reference_name'} ||
$query_sequences{$a}->{'start'} <=> $query_sequences{$b}->{'start'}} keys %query_sequences) {
print $query_sequences{$query_name}{'reference_name'}."\t";
print $query_sequences{$query_name}{'start'}."\t";
print $query_sequences{$query_name}{'end'}."\t";
print $query_sequences{$query_name}{'length'}."\t";
print $query_name."\t";
print $query_sequences{$query_name}{'orientation'}."\t";
print $query_sequences{$query_name}{'mixed_orientations'}."\t";
print $query_sequences{$query_name}{'aligns_to_beginning'}."\t";
print $query_sequences{$query_name}{'aligns_to_end'}."\t";
print $query_sequences{$query_name}{'alignment_overlaps'}."\n";
}
sub help {
print STDERR <<EOF;
$0:
Description:
This script reads coordinates of BACs aligned to a genome from a MUMmer show-coords file and determines start and end positions and does filtering for low quality/aberrant alignments.
Usage:
get_bac_locatons_from_mummer_coords.pl -i [MUMmer show-coords file]
Flags:
-i <show-coords file> MUMmer show-coords file (mandatory)
-h <help> Help
EOF
exit (1);
}
=head1 LICENSE
Same as Perl.
=head1 AUTHORS
Jeremy D. Edwards <[email protected]>
=cut