| 1 | package Bio::MUST::Drivers::CdHit; | ||||||||||||
| 2 | # ABSTRACT: Bio::MUST driver for running the CD-HIT program | ||||||||||||
| 3 | # CONTRIBUTOR: Amandine BERTRAND <amandine.bertrand@doct.uliege.be> | ||||||||||||
| 4 | 6 | $Bio::MUST::Drivers::CdHit::VERSION = '0.210160'; | |||||||||||
| 5 | 6 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 6 | ▶ | use namespace::autoclean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 6 | ▶ | use autodie; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 6 | ▶ | use feature qw(say); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | # use Smart::Comments; | ||||||||||||
| 12 | |||||||||||||
| 13 | 6 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 6 | ▶ | use IPC::System::Simple qw(system); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 6 | ▶ | use Module::Runtime qw(use_module); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 6 | ▶ | use Path::Class qw(file); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 6 | ▶ | use Tie::IxHash; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | |||||||||||||
| 19 | 6 | ▶ | use Bio::MUST::Core; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | 6 | extends 'Bio::MUST::Core::Ali::Temporary'; | |||||||||||
| 21 | |||||||||||||
| 22 | 6 | ▶ | use Bio::MUST::Drivers::Utils qw(stringify_args); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 23 | 6 | ▶ | use aliased 'Bio::MUST::Core::Ali'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | 6 | ▶ | use aliased 'Bio::MUST::Core::SeqId'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | 6 | ▶ | use aliased 'Bio::FastParsers::CdHit'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | |||||||||||||
| 27 | |||||||||||||
| 28 | has 'cdhit_args' => ( | ||||||||||||
| 29 | is => 'ro', | ||||||||||||
| 30 | isa => 'HashRef', | ||||||||||||
| 31 | 0 | ▶ | default => sub { {} }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 32 | 6 | ); | |||||||||||
| 33 | |||||||||||||
| 34 | 6 | has '_cluster_seq_ids' => ( | |||||||||||
| 35 | traits => ['Hash'], | ||||||||||||
| 36 | is => 'ro', | ||||||||||||
| 37 | isa => 'HashRef[ArrayRef[Bio::MUST::Core::SeqId]]', | ||||||||||||
| 38 | init_arg => undef, | ||||||||||||
| 39 | writer => '_set_cluster_seq_ids', | ||||||||||||
| 40 | handles => { | ||||||||||||
| 41 | all_cluster_names => 'keys', | ||||||||||||
| 42 | all_cluster_seq_ids => 'values', | ||||||||||||
| 43 | seq_ids_for => 'get', | ||||||||||||
| 44 | }, | ||||||||||||
| 45 | ); | ||||||||||||
| 46 | |||||||||||||
| 47 | 6 | has '_representatives' => ( | |||||||||||
| 48 | is => 'ro', | ||||||||||||
| 49 | isa => 'Bio::MUST::Core::Ali', | ||||||||||||
| 50 | init_arg => undef, | ||||||||||||
| 51 | writer => '_set_representatives', | ||||||||||||
| 52 | handles => { | ||||||||||||
| 53 | all_representatives => 'all_seqs', | ||||||||||||
| 54 | count_representatives => 'count_seqs', | ||||||||||||
| 55 | get_representative_with_id => 'get_seq_with_id', # useless? | ||||||||||||
| 56 | }, | ||||||||||||
| 57 | ); | ||||||||||||
| 58 | |||||||||||||
| 59 | 6 | has '_representative_for' => ( | |||||||||||
| 60 | traits => ['Hash'], | ||||||||||||
| 61 | is => 'ro', | ||||||||||||
| 62 | isa => 'HashRef[Bio::MUST::Core::Seq]', | ||||||||||||
| 63 | init_arg => undef, | ||||||||||||
| 64 | lazy => 1, | ||||||||||||
| 65 | builder => '_build_representative_for', | ||||||||||||
| 66 | handles => { | ||||||||||||
| 67 | all_member_names => 'keys', | ||||||||||||
| 68 | representative_for => 'get', | ||||||||||||
| 69 | }, | ||||||||||||
| 70 | ); | ||||||||||||
| 71 | |||||||||||||
| 72 | ## no critic (ProhibitUnusedPrivateSubroutines) | ||||||||||||
| 73 | |||||||||||||
| 74 | sub _build_representative_for { | ||||||||||||
| 75 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_build_representative_for: not called CC=3 SCAR=24.8
| |||||||||||||
| 76 | |||||||||||||
| 77 | 0 | my %representative_for; | |||||||||||
| 78 | 0 | for my $repr ( $self->all_cluster_names ) { | |||||||||||
| 79 | 0 | for my $id ( @{ $self->seq_ids_for($repr) } ) { | |||||||||||
| 80 | 0 | $representative_for{ $id->full_id } | |||||||||||
| 81 | = $self->get_representative_with_id($repr); | ||||||||||||
| 82 | } | ||||||||||||
| 83 | } | ||||||||||||
| 84 | |||||||||||||
| 85 | 0 | return \%representative_for; | |||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | ## use critic | ||||||||||||
| 89 | |||||||||||||
| 90 | sub BUILD { | ||||||||||||
| 91 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
BUILD: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||
| 92 | |||||||||||||
| 93 | # provision executable | ||||||||||||
| 94 | 0 | my $app = use_module('Bio::MUST::Provision::CdHit')->new; | |||||||||||
| 95 | 0 | $app->meet(); | |||||||||||
| 96 | |||||||||||||
| 97 | # setup output files | ||||||||||||
| 98 | 0 | my $infile = $self->filename; | |||||||||||
| 99 | 0 | my $basename = $infile . '.cdhit'; | |||||||||||
| 100 | 0 | my $outfile = $basename . '.out'; | |||||||||||
| 101 | 0 | my $outfile_clstr = $basename . '.out.clstr'; | |||||||||||
| 102 | |||||||||||||
| 103 | # format cd-hit (optional) arguments | ||||||||||||
| 104 | 0 | my $args = $self->cdhit_args; | |||||||||||
| 105 | 0 | my $args_str = stringify_args($args); | |||||||||||
| 106 | |||||||||||||
| 107 | # create cd-hit (or cd-hit-est) command | ||||||||||||
| 108 | 0 | ▶ | my $pgm = $self->type eq 'prot' ? 'cd-hit' : 'cd-hit-est'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 109 | 0 | my $cmd = "$pgm -i $infile -o $outfile $args_str > /dev/null 2> /dev/null"; | |||||||||||
| 110 | #### $cmd | ||||||||||||
| 111 | |||||||||||||
| 112 | # try to robustly execute cd-hit | ||||||||||||
| 113 | 0 | my $ret_code = system( [ 0, 127 ], $cmd); | |||||||||||
| 114 | 0 | ▶ | if ($ret_code == 127) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 115 | 0 | carp "[BMD] Warning: cannot execute $pgm command;" | |||||||||||
| 116 | . ' returning without contigs!'; | ||||||||||||
| 117 | 0 | return; | |||||||||||
| 118 | } | ||||||||||||
| 119 | # TODO: try to bypass shell (need for absolute path to executable then) | ||||||||||||
| 120 | |||||||||||||
| 121 | # parse output file | ||||||||||||
| 122 | 0 | my $parser = CdHit->new(file => $outfile_clstr); | |||||||||||
| 123 | 0 | my $mapper = $self->mapper; | |||||||||||
| 124 | |||||||||||||
| 125 | # restore original ids for cluster members... | ||||||||||||
| 126 | 0 | tie my %cluster_seq_ids, 'Tie::IxHash'; | |||||||||||
| 127 | 0 | for my $abbr_id ( $parser->all_representatives ) { | |||||||||||
| 128 | my @member_ids = map { | ||||||||||||
| 129 | 0 | SeqId->new( full_id => $mapper->long_id_for($_) ) | |||||||||||
| 130 | 0 | ▶ | } @{ $parser->members_for($abbr_id) // [] }; | ||||||||||
|
Condition0%0/2
$parser->members_for($abbr_id) // []
MC/DC0%0/1
$parser->members_for($abbr_id) // []
$parser->members_for($abbr_id)
Truth table0%0/2
A
A= $parser->members_for($abbr_id)
| |||||||||||||
| 131 | 0 | $cluster_seq_ids{ $mapper->long_id_for($abbr_id) } = \@member_ids; | |||||||||||
| 132 | } | ||||||||||||
| 133 | |||||||||||||
| 134 | # ... and store cluster members | ||||||||||||
| 135 | 0 | $self->_set_cluster_seq_ids(\%cluster_seq_ids); | |||||||||||
| 136 | |||||||||||||
| 137 | # read and store representative seqs... | ||||||||||||
| 138 | 0 | my $representatives = Ali->load($outfile); | |||||||||||
| 139 | 0 | $representatives->dont_guess; | |||||||||||
| 140 | 0 | $representatives->restore_ids($mapper); # ... restoring original ids | |||||||||||
| 141 | 0 | $self->_set_representatives($representatives); | |||||||||||
| 142 | |||||||||||||
| 143 | # unlink temp files | ||||||||||||
| 144 | 0 | file($_)->remove for $outfile, $outfile_clstr; | |||||||||||
| 145 | |||||||||||||
| 146 | 0 | return; | |||||||||||
| 147 | } | ||||||||||||
| 148 | |||||||||||||
| 149 | 6 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 150 | 6 | 1; | |||||||||||
| 151 | |||||||||||||
| 152 | __END__ | ||||||||||||
| 153 | |||||||||||||
| 154 | =pod | ||||||||||||
| 155 | |||||||||||||
| 156 | =head1 NAME | ||||||||||||
| 157 | |||||||||||||
| 158 | Bio::MUST::Drivers::CdHit - Bio::MUST driver for running the CD-HIT program | ||||||||||||
| 159 | |||||||||||||
| 160 | =head1 VERSION | ||||||||||||
| 161 | |||||||||||||
| 162 | version 0.210160 | ||||||||||||
| 163 | |||||||||||||
| 164 | =head1 SYNOPSIS | ||||||||||||
| 165 | |||||||||||||
| 166 | # TODO | ||||||||||||
| 167 | |||||||||||||
| 168 | =head1 DESCRIPTION | ||||||||||||
| 169 | |||||||||||||
| 170 | # TODO | ||||||||||||
| 171 | |||||||||||||
| 172 | =head1 AUTHOR | ||||||||||||
| 173 | |||||||||||||
| 174 | Denis BAURAIN <denis.baurain@uliege.be> | ||||||||||||
| 175 | |||||||||||||
| 176 | =head1 CONTRIBUTOR | ||||||||||||
| 177 | |||||||||||||
| 178 | =for stopwords Amandine BERTRAND | ||||||||||||
| 179 | |||||||||||||
| 180 | Amandine BERTRAND <amandine.bertrand@doct.uliege.be> | ||||||||||||
| 181 | |||||||||||||
| 182 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 183 | |||||||||||||
| 184 | This software is copyright (c) 2013 by University of Liege / Unit of Eukaryotic Phylogenomics / Denis BAURAIN. | ||||||||||||
| 185 | |||||||||||||
| 186 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 187 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 188 | |||||||||||||
| 189 | =cut | ||||||||||||