blib/script/show-align2clustalw.pl untested

filter: Statementstmt 0.0% 0 / 71 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 11 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 112 CC 6 SCAR 28.9
CC
6
Cov
0%
parse_alignment
42.0
next_aln
2.0
BEGIN
2.0
CRAP 18.0
1 #!/usr/bin/env perl
2  
3 use warnings;
4 use strict;
5  
6 use Carp;
7 use Getopt::Long;
8 use Pod::Usage;
9  
10 use Bio::SimpleAlign;
11 use Bio::LocatableSeq;
12 use Bio::AlignIO;
13  
14 my %a;
15 GetOptions( \%a, 'help|h|?', ) or pod2usage( -verbose => 2 );
16 pod2usage( -verbose => 2 ) if ( $a{help} );
17  
18 my ( $aln_file, $clustal_file ) = @ARGV;
19 pod2usage(
20 -msg => "ERROR: MUMMER alignment file not supplied or non-existent\n",
21 -verbose => 1,
22 -noperldoc => 1
23 ) unless ( $aln_file && -f $aln_file );
24  
25 #set clustalw output
26 my %aln_opt = ( -format => 'clustalw' );
27 if ( $clustal_file && $clustal_file ne '-' ) {
28 # real file
29 $aln_opt{'-file'} = ">$clustal_file";
30 } else {
31 # no file/stdout
32 $aln_opt{'-fh'} = \*STDOUT;
33 }
34 my $aln_out = Bio::AlignIO->new(%aln_opt);
35  
36 open my $aln_fh, '<', $aln_file or confess "Can't open filehandle: $!";
37 my $info = next_aln($aln_fh);
38 die "Can't find alignment header" unless ( $info =~ /^-- Alignments between (\S+) and (\S+)$/m );
39  
40 while ( my $ao = next_aln($aln_fh) ) {
41 $aln_out->write_aln( parse_alignment( $1, $2, $ao ) );
42 }
43  
44 $aln_fh->close;
45  
46 sub next_aln {
47 my ($aln_fh) = @_;
48  
49 local $/ = "\n-- BEGIN alignment ";
50 return <$aln_fh>;
51  
52 }
53  
54 sub parse_alignment {
55 my ( $r_id, $q_id, $data ) = @_;
56  
57 my @raw_alignment = grep {/^\[|\d/} split /\n/, $data;
58  
59 #get rid of 1st and last lines (coord infomation)
60 pop @raw_alignment;
61 die
62 unless ( ( shift @raw_alignment )
63 =~ /^\[\s+([-+]1)\s+(\d+)\s+-\s+(\d+)\s+\|\s+([+-]1)\s+(\d+)\s+-\s+(\d+)\s+\]$/ );
64 my %coords = (
65 r_strand => ( $1 > 0 ? '+' : '-' ),
66 r_start => $2,
67 r_end => $3,
68 q_strand => ( $4 > 0 ? '+' : '-' ),
69 q_start => $5,
70 q_end => $6,
71 );
72  
73 if ( $coords{r_start} > $coords{r_end} ) {
74 %coords = ( %coords, r_start => $coords{r_end}, r_end => $coords{r_start} );
75 }
76 if ( $coords{q_start} > $coords{q_end} ) {
77 %coords = ( %coords, q_start => $coords{q_end}, r_end => $coords{q_start} );
78 }
79  
80 my @alignments;
81 for ( my $i = 0; $i < @raw_alignment; $i++ ) {
82 my ( $start, $seq ) = split /\s+/, $raw_alignment[$i];
83 $seq =~ s/\r\n/\n/;
84 chomp $seq;
85 $alignments[ $i % 2 ] .= $seq;
86 }
87  
88 my $aln = Bio::SimpleAlign->new( -source => 'jwb', );
89  
90 #species-refseq(strand)/start-end
91 #rice-3(+)/16598648-16600199
92 #c_remanei-Crem_Contig172(-)/123228-124941
93  
94 my $r_seq = Bio::LocatableSeq->new(
95 -seq => $alignments[0],
96 -id => substr( $r_id, 0, 1 ) . "-$r_id($coords{r_strand})",
97 -start => $coords{r_start},
98 );
99 $aln->add_seq($r_seq);
100  
101 my $q_seq = Bio::LocatableSeq->new(
102 -seq => $alignments[1],
103 -id => substr( $q_id, 0, 1 ) . "-$q_id($coords{q_strand})",
104 -start => $coords{q_start},
105 );
106 $aln->add_seq($q_seq);
107  
108 $aln->map_chars( '\.', '-' );
109 return $aln;
110 }
111  
112 __END__
113  
114 =head1 NAME
115  
116 show-align2clustalw.pl - convert mummer alignment files to clustalw format
117  
118 =head1 SYNOPSIS
119
120 # store results in OUTPUT.aln
121 perl show-align2clustalw.pl [OPTIONS] <MUMMER_ALIGNMENT.aln> <CLUSTALW_OUTPUT.aln>
122  
123 # print results to standard output
124 perl show-align2clustalw.pl [OPTIONS] <MUMMER_ALIGNMENT.aln>
125 # or
126 perl show-align2clustalw.pl [OPTIONS] <MUMMER_ALIGNMENT.aln> -
127  
128 =head1 DESCRIPTION
129  
130 This script converts MUMMER's show-aligns output to clustalw formatted output.
131  
132 =head1 OPTIONS
133  
134 Alternative option names are separated by "|".
135  
136 =over 4
137  
138 =item B<< --help|h|? >>
139  
140 Complete help.
141  
142 =back
143  
144 =cut
145
146 =head1 SEE ALSO
147  
148 L<Bio::FeatureIO>, L<Bio::SeqFeature::Generic>
149  
150 =head1 AUTHOR
151  
152 jw bargsten, C<< <joachim.bargsten at wur.nl> >>
153  
154 =cut