| 1 | package Bio::Gonzales::Feat::IO::CDhit; | ||
| 2 | |||
| 3 | use Mouse; | ||
| 4 | |||
| 5 | use warnings; | ||
| 6 | use strict; | ||
| 7 | |||
| 8 | use 5.010; | ||
| 9 | use Carp; | ||
| 10 | |||
| 11 | use List::MoreUtils qw/zip/; | ||
| 12 | use Bio::Gonzales::Feat; | ||
| 13 | use Data::Dumper; | ||
| 14 | use Carp; | ||
| 15 | use Scalar::Util qw/blessed/; | ||
| 16 | use Bio::Gonzales::Seq::Util qw/strand_convert/; | ||
| 17 | |||
| 18 | extends 'Bio::Gonzales::Feat::IO::Base'; | ||
| 19 | |||
| 20 | has _current_cl => ( is => 'rw' ); | ||
| 21 | has _current_strand => ( is => 'rw' ); | ||
| 22 | has _current_num => ( is => 'rw', default => 0 ); | ||
| 23 | has query_reverse_match_orientation => ( is => 'rw', default => 1 ); | ||
| 24 | has seq_id => ( is => 'rw', default => 'ref01' ); | ||
| 25 | |||
| 26 | our $VERSION = '0.058'; # VERSION | ||
| 27 | |||
| 28 | sub BUILD { | ||
| 29 | my ($self) = @_; | ||
| 30 | |||
| 31 | $self->_parse_header if ( $self->mode eq '<' ); | ||
| 32 | } | ||
| 33 | |||
| 34 | sub _parse_header { | ||
| 35 | my ($self) = @_; | ||
| 36 | |||
| 37 | my $fhi = $self->_fhi; | ||
| 38 | |||
| 39 | my $l; | ||
| 40 | while ( defined( $l = $fhi->() ) ) { | ||
| 41 | next if ( !$l || $l =~ /^\s*$/ ); | ||
| 42 | last if ( $l =~ /^>/ ); | ||
| 43 | } | ||
| 44 | |||
| 45 | push @{ $self->_cached_records }, $l; | ||
| 46 | return; | ||
| 47 | } | ||
| 48 | |||
| 49 | sub next_feat { | ||
| 50 | my ($self) = @_; | ||
| 51 | |||
| 52 | my $fhi = $self->_fhi; | ||
| 53 | |||
| 54 | my $l; | ||
| 55 | my $cur_cl = $self->_current_cl; | ||
| 56 | my $cur_strand = $self->_current_strand; | ||
| 57 | while ( defined( $l = $fhi->() ) ) { | ||
| 58 | if ( $l =~ /^>Cluster\s*(\d+)/ ) { | ||
| 59 | $cur_cl = $1; | ||
| 60 | |||
| 61 | $self->_current_cl($cur_cl); | ||
| 62 | next; | ||
| 63 | } elsif ( $l =~ /^(\d+)\s+(\d+)nt, >(\S+)\.\.\.\s+(\*|at ([+-])\/([0-9.]+)%)$/ ) { | ||
| 64 | my ( $cl_member_id, $len, $id, $strand, $score, $star ) = ( $1, $2, $3, $5, $6, $4 ); | ||
| 65 | |||
| 66 | $score //= 100; | ||
| 67 | $strand //= '+'; | ||
| 68 | |||
| 69 | return Bio::Gonzales::Feat->new( | ||
| 70 | seq_id => "cl" . $cur_cl, | ||
| 71 | source => 'cdhit', | ||
| 72 | type => 'match', | ||
| 73 | strand => strand_convert($strand), | ||
| 74 | start => '.', | ||
| 75 | end => '.', | ||
| 76 | score => $score, | ||
| 77 | attributes => { | ||
| 78 | ID => [$id], | ||
| 79 | Length => [$len], | ||
| 80 | Representative => [ ( $star eq '*' ? 1 : 0 ) ], | ||
| 81 | }, | ||
| 82 | ); | ||
| 83 | } else { | ||
| 84 | last; | ||
| 85 | } | ||
| 86 | } | ||
| 87 | $self->close; | ||
| 88 | return; | ||
| 89 | } | ||
| 90 | |||
| 91 | 1; |