| 1 | # | ||||||||||||||
| 2 | # BioPerl module for Bio::AlignIO::maf | ||||||||||||||
| 3 | # | ||||||||||||||
| 4 | # Copyright Allen Day | ||||||||||||||
| 5 | # | ||||||||||||||
| 6 | |||||||||||||||
| 7 | =head1 NAME | ||||||||||||||
| 8 | |||||||||||||||
| 9 | Bio::AlignIO::maf - Multiple Alignment Format sequence input stream | ||||||||||||||
| 10 | |||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||
| 12 | |||||||||||||||
| 13 | Do not use this module directly. Use it via the Bio::AlignIO class. | ||||||||||||||
| 14 | |||||||||||||||
| 15 | use Bio::AlignIO; | ||||||||||||||
| 16 | |||||||||||||||
| 17 | my $alignio = Bio::AlignIO->new(-fh => \*STDIN, -format => 'maf'); | ||||||||||||||
| 18 | |||||||||||||||
| 19 | while(my $aln = $alignio->next_aln()){ | ||||||||||||||
| 20 | my $match_line = $aln->match_line; | ||||||||||||||
| 21 | |||||||||||||||
| 22 | print $aln, "\n"; | ||||||||||||||
| 23 | |||||||||||||||
| 24 | print $aln->length, "\n"; | ||||||||||||||
| 25 | print $aln->num_residues, "\n"; | ||||||||||||||
| 26 | print $aln->is_flush, "\n"; | ||||||||||||||
| 27 | print $aln->num_sequences, "\n"; | ||||||||||||||
| 28 | |||||||||||||||
| 29 | $aln->splice_by_seq_pos(1); | ||||||||||||||
| 30 | |||||||||||||||
| 31 | print $aln->consensus_string(60), "\n"; | ||||||||||||||
| 32 | print $aln->get_seq_by_pos(1)->seq, "\n"; | ||||||||||||||
| 33 | print $aln->match_line(), "\n"; | ||||||||||||||
| 34 | |||||||||||||||
| 35 | print "\n"; | ||||||||||||||
| 36 | } | ||||||||||||||
| 37 | |||||||||||||||
| 38 | =head1 DESCRIPTION | ||||||||||||||
| 39 | |||||||||||||||
| 40 | This class constructs Bio::SimpleAlign objects from an MAF-format | ||||||||||||||
| 41 | multiple alignment file. | ||||||||||||||
| 42 | |||||||||||||||
| 43 | Writing in MAF format is currently unimplemented. | ||||||||||||||
| 44 | |||||||||||||||
| 45 | Spec of MAF format is here: | ||||||||||||||
| 46 | http://genome.ucsc.edu/FAQ/FAQformat | ||||||||||||||
| 47 | |||||||||||||||
| 48 | =head1 FEEDBACK | ||||||||||||||
| 49 | |||||||||||||||
| 50 | =head2 Support | ||||||||||||||
| 51 | |||||||||||||||
| 52 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||
| 53 | |||||||||||||||
| 54 | I<bioperl-l@bioperl.org> | ||||||||||||||
| 55 | |||||||||||||||
| 56 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||
| 57 | reponsive experts will be able look at the problem and quickly | ||||||||||||||
| 58 | address it. Please include a thorough description of the problem | ||||||||||||||
| 59 | with code and data examples if at all possible. | ||||||||||||||
| 60 | |||||||||||||||
| 61 | =head2 Reporting Bugs | ||||||||||||||
| 62 | |||||||||||||||
| 63 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||
| 64 | the bugs and their resolution. Bug reports can be submitted via the | ||||||||||||||
| 65 | web: | ||||||||||||||
| 66 | |||||||||||||||
| 67 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||
| 68 | |||||||||||||||
| 69 | =head1 AUTHORS - Allen Day | ||||||||||||||
| 70 | |||||||||||||||
| 71 | Email: allenday@ucla.edu | ||||||||||||||
| 72 | |||||||||||||||
| 73 | =head1 APPENDIX | ||||||||||||||
| 74 | |||||||||||||||
| 75 | The rest of the documentation details each of the object | ||||||||||||||
| 76 | methods. Internal methods are usually preceded with a _ | ||||||||||||||
| 77 | |||||||||||||||
| 78 | =cut | ||||||||||||||
| 79 | |||||||||||||||
| 80 | # Let the code begin... | ||||||||||||||
| 81 | |||||||||||||||
| 82 | package Bio::AlignIO::maf; | ||||||||||||||
| 83 | 2 | $Bio::AlignIO::maf::VERSION = '1.7.8'; | |||||||||||||
| 84 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 85 | |||||||||||||||
| 86 | 2 | ▶ | use Bio::SimpleAlign; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 87 | |||||||||||||||
| 88 | 2 | ▶ | use base qw(Bio::AlignIO); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 89 | |||||||||||||||
| 90 | =head2 new | ||||||||||||||
| 91 | |||||||||||||||
| 92 | Title : new | ||||||||||||||
| 93 | Usage : my $alignio = Bio::AlignIO->new(-format => 'maf' | ||||||||||||||
| 94 | -file => '>file', | ||||||||||||||
| 95 | -idlength => 10, | ||||||||||||||
| 96 | -idlinebreak => 1); | ||||||||||||||
| 97 | Function: Initialize a new L<Bio::AlignIO::maf> reader | ||||||||||||||
| 98 | Returns : L<Bio::AlignIO> object | ||||||||||||||
| 99 | Args : | ||||||||||||||
| 100 | |||||||||||||||
| 101 | =cut | ||||||||||||||
| 102 | |||||||||||||||
| 103 | 2 | ▶ | sub _initialize { | ||||||||||||
|
Subroutine
_initialize: called CC=1 SCAR=0.0
| |||||||||||||||
| 104 | 2 | my($self,@args) = @_; | |||||||||||||
| 105 | 2 | $self->SUPER::_initialize(@args); | |||||||||||||
| 106 | |||||||||||||||
| 107 | 2 | 1; | |||||||||||||
| 108 | } | ||||||||||||||
| 109 | |||||||||||||||
| 110 | =head2 next_aln | ||||||||||||||
| 111 | |||||||||||||||
| 112 | Title : next_aln | ||||||||||||||
| 113 | Usage : $aln = $stream->next_aln() | ||||||||||||||
| 114 | Function: returns the next alignment in the stream. | ||||||||||||||
| 115 | Throws an exception if trying to read in PHYLIP | ||||||||||||||
| 116 | sequential format. | ||||||||||||||
| 117 | Returns : L<Bio::SimpleAlign> object | ||||||||||||||
| 118 | Args : | ||||||||||||||
| 119 | |||||||||||||||
| 120 | =cut | ||||||||||||||
| 121 | |||||||||||||||
| 122 | 4 | ▶ | sub next_aln { | ||||||||||||
|
Subroutine
next_aln: called CC=16 SCAR=27.8
Pod
documented
| |||||||||||||||
| 123 | 4 | my $self = shift; | |||||||||||||
| 124 | |||||||||||||||
| 125 | # check beginning of file for proper header | ||||||||||||||
| 126 | 4 | ▶ | if(!$self->{seen_header}){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 127 | 2 | my $line = $self->_readline; | |||||||||||||
| 128 | 2 | ▶ | $self->throw("This doesn't look like a MAF file. First line should start with ##maf, but it was: ".$line) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 129 | unless $line =~ /^##maf/; | ||||||||||||||
| 130 | 2 | $self->{seen_header} = 1; | |||||||||||||
| 131 | # keep in case we parse this later | ||||||||||||||
| 132 | 2 | $self->_pushback($line); | |||||||||||||
| 133 | } | ||||||||||||||
| 134 | |||||||||||||||
| 135 | 4 | my $aln = Bio::SimpleAlign->new(-source => 'maf'); | |||||||||||||
| 136 | |||||||||||||||
| 137 | 4 | my($aline, @slines, $seen_aline); | |||||||||||||
| 138 | 4 | ▶ | while(my $line = $self->_readline()){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 139 | 34 | ▶ | if ($line =~ /^a\s/xms) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 140 | # next block? | ||||||||||||||
| 141 | 7 | ▶ | if ($seen_aline) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 142 | 3 | $self->_pushback($line); | |||||||||||||
| 143 | 3 | last; | |||||||||||||
| 144 | } | ||||||||||||||
| 145 | 4 | $aline = $line; | |||||||||||||
| 146 | 4 | $seen_aline++; | |||||||||||||
| 147 | } elsif ($line =~ /^s\s/xms) { | ||||||||||||||
| 148 | 17 | push @slines, $line; | |||||||||||||
| 149 | } else { | ||||||||||||||
| 150 | # missed lines | ||||||||||||||
| 151 | 10 | $self->debug($line); | |||||||||||||
| 152 | } | ||||||||||||||
| 153 | } | ||||||||||||||
| 154 | |||||||||||||||
| 155 | # all MAF starts with 'a' line | ||||||||||||||
| 156 | 4 | ▶ | return unless $aline; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 157 | |||||||||||||||
| 158 | 4 | my($kvs) = $aline =~ /^a\s+(.+)$/; | |||||||||||||
| 159 | 4 | ▶ | my @kvs = split /\s+/, $kvs if $kvs; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 160 | 4 | my %kv; | |||||||||||||
| 161 | 4 | foreach my $kv (@kvs){ | |||||||||||||
| 162 | 3 | my($k,$v) = $kv =~ /(.+)=(.+)/; | |||||||||||||
| 163 | 3 | $kv{$k} = $v; | |||||||||||||
| 164 | } | ||||||||||||||
| 165 | |||||||||||||||
| 166 | 4 | $aln->score($kv{score}); | |||||||||||||
| 167 | |||||||||||||||
| 168 | 4 | foreach my $sline (@slines){ | |||||||||||||
| 169 | 17 | my($s,$src,$start,$size,$strand,$srcsize,$text) = | |||||||||||||
| 170 | split /\s+/, $sline; | ||||||||||||||
| 171 | # adjust coordinates to be one-based inclusive | ||||||||||||||
| 172 | 17 | $start = $start + 1; | |||||||||||||
| 173 | 17 | ▶ | $strand = $strand eq '+' ? 1 : $strand eq '-' ? -1 : 0; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 174 | 17 | ▶ | my $seq = Bio::LocatableSeq->new('-seq' => $text, | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 175 | '-display_id' => $src, | ||||||||||||||
| 176 | '-start' => $strand > 0 ? $start : ($srcsize-($start+$size-2)), | ||||||||||||||
| 177 | '-end' => $strand > 0 ? ($start + $size - 1) : ($srcsize-($start-1)) , | ||||||||||||||
| 178 | '-strand' => $strand, | ||||||||||||||
| 179 | '-alphabet' => $self->alphabet, | ||||||||||||||
| 180 | ); | ||||||||||||||
| 181 | 17 | $aln->add_seq($seq); | |||||||||||||
| 182 | } | ||||||||||||||
| 183 | |||||||||||||||
| 184 | 4 | ▶ | return $aln if $aln->num_sequences; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 185 | 0 | return; | |||||||||||||
| 186 | } | ||||||||||||||
| 187 | |||||||||||||||
| 188 | 0 | ▶ | sub write_aln { | ||||||||||||
|
Subroutine
write_aln: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 189 | shift->throw_not_implemented | ||||||||||||||
| 190 | 0 | } | |||||||||||||
| 191 | |||||||||||||||
| 192 | 2 | 1; | |||||||||||||