| 1 | #!/usr/bin/env perl | ||
| 2 | # PODNAME: transferCleaner.pl | ||
| 3 | # ABSTRACT: transfer amino acid LSSs on corresponding nucleotide alignment | ||
| 4 | |||
| 5 | use Modern::Perl; | ||
| 6 | use Getopt::Euclid; | ||
| 7 | |||
| 8 | ## no critic (RequireLocalizedPunctuationVars) | ||
| 9 | BEGIN{ | ||
| 10 | $ENV{Smart_Comments} = $ARGV{-v} | ||
| 11 | ? join q{ }, map { '#' x (2 + $_) } 1..$ARGV{-v} | ||
| 12 | : q{} | ||
| 13 | ; | ||
| 14 | } | ||
| 15 | ## use critic | ||
| 16 | use Smart::Comments -ENV; | ||
| 17 | use Bio::MUST::Core::Utils qw(change_suffix); | ||
| 18 | use aliased 'Bio::MUST::Apps::HmmCleaner'; | ||
| 19 | use aliased 'Bio::MUST::Core::Ali'; | ||
| 20 | use Path::Class; | ||
| 21 | |||
| 22 | ### Lauching script... | ||
| 23 | |||
| 24 | ### INFILE : $ARGV{'<infile>'} | ||
| 25 | |||
| 26 | my $ali = Ali->load($ARGV{'<infile>'}); | ||
| 27 | |||
| 28 | my %log; | ||
| 29 | my $logfile = file($ARGV{'-log'}); | ||
| 30 | my $fh = $logfile->openr; | ||
| 31 | |||
| 32 | my $corg; | ||
| 33 | my @spans; | ||
| 34 | while (my $line = <$fh>) { | ||
| 35 | chomp $line; | ||
| 36 | unless (substr($line,0,1) =~ m/\s/) { | ||
| 37 | if (defined $corg && @spans > 0) { | ||
| 38 | $log{$corg} = [@spans]; | ||
| 39 | @spans = (); | ||
| 40 | } | ||
| 41 | $corg = $line; | ||
| 42 | } else { | ||
| 43 | $line =~ s/\s+//g; | ||
| 44 | my ($s,$e) = split "-", $line; | ||
| 45 | push @spans, [$s,$e]; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | $log{$corg} = [@spans] if (@spans); | ||
| 49 | |||
| 50 | #### %log | ||
| 51 | |||
| 52 | for my $seqid (keys %log) { | ||
| 53 | my $seq = $ali->get_seq_with_id($seqid); | ||
| 54 | |||
| 55 | for my $span (@{$log{$seqid}}) { | ||
| 56 | my $e_nt = (($$span[1]-1)*3)+2; | ||
| 57 | my $s_nt = ($$span[0]-1)*3; | ||
| 58 | my @indexes = $s_nt..$e_nt; | ||
| 59 | |||
| 60 | for my $pos (@indexes) { | ||
| 61 | $seq->edit_seq($pos,1,$ARGV{'-delchar'}); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | $ali->store(change_suffix($ali->file,'_cleaned.ali')); | ||
| 67 | |||
| 68 | ### End of script... | ||
| 69 | |||
| 70 | __END__ | ||
| 71 | |||
| 72 | =pod | ||
| 73 | |||
| 74 | =encoding UTF-8 | ||
| 75 | |||
| 76 | =head1 NAME | ||
| 77 | |||
| 78 | transferCleaner.pl - transfer amino acid LSSs on corresponding nucleotide alignment | ||
| 79 | |||
| 80 | =head1 VERSION | ||
| 81 | |||
| 82 | version 0.180750 | ||
| 83 | |||
| 84 | =head1 USAGE | ||
| 85 | |||
| 86 | transferCleaner.pl <infiles> -log=<log> [-delchar <delchar> -costs <c1> <c2> <c3> <c4> --changeID --noX] | ||
| 87 | |||
| 88 | =head1 REQUIRED ARGUMENTS | ||
| 89 | |||
| 90 | =over | ||
| 91 | |||
| 92 | =item <infile> | ||
| 93 | |||
| 94 | list of alignment file to check with HMMCleaner | ||
| 95 | |||
| 96 | =for Euclid: infile.type: readable | ||
| 97 | |||
| 98 | =item -log=<log> | ||
| 99 | |||
| 100 | Log file | ||
| 101 | |||
| 102 | =for Euclid: log.type: readable | ||
| 103 | |||
| 104 | =back | ||
| 105 | |||
| 106 | =head1 OPTIONS | ||
| 107 | |||
| 108 | =over | ||
| 109 | |||
| 110 | =item -delchar <delchar> | ||
| 111 | |||
| 112 | Replacement character for removed residues | ||
| 113 | |||
| 114 | =for Euclid: delchar.type: string | ||
| 115 | delchar.default: ' ' | ||
| 116 | |||
| 117 | =item -costs <c1> <c2> <c3> <c4> | ||
| 118 | |||
| 119 | Cost parameters that defines the low similarity segments detected by HmmCleaner. | ||
| 120 | Default values are -0.15, -0.08, 0.15, 0.45 | ||
| 121 | Users can change each value but they have to be in increasing order. | ||
| 122 | c1 < c2 < 0 < c3 < c4 | ||
| 123 | Predefine value are also available with --large and --specificity options but | ||
| 124 | user defined costs will be prioritary if present. | ||
| 125 | |||
| 126 | =for Euclid: c1.type: number < 0 | ||
| 127 | c2.type: number < 0 | ||
| 128 | c3.type: number > 0 | ||
| 129 | c4.type: number > 0 | ||
| 130 | |||
| 131 | =item --changeID | ||
| 132 | |||
| 133 | Determine if output will have defline with generic suffix (_hmmcleaned) | ||
| 134 | |||
| 135 | =item --noX | ||
| 136 | |||
| 137 | Consider X characters as gap that will not be taken into account by HmmCleaner. | ||
| 138 | |||
| 139 | =item -profile=<profile> | ||
| 140 | |||
| 141 | Determine how the profile will be create | ||
| 142 | local or global (default: global) | ||
| 143 | local = without the analyzed sequence (new profile each time) | ||
| 144 | global = all sequences (same profile for each sequence) | ||
| 145 | First case is more sensitive but need more ressource (hence more time) | ||
| 146 | |||
| 147 | =for Euclid: profile.type: /local|global/ | ||
| 148 | profile.type.error: <profile> must be either "local" or "global" | ||
| 149 | profile.default: 'global' | ||
| 150 | |||
| 151 | =item --large | ||
| 152 | |||
| 153 | Load predifined cost parameters optimized for MSA with at least 50 sequences. | ||
| 154 | Can be use with --specificity option. | ||
| 155 | User defined costs will be prioritary if present. | ||
| 156 | |||
| 157 | =item --specificity | ||
| 158 | |||
| 159 | Load predifined cost parameters optimized to give more weigth on specificity. | ||
| 160 | Can be use with --large option. | ||
| 161 | User defined costs will be prioritary if present. | ||
| 162 | |||
| 163 | =item --log_only | ||
| 164 | |||
| 165 | Only outputs list of segments removed. | ||
| 166 | |||
| 167 | =item --ali | ||
| 168 | |||
| 169 | Outputs result file(s) in ali MUST format. | ||
| 170 | |||
| 171 | =item -v[erbosity]=<level> | ||
| 172 | |||
| 173 | Verbosity level for logging to STDERR [default: 0]. Available levels range from | ||
| 174 | 0 to 5. | ||
| 175 | |||
| 176 | =for Euclid: level.type: int, level >= 0 && level <= 5 | ||
| 177 | level.default: 0 | ||
| 178 | |||
| 179 | =item --version | ||
| 180 | |||
| 181 | =item --usage | ||
| 182 | |||
| 183 | =item --help | ||
| 184 | |||
| 185 | =item --man | ||
| 186 | |||
| 187 | Print the usual program information | ||
| 188 | |||
| 189 | =back | ||
| 190 | |||
| 191 | =head1 AUTHOR | ||
| 192 | |||
| 193 | Arnaud Di Franco <arnaud.difranco@gmail.fr> | ||
| 194 | |||
| 195 | =head1 COPYRIGHT AND LICENSE | ||
| 196 | |||
| 197 | This software is copyright (c) 2018 by Arnaud Di Franco. | ||
| 198 | |||
| 199 | This is free software; you can redistribute it and/or modify it under | ||
| 200 | the same terms as the Perl 5 programming language system itself. | ||
| 201 | |||
| 202 | =cut |