1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| use Data::Dumper;
use Statistics::Lite qw(:funcs);
#use Statistics::Descriptive;
open (READS, $ARGV[0]) or warn "On ne peut pas lire le fichier entrant: $!\n"and next;
undef($/);
my $readInString = <READS>;
close (READS);
%transColor = (A => [A,C,G,T], T=>[T,G,C,A] , C=>[C,A,T,G], G=>[G,T,A,C]);
@tableOfLines = split (/>/,$readInString);
open (QUALV, $ARGV[1]) or warn "On ne peut pas lire le fichier entrant: $!\n"and next;
undef($/);
my $qualInString = <QUALV>;
close (QUALV);
@tableOfLines2 = split (/>/,$qualInString);
$threshold=$ARGV[2];
if (defined($ARGV[3])){
$threshold2=$ARGV[3];
}
else {$threshold2=100000;
}
if ($tableOfLines[0] eq ''){
shift @tableOfLines;
}
if ($tableOfLines2[0] eq ''){
shift @tableOfLines2;
}
$NbReads=@tableOfLines;
for ($i=0; $i<$NbReads; $i++) { #parcour tout le fichier de read
$read = $tableOfLines[$i];
$qual = $tableOfLines2[$i];
if ($read =~ /(.*)\n(.*)/){ #recupere le nom et la sequence d'un read
$nam=$1;
$seq=$2;
if (($seq !~ /.*\..*/) or (index($seq,".") >= 25)) { #garde le read s'il ne contient pas de . ou alors au-delà du caractere 25
while ($seq =~ /(.*)\./){ #ne garde que ce qu'il y a avant le 1er point
$seq=$1;
}
if ($qual=~/$nam\n(.*)\n/){ #verifie le nom de read des QV associees
#puis trouve le minimum
$qValues=$1;
@tableQValues=split (/ /,$qValues);
$t=@tableQValues;
for ($r=length($seq); $r<$t-1;$r++){
pop (@tableQValues);
}
$smallest= min @tableQValues;
@readNum= split (//,$seq);
$tableNumSize= @readNum;
if ($nam=~ s/F3/.1/){ #change les fins d'en-tête de reads pour MEGAN
$transChar[0]=$readNum[0];
}
elsif ($nam=~ s/R3/.2/){ #change les fins d'en-tête de reads pour MEGAN
$transChar[0]=$readNum[0];
}
if (($smallest>$threshold)and($smallest<=$threshold2)){ # traduit, filtre si les QV sont > seuil pendant au moins 24 caracteres
$transString="";
for ($j=1;$j<$tableNumSize;$j++){ #traduit les sequences
$transChar[$j]=$transColor{$transChar[$j-1]}[$readNum[$j]];
$transString=$transString.$transChar[$j];
}
if (($transString=~ /(.*)AGAGTTTGAT$/) or ($transString=~ /^CCTGGCTCAG(.*)/) or ($transString=~/(.*)GACGGGCGGT$/) or ($transString=~/^GGTGWGTRCA(.*)/)){
if (length($1)>24){
$transString=$1; #filtre les primers.
}
else {$discard++;
next;}
}
mkdir "$threshold-$threshold2";
open (TRANS, ">>$threshold-$threshold2/$ARGV[0]");
print TRANS ">$nam\n$transString\n";
}
else { $discard++;
}
}
else {print "ne trouve pas les qualV associees a $nam!"}
}
else {
$discard++;
}
}
}
print "threshold min: ".$threshold." threshold max: ".$threshold2." total discarded reads: ".$discard; |
Partager