« blib/lib/Bio/AutomatedAnnotation/CommandLine/ParseGenesFromGFFs.pm
↑ Summary
blib/lib/Bio/AutomatedAnnotation/GeneNamesFromGFF.pm »
| 1 | package Bio::AutomatedAnnotation::External::Cmscan; | ||
| 2 | |||
| 3 | # ABSTRACT: Run and parse the output of cmscan | ||
| 4 | |||
| 5 | |||
| 6 | use Moose; | ||
| 7 | use Bio::SeqFeature::Generic; | ||
| 8 | |||
| 9 | has 'cmdb' => ( is => 'ro', isa => 'Str', required => 1 ); | ||
| 10 | has 'input_file' => ( is => 'ro', isa => 'Str', required => 1 ); | ||
| 11 | |||
| 12 | has 'exec' => ( is => 'ro', isa => 'Str', default => 'cmscan' ); | ||
| 13 | has 'version' => ( is => 'ro', isa => 'Str', default => '1.1' ); | ||
| 14 | has 'cpus' => ( is => 'ro', isa => 'Int', default => 1 ); | ||
| 15 | has 'evalue' => ( is => 'ro', isa => 'Num', default => 1E-6 ); | ||
| 16 | has 'features' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build_features' ); | ||
| 17 | has 'number_of_features' => ( is => 'rw', isa => 'Int', default => 0 ); | ||
| 18 | |||
| 19 | has '_tool' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build__tool' ); | ||
| 20 | has '_cpus' => ( is => 'ro', isa => 'Int', lazy => 1, builder => '_build__cpus' ); | ||
| 21 | has '_infernal_fh' => ( is => 'ro', lazy => 1, builder => '_build__infernal_fh' ); | ||
| 22 | |||
| 23 | sub _build__tool { | ||
| 24 | my ($self) = @_; | ||
| 25 | return "Infernal:" . $self->version; | ||
| 26 | } | ||
| 27 | |||
| 28 | sub _build__cpus { | ||
| 29 | my ($self) = @_; | ||
| 30 | return $self->cpus || 1; | ||
| 31 | } | ||
| 32 | |||
| 33 | sub _build__infernal_fh { | ||
| 34 | my ($self) = @_; | ||
| 35 | open( | ||
| 36 | my $fh, | ||
| 37 | '-|', | ||
| 38 | join( | ||
| 39 | ' ', | ||
| 40 | ( | ||
| 41 | $self->exec, '--cpu', $self->_cpus, '-E', $self->evalue, '--tblout', | ||
| 42 | '/dev/stdout', '-o', '/dev/null', '--noali', $self->cmdb, $self->input_file | ||
| 43 | ) | ||
| 44 | ) | ||
| 45 | ); | ||
| 46 | return $fh; | ||
| 47 | } | ||
| 48 | |||
| 49 | sub _build_features { | ||
| 50 | my ($self) = @_; | ||
| 51 | my %features; | ||
| 52 | |||
| 53 | my $number_of_features = 0; | ||
| 54 | my $fh = $self->_infernal_fh; | ||
| 55 | while ( <$fh> ) { | ||
| 56 | next if (/\#/); | ||
| 57 | my @x = split ' '; # magic Perl whitespace splitter | ||
| 58 | next if ( @x < 16 ); | ||
| 59 | next unless $x[1] =~ m/^RF\d/; | ||
| 60 | |||
| 61 | # The start coord is always the lowest | ||
| 62 | my $sequence_id = $x[2]; | ||
| 63 | my $start_coords = $x[7]; | ||
| 64 | my $end_coords = $x[8]; | ||
| 65 | my $current_strand = $x[9] eq '-' ? -1 : +1; | ||
| 66 | |||
| 67 | if ( $start_coords > $end_coords ) { | ||
| 68 | my $tmp_coords = $end_coords; | ||
| 69 | $end_coords = $start_coords; | ||
| 70 | $start_coords = $tmp_coords; | ||
| 71 | $current_strand = -1; | ||
| 72 | } | ||
| 73 | |||
| 74 | push @{ $features{$sequence_id} }, | ||
| 75 | Bio::SeqFeature::Generic->new( | ||
| 76 | -primary => 'ncRNA', | ||
| 77 | -seq_id => $sequence_id, | ||
| 78 | -source => $self->_tool, | ||
| 79 | -start => $start_coords, | ||
| 80 | -end => $end_coords, | ||
| 81 | -strand => $current_strand, | ||
| 82 | -frame => 0, | ||
| 83 | -tag => { | ||
| 84 | 'product' => $x[0], | ||
| 85 | 'inference' => "COORDINATES:profile:" . $self->_tool, | ||
| 86 | } | ||
| 87 | ); | ||
| 88 | $number_of_features++; | ||
| 89 | |||
| 90 | } | ||
| 91 | $self->number_of_features($number_of_features); | ||
| 92 | return \%features; | ||
| 93 | } | ||
| 94 | |||
| 95 | |||
| 96 | sub add_features_to_prokka_structure | ||
| 97 | { | ||
| 98 | my ($self, $prokka_sequence_structure) = @_; | ||
| 99 | for my $sequence_id (keys %{$self->features}) | ||
| 100 | { | ||
| 101 | push(@{$prokka_sequence_structure->{$sequence_id}{FEATURE}}, @{$self->features->{$sequence_id}}); | ||
| 102 | } | ||
| 103 | return $prokka_sequence_structure; | ||
| 104 | } | ||
| 105 | |||
| 106 | no Moose; | ||
| 107 | __PACKAGE__->meta->make_immutable; | ||
| 108 | |||
| 109 | 1; | ||
| 110 | |||
| 111 | __END__ | ||
| 112 | |||
| 113 | =pod | ||
| 114 | |||
| 115 | =encoding UTF-8 | ||
| 116 | |||
| 117 | =head1 NAME | ||
| 118 | |||
| 119 | Bio::AutomatedAnnotation::External::Cmscan - Run and parse the output of cmscan | ||
| 120 | |||
| 121 | =head1 VERSION | ||
| 122 | |||
| 123 | version 1.182685 | ||
| 124 | |||
| 125 | =head1 SYNOPSIS | ||
| 126 | |||
| 127 | Run and parse the output of cmscan | ||
| 128 | use Bio::AutomatedAnnotation::External::Cmscan; | ||
| 129 | |||
| 130 | my $obj = Bio::AutomatedAnnotation::External::Cmscan->new( | ||
| 131 | cmdb => 'database/cm/Bacteria', | ||
| 132 | input_file => 'abc.fa', | ||
| 133 | exec => 'cmscan', | ||
| 134 | version => '1.1', | ||
| 135 | cpus => 1, | ||
| 136 | evalue => 1E-6, | ||
| 137 | ); | ||
| 138 | $obj->features; | ||
| 139 | |||
| 140 | =head1 AUTHOR | ||
| 141 | |||
| 142 | Andrew J. Page <ap13@sanger.ac.uk> | ||
| 143 | |||
| 144 | =head1 COPYRIGHT AND LICENSE | ||
| 145 | |||
| 146 | This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute. | ||
| 147 | |||
| 148 | This is free software, licensed under: | ||
| 149 | |||
| 150 | The GNU General Public License, Version 3, June 2007 | ||
| 151 | |||
| 152 | =cut |