OUTPUT BUFFER:
#!/usr/bin/tclsh #package require profile proc ContenuDuFichier {{Fichier ""}} { if { $Fichier == "" } {return ""} set f [open $Fichier r] set Texte [read -nonewline $f] close $f return $Texte } proc LesLignesDuFichier {{Fichier ""}} { return [split [ContenuDuFichier $Fichier] "\n"] } proc EstUnAccessPDB Access { if { ! [regexp -nocase {^[0-9]+[a-z]+[0-9a-z_]*$} $Access] } { return 0 } if {[regexp -nocase {_[0-9a-z]{3,}} $Access] } { return 0 } return 1 } proc StringSuivant {Champ dans Texte} { set i [string first $Champ $Texte] if {$i==-1} { return "" } incr i [string length $Champ] return [string range $Texte $i end] } proc DecortiqueBlast {TexteOuListeOuFichier CutPN MaxListe aQuery {alBanqueId ""} {alAccess ""} {alDE ""} {alProfil ""} {alPN ""} {alPartieSegAli ""}} { global PourBallast if {$aQuery!="BlastHitCount" || $aQuery!="RetourneBlastTrie"} { if {$aQuery !=""} { upvar $aQuery Query } if {$alBanqueId !=""} { upvar $alBanqueId lBanqueId } if {$alAccess !=""} { upvar $alAccess lAccess } if {$alDE !=""} { upvar $alDE lDE } if {$alProfil !=""} { upvar $alProfil lProfil } if {$alPN !=""} { upvar $alPN lPN } } if {$alPartieSegAli != ""} { if { ! [string equal $alPartieSegAli "LongDefinition"]} { upvar $alPartieSegAli lPartieSegAli } set OnVeutPartieSegAli 1 set lPartieSegAli {} } else { set lPartieSegAli {} set OnVeutPartieSegAli 0 } set RetourneBlastTrie 0 if {$aQuery=="RetourneBlastTrie"} { set RetourneBlastTrie 1 } set Fichier "" if {[regexp "\n" $TexteOuListeOuFichier]} { set ListeDesLignes [split $TexteOuListeOuFichier "\n"] } elseif {[regexp " " $TexteOuListeOuFichier]} { set ListeDesLignes $TexteOuListeOuFichier } elseif {[file exists $TexteOuListeOuFichier]} { set Fichier $TexteOuListeOuFichier set ListeDesLignes [LesLignesDuFichier $TexteOuListeOuFichier] } else { return "" } if {$CutPN == "" } { set CutPN 0.001 } if {$MaxListe == "" } { set MaxListe "SansLimiteDeNombre" } if {$CutPN == "SansSeuilExpect"} { set CutPN 9999.9 } set RenvoieLesHitsAvecSegAliUniquement 1 if {$MaxListe == "SansLimiteDeNombreDuTout"} { set MaxListe "SansLimiteDeNombre" set RenvoieLesHitsAvecSegAliUniquement 0 } if {$MaxListe == "SansLimiteDeNombre"} { set MaxListe 9999 } set lBanqueId {} set lAccess {} set lDE {} set lProfil {} set lPN {} set NombreDeBons 0 set PremierMot "" scan [join [lrange $ListeDesLignes 0 3] " "] "%s" PremierMot set RechercheDansFichier 1 while {1} { set PourBlastP [expr ![string compare $PremierMot "BLASTP"]] set PourBlastX [expr ![string compare $PremierMot "BLASTX"]] set PourBallast [expr ![string compare $PremierMot "BALLAST"]] set PourTBlastX [expr ![string compare $PremierMot "TBLASTX"]] set PourBlastN [expr ![string compare $PremierMot "BLASTN"]] set PourTBlastN [expr ![string compare $PremierMot "TBLASTN"]] if {[expr $PourBlastP+$PourBlastX+$PourBallast+$PourTBlastX+$PourBlastN+$PourTBlastN] == 1} { break } if {$RechercheDansFichier && \ [regexp "BLASTP|BLASTX|Ballast|TBLASTX|BLASTN|TBLASTN" \ [join [lrange $ListeDesLignes 0 9] " "] PremierMot]} { set RechercheDansFichier 0 continue } return "" } if {$PourBallast} { set TexteSPSA "Sequences producing High-scoring Segment Pairs" set iProfil 62 set FinDE 65 } elseif {$PourTBlastX} { set TexteSPSA "Sequences producing High-scoring Segment Pairs" set FinDE 59 set iProfil 61 } else { set TexteSPSA "Sequences producing significant alignments" set FinDE 65 set iProfil 66 } set IndexQuery [lsearch -regexp $ListeDesLignes "Query="] if { $IndexQuery == -1 } { return "" } if {$aQuery=="BlastHitCount"} { set Query "NotImportantForBlastHitCount" set Nomquery "NotImportantForBlastHitCount" } else { set PossiblePAB [file tail $Fichier] # set Query [QueryDeLaLigne [lindex $ListeDesLignes $IndexQuery] "DoNotCreateIt" $PossiblePAB] # set NomQuery [file tail $Query] } if {[lsearch -regexp [lrange $ListeDesLignes 0 30] "No hits found"] != -1} { return 0 } set IndexSPSA [lsearch -regexp $ListeDesLignes $TexteSPSA] if { $IndexSPSA == -1 } { return 0} set Gapped [string equal [string index [lindex $ListeDesLignes $IndexSPSA] end] "N"] set Saut 2 if {[regexp -nocase {[a-z]} [lindex $ListeDesLignes [expr $IndexSPSA + 1]]]} { incr Saut } set PartieRestante [lrange $ListeDesLignes [incr IndexSPSA $Saut] end] set PartieEntete [lrange $ListeDesLignes 0 $IndexSPSA] set IndexPremierChevron [lsearch -regexp $PartieRestante {^>}] if { $IndexPremierChevron == -1 } { set PartieScores [lrange $PartieRestante 0 end] set PartieSegAli {} } else { set PartieScores [lrange $PartieRestante 0 [expr $IndexPremierChevron-1]] set PartieSegAli [lrange $PartieRestante $IndexPremierChevron end] } if {$Gapped} {set ICol 1} else {set ICol 0} set OldPN -99999 set zPN 0 set IlFautTrier 0 set EstUnPsiBlast 0 set Profil 0 set FautVider [expr ! $PourBallast] set LuPremier 0 foreach Ligne $PartieScores { if { $Ligne == "" } { continue } if { [regexp "Sequences not found previously" $Ligne] } { set EstUnPsiBlast 1 continue } regsub "!" $Ligne " " Ligne if { $PourBallast && [regexp {\-{50}} $Ligne]} { continue } if {! [regexp {[a-zA-Z]} $Ligne]} {continue} if { [regexp {\\\\End} $Ligne]} { break } if {! $PourBallast} {set FautVider 1} if { [regexp {^[0-9a-zA-Z]} $Ligne]} { if {$LuPremier} { lappend lBanqueId $oldBanqueId lappend lAccess $oldAccess lappend lProfil $oldProfil lappend lPN $oldPN lappend lScore $oldScore set oldDE [join $oldDE " "] lappend lDE $oldDE incr NombreDeBons } set LuPremier 1 set Access "" if {! [scan $Ligne "%s %s" BanqueId Access]} {break} set AccessLu $Access if {[regexp -nocase {^UniRef} $BanqueId]} { set Access $BanqueId } if {[regexp -nocase {[\(\)\{\}\[\]]} $Access]} { set Access $BanqueId } if {! [EstUnAccessPDB $Access] && \ ([EstUnAccessPDB $BanqueId] || ! [regexp -nocase {[a-z_]} $Access])} { set Access $BanqueId } set Profil [string equal [string range $Ligne $iProfil $iProfil] "*"] set ScorePN [string trim $Ligne] while {[regsub -all " " $ScorePN " " tmp]} {set ScorePN $tmp} set LesMots [split $ScorePN " "] set LesMots [lrange $LesMots 0 end-$ICol] set sScore [lindex $LesMots end-1] scan $sScore "%d" Score set sPN [lindex $LesMots end] if {$sScore=="" || $sPN==""} { break } set DE $Ligne set DE [StringSuivant "$BanqueId" dans $DE] if {! [EstUnAccessPDB $BanqueId] && ! [regexp -nocase {[^a-z0-9_]} $AccessLu] } { set DE [StringSuivant "$AccessLu" dans $DE] } regsub "$sPN *$" $DE "" DE regsub "$sScore *$" $DE "" DE regsub -all {"} $DE "" DE set DE [string trim $DE] set oldDE $DE set oldAccess $Access set oldBanqueId $BanqueId set oldProfil $Profil set oldScore $Score regsub {^[eE]} $sPN "1e" sPN set PN $sPN set oldPN $PN } else { if { ! $PourBallast} {continue} set Ligne [string trim $Ligne] if {! [scan $Ligne "%s %s" BanqueId Access]} {continue} lappend oldDE [string range $Ligne [string length "$BanqueId $Access "] end] continue } if {[catch { expr $PN > $CutPN } ]} {set PN 1E-200} if { ! $PourBallast && [expr $PN > $CutPN] } {break} if {$NombreDeBons >= $MaxListe } { break } } lappend lBanqueId $oldBanqueId lappend lAccess $oldAccess lappend lProfil $oldProfil lappend lPN $oldPN lappend lScore $oldScore set oldDE [join $oldDE " "] lappend lDE $oldDE incr NombreDeBons set LIndexChevron [lsearch -regexp -all $PartieSegAli {^>}] set n 0 set nDE {} set npris [llength $lDE] set iend [expr $npris - 1] set LIndexChevron [lrange $LIndexChevron 0 $iend] foreach i $LIndexChevron des $lDE { if {$n == [expr $npris - 1]} { set j "end" } else { set j [expr [lindex $LIndexChevron [expr $n + 1]] - 1] } set PartieSegAliRestante [lrange $PartieSegAli $i $j] set LeMeilleurDE {} foreach LigneDuSegAli $PartieSegAliRestante { if {! [regexp -nocase {[0-9a-z]} $LigneDuSegAli]} {break} set MeilleurDE [string trim $LigneDuSegAli] regsub {^>[^ ]+ } $MeilleurDE "" MeilleurDE lappend LeMeilleurDE $MeilleurDE } set newDE [join $LeMeilleurDE " "] while {[regsub -all " " $newDE " " tmp]} {set newDE $tmp} lappend nDE $newDE incr n } set lDE $nDE return } proc ValArg {e} { set e [string trim $e] set i [expr [string first "=" $e] + 1] return [string range $e $i end] } proc QueryDeLaLigne {LigneQuery {CreateIt ""} {PossiblePAB ""}} { global CreateQueryDeLaLigne if {$CreateIt=="CreateIt"} { set CreateIt 1 } elseif {$CreateIt=="DoNotCreateIt"} { set CreateIt 0 } else { if {[info exists CreateQueryDeLaLigne]} { set CreateIt $CreateQueryDeLaLigne } else { set CreateIt 1 } } set IndexBlanc [string first " " $LigneQuery] set LigneQuery [string trim [string range $LigneQuery $IndexBlanc end]] if { [regexp -indices {[, :\|]} $LigneQuery IndexesFin] } { set IndexFin [expr [lindex $IndexesFin 0]-1] } else { set IndexFin "end" } set Query [string trim [string range $LigneQuery 0 $IndexFin]] foreach TryQuery [list \ "$Query" \ "$RepertoireDuGenome/../casimir/prottfa/[file tail $Query]" \ "[RepertoireDeTravail]/[file tail $Query]" \ "$RepertoireDuGenome/nuctfa/[file tail $Query]" \ "$RepertoireDuGenome/prottfa/[file tail $Query]"] { if { [file exists $TryQuery] } { return $TryQuery } } if {$PossiblePAB!="" && [Alias $PossiblePAB]==$Query} { set Query $PossiblePAB } if { ! $CreateIt} { return $Query } set SequenceQuery [SequenceDesBanquesVite $Query] if {$SequenceQuery!=""} { set TmpQuery [Sauve $SequenceQuery dans "[RepertoireDeTravail]/[file tail $Query]"] return $TmpQuery } return $Query } proc EstTropLong d { global NbLg set i [expr [string first "Length = " $d] + 9] set pl1 [string range $d $i end] set ib [string first " " $pl1] if {$ib == -1} {set ib "end"} set l [string trim [string range $pl1 0 $ib]] if {$l > 10000 || [regexp {[^0-9]} $l] || $l == ""} { incr NbLg return 1 } else { return 0 } } proc EstUnFragment d { global NbFrg if {[regexp -nocase "fragment" $d]} { incr NbFrg return 1 } else { return 0 } } proc TriNature {e m la lp} { set n 0 set lbon {} foreach a $la p $lp { if {$n >= $m} {break} if {$p > $e} {break} lappend lbon $a incr n } return $lbon } proc TriMounir {e m la lp} { set i 0 set n 0 set palier 0. foreach p $lp { set pal($i) $p if {$p == "1e-200"} {set pal($i) 0.} set j [expr $i - 1] if {$i > 0 && [expr [set pal($i)] * [set pal($j)] ]} { set palier [expr $palier + log([set pal($i)]) - log([set pal($j)]) ] } incr i incr n } set palier [expr $palier / ($n - 1)] # puts "palier $palier pour $n" # prends toujours le premier set i 0 set nok 0 set liste {} while {($i < $n) && ($nok < $m)} { if {$i == 0} { lappend liste [lindex $la 0] set exprev [set pal(0)] incr nok } else { if {[set pal($i)] != 0.} { if {$exprev == 0.} { lappend liste [lindex $la $i] set exprev [set pal($i)] set difference 0. incr nok } else { set difference [expr log([set pal($i)])-log($exprev)] } # Si la difference est sup. au palier on prend la sequence if {$difference > $palier} { lappend liste [lindex $la $i] set exprev [set pal($i)] incr nok } } } incr i } return $liste } proc RajoutBallast {bfile liste e m} { set LBlast [LesLignesDuFichier $bfile] DecortiqueBlast $LBlast 9999. 5000 Query lBanqueId lAccess lDE lProfil lPN "LongDescription" set nelt [llength $liste] set nmax [expr $nelt / 2] if {[expr $nelt + $nmax] > $m} { set nrajout [expr $m - $nelt] } else { set nrajout $nmax } set npris 0 foreach p $lPN a $lBanqueId des $lDE { if {$npris >= $nrajout} {break} if {$p < $e} {continue} if {[EstTropLong $des]} {continue} if {[EstUnFragment $des]} {continue} lappend liste $a incr npris } return $liste } proc FaitLesTris liste { global NbLg global NbFrg set args [string trim $liste] regsub -all " " $args " " args set args [split $args " "] if {[llength $args] < 2} { puts "\nUsage : filter" puts "\t-input=