#rR gscope_projet.tcl #rR Où l'on crée des projets gscope automatiquement ... #rR La creation d'un projet doit être faite en 2 temps #rR D'abord par un autre Gscope existant pour créer le repertoire et y mettre le fasta #rR Puis on peut faire par QuestionDeScience proc CreateHitFiles {} { foreach a b { } } proc MissBlastP {} { #rR A ne pas confondre avec MissBlast où on fouille dans les resultats des blast de OI2017 #rR Ici on veut simplement savoir pourquoi certains blast n'ont pas été créés. set LesNomsSeq {} foreach Nom [ListeDesPABs] { set FichierBlast [GscopeFile $Nom "blastp"] if {[FileExists $FichierBlast]} { continue } set FichierTfa [GscopeFile $Nom "prottfa"] set Seq [QueLaSequenceDuFichierTFA $FichierTfa] Espionne "$Nom $Seq" lappend LesNomSeq "$Nom $Seq" } return $LesNomSeq } proc RelanceGrilladin {} { #rR On ne fournit au Grilladin que ceux qui manquent ... dans le nouveau répertoire ProttfaCourant NousAllonsAuBoulot [RepertoireDuGenome] set ProttfaCourant "prottfa_[Date]" file mkdir $ProttfaCourant foreach Nom [ListeDesPABs] { if {[FileExists [GscopeFile $Nom blastp]]} { continue } file copy [GscopeFile $Nom prottfa] [GscopeFile $Nom $ProttfaCourant] } set Reponse [CompleteBlastGscopeProject "" "" $ProttfaCourant] OnRevientDuBoulot return $Reponse } proc CreeBlastDatabaseForUniprot {{Rep ""}} { #rR ceci sert surtout de pense-bête ... if {$Rep==""} { set Rep "./" } NousAllonsAuBoulot $Rep foreach B [list sprot trembl] { lappend LesCommandes "curl 'ftp://ftp.uniprot.org/pub/databases/uniprot/current_release/knowledgebase/complete/uniprot_${B}.fasta.gz' -o uniprot_${B}.fasta.gz" lappend LesCommandes "gunzip uniprot_${B}.fasta.gz" lappend LesCommandes "mv uniprot_${B}.fasta ${B}SansOX" lappend LesCommandes "gscope yes FastaForBlast NewFastaFile - ${B}SansOX ${B}" lappend LesCommandes "ls " lappend LesCommandes "gscope yes CompleteCreateBlastDatabaseWithFasta $B $B" } set LesCommandesToDo [split [AfficheListe $LesCommandes "AvecRetour"] "\n"] EspionneL $LesCommandesToDo foreach Commande $LesCommandesToDo { Espionne $Commande if {[regexp "^gscope yes" $Commande]} { regsub "gscope yes " $Commande "" Commande eval $Commande } else { eval exec $Commande } Espionne "$Commande done" } OnRevientDuBoulot return "coucou" } proc BlastomicsDb {{Qui ""} {Quoi ""}} { #rR on interroge ici toutes les bases Sqlite de BlastomicsDbDir #rR et on met tout en mémoire #rR Chaque projet peut avoir plusieurs Paraphylums associés EHomsa_CMC et EHomsa_TTLL #rR Chaque Paraphylum evidemment pluisieurs projets global BlastomicsDb if {[info exists BlastomicsDb($Qui,$Quoi)]} { return $BlastomicsDb($Qui,$Quoi) } if {[info exists BlastomicsDb("EstCharge")]} { return "" } set BlastomicsDb("EstCharge") 1 set LesDb [lsort [glob -nocomplain [BlastomicsDbDir]/*.db]] foreach Db $LesDb { if {[catch {set NbOrga [SqlExecForDatabase $Db "select count(*) from organism" "GetFirstValue"]} ]} { continue } set Queue [file tail $Db] if { ! [regexp {^([^_]+)_([^\.]+)\.db$} $Queue Match Science Paraphylum]} { FaireLire "$Db non valide" } regsub {\.db$} $Queue "" DbName lappend BlastomicsDb(ListOf,Db) $Db lappend BlastomicsDb(ListOf,DbName) $DbName set BlastomicsDb($DbName,Db) $Db lappend BlastomicsDb(ListOf,Science) $Science lappend BlastomicsDb(ListOf,Paraphylum) $Paraphylum lappend BlastomicsDb($Science,ListOfDb) $Db lappend BlastomicsDb($Science,ListOfDbName) $DbName lappend BlastomicsDb($Science,ListOfParaphylum) $Paraphylum lappend BlastomicsDb($Paraphylum,ListOfScience) $Science set BlastomicsDb($DbName,ListOfClade) [SqlExecForDatabase $Db "select nom from clade" "GetList"] foreach Clade $BlastomicsDb($DbName,ListOfClade) { set SqlOX "select taxid from organism, clade, ln_clade_organism where \ clade.nom = '$Clade' and \ clade.pk_clade = ln_clade_organism.pk_clade and \ ln_clade_organism.pk_organism = organism.pk_organism" #Espionne $SqlOX set BlastomicsDb($DbName-$Clade,ListOfOX) [SqlExecForDatabase $Db $SqlOX "GetList"] #Espionne $BlastomicsDb($Queue-$Clade,ListOfOX) regsub taxid $SqlOX specie SqlOS set BlastomicsDb($DbName-$Clade,ListOfOS) [SqlExecForDatabase $Db $SqlOS "GetList"] } set BlastomicsDb($Db,NbOrga) $NbOrga foreach DirTaxobla [TaxoblaProjects $Science ListOfDirTaxobla] { set NbO [TaxoblaProjects $Science-$DirTaxobla NbOrga] } } set BlastomicsDb(ListOf,Science) [lsort -unique $BlastomicsDb(ListOf,Science)] set BlastomicsDb(ListOf,Paraphylum) [lsort -unique $BlastomicsDb(ListOf,Paraphylum)] foreach Science $BlastomicsDb(ListOf,Science) { set BlastomicsDb($Science,ListOfParaphylum) [lsort -unique $BlastomicsDb($Science,ListOfParaphylum)] } foreach Paraphylum $BlastomicsDb(ListOf,Paraphylum) { set BlastomicsDb($Paraphylum,ListOfScience) [lsort -unique $BlastomicsDb($Paraphylum,ListOfScience)] } return [BlastomicsDb $Qui $Quoi] } proc BlastomicsProjects {{Qui ""} {Quoi ""}} { foreach Science [TaxoblaProjects ListOf Science] { foreach DirTaxobla [TaxoblaProjects $Science ListOfDirTaxobla] { set } } } proc TaxoblaProjects {{Qui ""} {Quoi ""}} { #rR C'est dément ... ça marche je crois ... (2018/01/09) #rR On fait ici la liste des projets taxobla : .. il existe un répertoire taxobla .. Plus ou moins rempli #rR On mémorise tout ça dans FicMemo mia son peut le refaire par TaxoblaProjects ReDo #rR Je vous laisse apprécier :) global TaxoblaProjects if {[regexp {^(ReDo|ReLoad)_} $Qui]} { if {[info exists TaxoblaProjects]} { unset TaxoblaProjects } } if {[info exists TaxoblaProjects($Qui,$Quoi)]} { return $TaxoblaProjects($Qui,$Quoi) } if {[info exists TaxoblaProjects("EstCharge")]} { return "" } set TaxoblaProjects("EstCharge") 1 set FicMemo "/genomics/link/CilioCarta/fiches/BlastomesProjects.txt" if {[regexp {^ReDo_} $Qui] && [file exists $FicMemo]} { file delete $FicMemo } regsub {^(ReDo|ReLoad)_} $Qui "" Qui if {[file exists $FicMemo]} { array set TaxoblaProjects [ContenuDuFichier $FicMemo] ; return [TaxoblaProjects $Qui $Quoi] } set TaxoblaProjects(ListOf,Science) {} set TaxoblaProjects(ListOf,Go) {} set TaxoblaProjects(ListOf,Taxobla) {} set LesRepTaxobla [lsort [glob -nocomplain "/genomics/link/*/taxobla"]] set LesMyGOsFromGene [lsort [glob -nocomplain "/genomics/link/*/fiches/MyGOsFromGene.txt"]] set LesMyGenesFromGo [lsort [glob -nocomplain "/genomics/link/*/fiches/MyGenesFromGo.txt"]] set LesSciences {} foreach RepTaxobla $LesRepTaxobla { set Science [file tail [file dirname $RepTaxobla]] lappend LesSciences $Science } foreach MyGOsFromGene $LesMyGOsFromGene { set Science [file tail [file dirname [file dirname $MyGOsFromGene]]] lappend LesSciences $Science } foreach MyGenesFromGo $LesMyGenesFromGo { set Science [file tail [file dirname [file dirname $MyGenesFromGo]]] lappend LesSciences $Science } set LesSciences [lsort -unique $LesSciences] set TaxoblaProjects(ListOf,Science) $LesSciences set TaxoblaProjects(ListOf,Info) {} set FormatHeader "%-12s %-10s %-8s %9s %9s %9s %9s %9s %-30s %-30s %-12s %12s %12s %11s %6s %-12s %s" set FormatData "%-12s %-10s %-8s %9d %9d %9d %9d %9d %-30s %-30s %-12s %12d %12d %11d %6d %-12s %s" lappend TaxoblaProjects(ListOf,Info) [format $FormatHeader Science Prefixe Status prottfa blastp taxobla GoWithGn GnWithGO DirTaxobla DirBlastp Blast NbSeq NbLetters NbSeqTotal NbOrga Winner BlastDatabase] foreach Science $TaxoblaProjects(ListOf,Science) { set RG "/genomics/link/$Science" set Miniconfig [ContenuDuFichier $RG/beton/miniconfig] set Prefixe [StringApres "PrefixeDesORFs " dans $Miniconfig] set NbProttfa 0 set RepProttfa "$RG/prottfa" if {[file exists $RepProttfa]} { set NbProttfa [llength [glob -nocomplain "$RepProttfa/$Prefixe*"]] } set NbGo 0 set FicMyGenesFromGo "$RG/fiches/MyGenesFromGo.txt" if {[file exists $FicMyGenesFromGo]} { set NbGo [regexp -all {\,Noms} [ContenuDuFichier $FicMyGenesFromGo]] } set NbGn 0 set FicMyGOsFromGene "$RG/fiches/MyGOsFromGene.txt" if {[file exists $FicMyGOsFromGene]} { set NbGn [regexp -all {\,GOs} [ContenuDuFichier $FicMyGOsFromGene]] } set TaxoblaProjects($Science,Prefixe) $Prefixe set TaxoblaProjects($Science,NbGo) $NbGo set TaxoblaProjects($Science,NbGn) $NbGn foreach RepTaxobla [glob -types d -nocomplain "$RG/taxobla*"] { if {[file type $RepTaxobla]=="link"} { continue } NousAllonsAuBoulot $RepTaxobla set PlusLong [exec sh -c "wc -l $Prefixe* | sort -k 1 -n -r | head -2"] OnRevientDuBoulot set NbSeqTotal -1 set NbOrga -1 set Gagnant "" lassign [LesMotsDuTexte $PlusLong] NbSeqTotal total NbOrga Gagnant regsub taxobla $RepTaxobla blastp RepBlastp set Premier "" set Database "" set EncoreUne 0 set NbSeq -1 set NbLet -1 if {[FileAbsent $RepBlastp]} { set RepBlastp "" } else { set Premier [lindex [lsort [glob -nocomplain "$RepBlastp/$Prefixe*"]] 0] set OnAttend 1 foreach Ligne [LesPremieresLignesDuFichier $Premier 50] { if {$EncoreUne} { regsub -all "," $Ligne "" Ligne lassign [LesMotsDuTexte $Ligne] NbSeq Bidon NbLet break } if {$OnAttend && ! [regexp {^Database: } $Ligne]} { continue } set OnAttend 0 set Database [StringApres "Database:" dans $Ligne] set EncoreUne 1 } set Premier [file tail $Premier] } set NbTaxobla 0 if {[file exists $RepTaxobla]} { set NbTaxobla [llength [glob -nocomplain "$RepTaxobla/$Prefixe*"]] } set NbBlastp 0 set RepBlastp "bidon" regsub taxobla $RepTaxobla blastp RepBlastp if {[file exists $RepBlastp]} { set NbBlastp [llength [glob -nocomplain "$RepBlastp/$Prefixe*"]] } set TaxoblaProjects($Science,NbTaxobla) $NbTaxobla set TaxoblaProjects($Science,NbBlastp) $NbBlastp set Missing "" if {$NbTaxobla<$NbBlastp} { set Missing "[expr $NbBlastp-$NbTaxobla] are missing :'(" } set Status 0 if {$NbProttfa < 1 } { incr Status 10000 } if {$NbBlastp < $NbProttfa} { incr Status 1000 } if {$NbTaxobla < $NbBlastp } { incr Status 100 } if {$NbGo < 1 } { incr Status 10 } if {$NbGn < 1 } { incr Status 1 } set Status [format "%5.5d" $Status] regsub -all "0" $Status "." Status regsub -all {[1-9]} $Status "X" Status set DirTaxobla [file tail $RepTaxobla] set DirBlastp [file tail $RepBlastp] lappend TaxoblaProjects(ListOf,Info) [format $FormatData $Science $Prefixe $Status $NbProttfa $NbBlastp $NbTaxobla $NbGo $NbGn $DirTaxobla $DirBlastp $Premier $NbSeq $NbLet $NbSeqTotal $NbOrga $Gagnant $Database] lappend TaxoblaProjects($Science,ListOfRepTaxobla) $RepTaxobla lappend TaxoblaProjects($Science,ListOfDirTaxobla) $DirTaxobla lappend TaxoblaProjects($Science,ListOfRepBlastp) $RepBlastp lappend TaxoblaProjects($Science,ListOfDirBlastp) $DirBlastp lappend TaxoblaProjects($Science,ListOfNbOrga) $NbOrga set TaxoblaProjects($Science-$DirTaxobla,Status) $Status set TaxoblaProjects($Science-$DirTaxobla,NbProttfa) $NbProttfa set TaxoblaProjects($Science-$DirTaxobla,NbBlastp) $NbBlastp set TaxoblaProjects($Science-$DirTaxobla,NbTaxobla) $NbTaxobla set TaxoblaProjects($Science-$DirTaxobla,NbSeq) $NbSeq set TaxoblaProjects($Science-$DirTaxobla,NbLet) $NbLet set TaxoblaProjects($Science-$DirTaxobla,NbSeqTotal) $NbSeqTotal set TaxoblaProjects($Science-$DirTaxobla,NbOrga) $NbOrga } if {0 && [incr X 1]>5} { break } } set TaxoblaProjects(TextOf,Info) [join $TaxoblaProjects(ListOf,Info) "\n"] set TaxoblaProjects(,) $TaxoblaProjects(TextOf,Info) Sauve [array get TaxoblaProjects] dans $FicMemo file attribute $FicMemo -permissions 0777 return [TaxoblaProjects $Qui $Quoi] } proc GrilladesEnCours {{Qui ""} {Quoi ""}} { global GEC #rR Attention c'est pas très clair : OI utilise surtout les liens et ici on se sert des fichiers dans fiches. A CLARIFIER !!!" if {[info exists GEC($Qui,$Quoi)]} { if {[PourWscope]} { return [join $GEC($Qui,$Quoi) "\n"] } return $GEC($Qui,$Quoi) } if {[info exists GEC("EstCharge")]} { return "" } set GEC("EstCharge") 1 set GEC(ListOf,Science) {} set GEC(ListOf,PP) {} set GEC(ListOf,PassePlat) {} #rR les passeplats sont tries ... du coup c'est le dernier qui est pris en compte pour une science set LesFichesPassePlats [lsort [glob -nocomplain "/genomics/link/*/fiches/PassePlat_*"]] set LesScience {} foreach FichePassePlat $LesFichesPassePlats { Espionne $FichePassePlat set Science [file tail [file dirname [file dirname $FichePassePlat]]] set PassePlat [ContenuDuFichier $FichePassePlat] set GEC($Science,PassePlat) $PassePlat set PP [file tail $PassePlat] set GEC($PP,Science) $Science lappend GEC(ListOf,Science) $Science lappend GEC(ListOf,PP) $PP lappend GEC(ListOf,PassePlat) $PassePlat } set GEC(ListOf,Info) {} foreach Science $GEC(ListOf,Science) { set LienPP "/genomics/link/$Science/fiches/passeplat" set PassePlat $GEC($Science,PassePlat) set NbGrillades [llength [glob -nocomplain "$PassePlat/blastp/*"]] set GEC($Science,NbGrillades) $NbGrillades if { ! [file exists $LienPP]} { if {[OuiOuNon "$LienPP does not exist. Do I create it ?" 0] } { file link -symbolic $LienPP "$PassePlat/blastp" } } lappend GEC(ListOf,Info) [format "%-10s %6d on %s" $Science $NbGrillades $PassePlat] } set GEC(,) [join $GEC(ListOf,Info) "\n"] return [GrilladesEnCours $Qui $Quoi] } proc RetourGrilladin {} { set LesFichesPassePlats [lsort [glob "[RepertoireDuGenome]/fiches/PassePlat*"]] set PassePlat [ContenuDuFichier [lindex $LesFichesPassePlats end]] set RepBlastPP "$PassePlat/blastp" set LesNouveaux {} file mkdir "[RepertoireDuGenome]/blastp" foreach F [lsort [glob "$RepBlastPP/[PreFixe]*"]] { set Queue [file tail $F] set B "[RepertoireDuGenome]/blastp/$Queue" if {[file exists $B]} { continue } lappend LesNouveaux $Queue file copy $F $B } return $LesNouveaux } proc CreateGscopeProjectWithFasta {{FastaFile ""} {ProjName ""}} { set RepGen "/gstock/$ProjName" set RepGenLink "/genomics/link/$ProjName" if {[file exists $RepGen] || [file exists $RepGenLink]} { if { ! [OuiOuNon "$RepGen or $RepGenLink already exists. Do I continue anyway ?" 1]} { return "" } } if {[FileAbsent $RepGen]} { file mkdir $RepGen } if {[FileAbsent $RepGenLink]} { file link -symbolic $RepGenLink $RepGen} set DeDir "$RepGenLink/DeWeb" file mkdir $DeDir set FastaName [file tail $FastaFile] set Destin $DeDir/$FastaName if {[FileAbsent $Destin]} { file copy $FastaFile $Destin } return $Destin } proc ValidBlastDatabaseForHotdog {BlastDatabase} { return [ValidBlastDatabaseForGrilladin $BlastDatabase] } proc ValidBlastDatabaseForGrilladin {BlastDatabase} { return 1 return [string equal $BlastDatabase "Proteome201501"] } proc CompleteGscopeProjectWithFasta {{FastaFile ""} {ProjName ""} {Prefixe ""} {NbDigit ""} {OS ""} {OX ""} {OC ""} {BlastDatabase ""}} { #rR est lancé en QDS if {$NbDigit=="."} { set NbDigit "" } if {$OS=="."} { set OS "" } if {$OX=="."} { set OX "" } if {$OC=="."} { set OC "" } if {$OX!="" && $OS==""} { set OS [Tax $OX Name] } if {$OS!="" && $OX==""} { set OX [Tax $OS TaxId] } if {$OX!="" && $OC==""} { set OC [TaxClass $OX Name] } if {$OS!="" && $OC==""} { set OC [TaxClass $OS Name] } regsub "^root; cellular organisms; " $OC "" OC if {[PasTouche "CompleteGscopeProjectWithFasta"]} { return "Sorry. CompleteGscopeProjectWithFasta is still running" } if {$NbDigit==""} { set NbDigit 5 } CreeFichierMiniConfig $Prefixe $NbDigit Prot $OX CreeLaCollection TFA $FastaFile "" KeepEntete "No" "No" # AllForGo LogWscope "BlastDatabase=$BlastDatabase" set PassePlat "" if {[ValidBlastDatabaseForGrilladin $BlastDatabase]} { set ProjNameWithDate "${ProjName}_[Date]" set DBSizeTxt [BlastDatabaseSize $BlastDatabase] scan $DBSizeTxt "%d" DBSize set NSeqPerJob 200 set PassePlat [Grillade::creerPoeleBlast ProjectName $ProjNameWithDate InputDir "[RepertoireDuGenome]/prottfa" DB $BlastDatabase DBsize $DBSize NSeqPerJob $NSeqPerJob] AppendAuFichier [Fiches PassePlat_$ProjNameWithDate] $PassePlat } else { LogWscope "$BlastDatabase invalid" } FinPasTouche "CompleteGscopeProjectWithFasta" set Message "OK. Most of the job is done for CompleteGscopeProjectWithFasta." if {$PassePlat!=""} { append $Message "Blast files will be available at $PassePlat" } return $Message } proc CompleteCreateBlastDatabaseWithFasta {{FastaFile ""} {BlastDatabaseName ""}} { if {$BlastDatabaseName==""} { set BlastDatabaseName [file tail $FastaFile] } ;#rR 2016/11/07 LogWscope "CompleteCreateBlastDatabaseWithFasta $FastaFile $BlastDatabaseName" set Logfile $BlastDatabaseName.formatdb.log exec formatdb -i $FastaFile -p T -n $BlastDatabaseName -l $Logfile -o T if {[FileAbsent $Logfile]} { set Message "Error. Something went wrong with CompleteCreateBlastDatabaseWithFasta. I didn't got the log file" } elseif {[FileAbsent $BlastDatabaseName.phr] && [FileAbsent $BlastDatabaseName.pal]} { set Message "Error. Something went wrong with CompleteCreateBlastDatabaseWithFasta. I didn't got the result. Log file contents [ContenuDuFichier $Logfile]" } else { set Message "OK. The BlastDatabase should be available at $BlastDatabaseName." } LogWscope $Message return $Message } proc CompleteTaxoblaGscopeProject {{FromOi ""}} { #rR est normalement lancé en QDS if {$FromOi=="FromOi"} { LogWscope "CompleteTaxoblaGscopeProject $FromOi" set LesFicTax [TaxoblaFromOi] return "[llength $LesFicTax] taxobla files were created" } TaxonomyDuBlastPourTous return "OK, TaxonomyDuBlastPourTous done" } proc CompleteRetourGrilladinGscopeProject {} { #rR est lancé en QDS RetourGrilladin return "OK, RetourGrilladin done" } proc CompleteBlastGscopeProject {{ProjName ""} {BlastDatabase ""} {ProttfaCourant ""}} { #rR est lancé en QDS ?????????????, if {$ProttfaCourant==""} { set ProttfaCourant "prottfa" } if {$BlastDatabase==""} { set BlastDatabase [LocaliseBlastPDataBase] } if {$ProjName==""} { set ProjName [file tail [RepertoireDuGenome]] } if {[PasTouche "CompleteBlastGscopeProject"]} { return "Sorry. CompleteBlastGscopeProject is still running" } set PassePlat "" if {[ValidBlastDatabaseForGrilladin $BlastDatabase]} { set ProjNameWithDate "${ProjName}_[Date]" set DBSizeTxt [BlastDatabaseSize $BlastDatabase] scan $DBSizeTxt "%d" DBSize Espionne "Grillade::creerPoeleBlast ProjectName $ProjNameWithDate Input [RepertoireDuGenome]/$ProttfaCourant DB $BlastDatabase DBsize $DBSize" set PassePlat [Grillade::creerPoeleBlast ProjectName $ProjNameWithDate Input [RepertoireDuGenome]/$ProttfaCourant DB $BlastDatabase DBsize $DBSize] if {[regexp -nocase "^Error" $PassePlat]} { set Message "Error. Something is wrong with Grilladin. I got the error message $PassePlat" } #rR Tcl ne veut pas pointer si la cible n'existe pas :file link -symbolic "[RepertoireDuGenome]/passeplat" "$PassePlat/blastp" exec ln -sf "$PassePlat/blastp" "[RepertoireDuGenome]/passeplat" AppendAuFichier [Fiches PassePlat_$ProjNameWithDate] $PassePlat set Message "Warning. I launched Grilladin for $ProjName. Blast files will be available at $PassePlat" return $Message } else { set Message "Error. Sorry the blast database '$BlastDatabase' is not a valid blast database for Grilladin" } LogWscope $Message FinPasTouche "CompleteBlastGscopeProject" return $Message } proc CreateGscopeProjectWithOi {Source OiName {SpOnly ""}} { if {$SpOnly ==""} { set SpOnly 0 } set FichierFasta [CreateGscopeProjectFromOiName $Source $OiName $SpOnly] return $FichierFasta } proc CompleteGscopeProjectWithOi {Source OiCode FichierFasta {NbDigit ""}} { #rR est lancé en QDS if {[PasTouche "CompleteGscopeProjectWithOi"]} { return "Sorry. CompleteGscopeProjectWithOi is still running" } if {$NbDigit==""} { set NbDigit 5 } if {$Source=="OiOld"} { set OX [OiName $OiCode OX] } else { #rR Source est OiArchaea ou OiEukaryota set Domain [string range $Source 2 end] set OX [OiCodeForDomain $Domain $OiCode OX] } CreeFichierMiniConfig $OiCode $NbDigit Prot $OX CreeLaCollection TFA $FichierFasta "" KeepEntete "No" "No" AllForGo NIAG FinPasTouche "CompleteGscopeProjectWithOi" return "OK. All is done for CompleteGscopeProjectWithOi" } proc SpOnlyFromFasta {Fasta NewFasta} { set LeNew {} set LeTFA {} foreach Ligne [LesLignesDuFichier $Fasta] { if { ! [regexp ">" $Ligne]} { lappend LeTFA $Ligne ; continue } if {[regexp "BANK=sp" $LeTFA]} { lappend LeNew [join $LeTFA "\n"] } set LeTFA {} lappend LeTFA $Ligne } return [SauveLesLignes $LeNew dans $NewFasta] } proc BestGN Nom { if {[set ValiGN [ExtraitInfo $Nom "ValiGN:"]] !=""} { return $ValiGN } if {[set GN [ExtraitInfo $Nom "GN:"]] !=""} { return $GN } if {[set DraftGN [ExtraitInfo $Nom "DraftGN:"]]!=""} { return $DraftGN } return "" } proc BestDE Nom { if {[set ValiDE [ExtraitInfo $Nom "ValiDE:"]] !=""} { return $ValiDE } if {[set DE [ExtraitInfo $Nom "DE:"]] !=""} { return $DE } if {[set DraftDE [ExtraitInfo $Nom "DraftDE:"]]!=""} { return $DraftDE } return "" } proc InformeFromOiPourTous {} { if { ! [OuiOuNon "Merci de vérifier cette proc, elle est peut-être obsolète. Il faut peut etre mettre ValiGN ou GN DraftGN. \nJe le fais quand même ?"]} { return "" } foreach Nom [ListeDesPABs] { set FicTfa [GscopeFile $Nom prottfa] set Header [PremiereLigneDuFichier $FicTfa] set Gn [StringApres "GN=" dans $Header] if {[regexp "DRAFT_" $Gn]} { InformeSansDemander $Nom "=DraftGN: $Gn" ; set Gn "" } if {$Gn=="Fragment"} { set Gn "" } regsub "GN=.+" $Header "" Debut set LesMots [LesMotsDuTexte $Debut] set Id [lindex $LesMots 1] set Ac [lindex $LesMots 2] set De [join [lrange $LesMots 5 end] " "] if {[regexp {\|} $Id]} { lassign [split $Id "|"] B A I set Id $I set Ac $A set Ba $B set De [join [lrange $LesMots 2 end] " "] } if {$Id!=""} { InformeSansDemander $Nom "=ID: $Id" } if {$Ac!=""} { InformeSansDemander $Nom "=AC: $Ac" } if {$Gn!=""} { InformeSansDemander $Nom "=GN: $Gn" ; InformeSansDemander $Nom "=Alias: $Gn"} if {$De!=""} { InformeSansDemander $Nom "=DE: $De" } } return "" } proc CreateGscopeProjectFromOiName {{Source ""} {OiName ""} {SpOnly ""}} { JeMeSignale #rR Attention ici OiName peut aussi être OiCode ............ mais je laisse OiName en nom de variable if {$Source=="OiOld"} { set UseOiCode 0 } else { set UseOiCode 1 } if {$SpOnly==""} { set SpOnly [OuiOuNon "Do I use only Swissprot (I'll test BANK=sp in the protein headers)" 0] } while {$OiName==""} { if {$UseOiCode} { set Info [ChoixParmi [OiCode ListOf Info]] } else { set Info [ChoixParmi [OiName ListOf Info]] } if {$Info==""} { if {[OuiOuNon "Do I skip CreateGscopeProjectFromOiName"]} { return "" } continue } scan $Info "%s" OiName } set RepGen "/gstock/$OiName" set RepGenLink "/genomics/link/$OiName" if {[file exists $RepGen] || [file exists $RepGenLink]} { if { ! [OuiOuNon "$RepGen or $RepGenLink already exists. Do I continue anyway ?" 1]} { return "" } } if {[FileAbsent $RepGen]} { file mkdir $RepGen } if {[FileAbsent $RepGenLink]} { file link -symbolic $RepGenLink $RepGen} set DeOiDir $RepGenLink/DeOi file mkdir $DeOiDir if {$UseOiCode} { set FastaFile [OiCode $OiName FullFilePath] set FastaName [OiCode $OiName OI] set OX [OiCode $OiName OX] } else { set FastaFile [OiName $OiName Fasta] set FastaName [OiName $OiName Orga] set OX [OiName $OiName OX] } set Destin $DeOiDir/$FastaName Espionne "file copy $FastaFile $Destin" if {[FileAbsent $Destin]} { file copy $FastaFile $Destin } if {$SpOnly} { set AllBanks "${Destin}_AllBanks" file rename $Destin "$AllBanks" SpOnlyFromFasta $AllBanks $Destin } set OS [Tax $OX Name] set OC [TaxClass $OX Name] regsub "^root; cellular organisms; " $OC "" OC return $Destin } proc CreateBlastDatabasesForDir {{Dir ""} {Titre ""} {OutFilename ""}} { #rR Je ne sais pas où on s'en sert ... à creuser (2016/07/25) #rR On crée les banques blast à deux niveaux .. faudrait le faire récursif ... #rR on crée les banques pour chaque fasta #rR puis un .nal pour cette banque #rR Puis un .nal du nom du répertoire qui contient tous ces .nhr #rR Et tout en haut le .nal qui contient les .nal des sous-répertoires if {$Titre ==""} { set Titre "GenomesFor[file tail [RepertoireDuGenome]]" } if {$OutFilename==""} { set $OutFilename $Titre } if {$Dir==""} { set Dir "[RepertoireDuGenome]/Genomes" } NousAllonsAuBoulot $Dir set LesFastaFile [glob -nocomplain */*{.fsa,.fna}*] set LesNal {} foreach FastaPath $LesFastaFile { set SubDir [file dirname $FastaPath] set FastaFile [file tail $FastaPath] NousAllonsAuBoulot $SubDir regsub {(\.fsa|\.fna)} $FastaFile "" Name Espionne $FastaFile Espionne $Name if { ! [file exists $Name.nhr]} { exec formatdb -p F -o T -i $FastaFile -n $Name -l $Name.log } if { ! [file exists $SubDir.nal]} { set LesNhr [lsort -dictionary [glob "*.nhr"]] set LesSousBanques {} foreach Nhr $LesNhr { regsub {\.nhr$} $Nhr "" Banque lappend LesSousBanques $Banque } set DbList [join $LesSousBanques " "] set LeNal {} lappend LeNal "#" lappend LeNal "# Alias file created by Gscope CreateBlastDatabasesForDir [Date Nice]" lappend LeNal "#" lappend LeNal "TITLE $SubDir" lappend LeNal "#" lappend LeNal "DBLIST $DbList" lappend LeNal "#" SauveLesLignes $LeNal dans $SubDir.nal } lappend LesNal $SubDir/$SubDir.nal OnRevientDuBoulot } set LesSousBanques {} foreach Nal $LesNal { regsub {\.nal$} $Nal "" Banque lappend LesSousBanques $Banque } set DbList [join $LesSousBanques " "] lappend LeNal "#" lappend LeNal "# Alias file created by Gscope CreateBlastDatabasesForDir [Date Nice]" lappend LeNal "#" lappend LeNal "TITLE $Titre" lappend LeNal "#" lappend LeNal "DBLIST $DbList" lappend LeNal "#" SauveLesLignes $LeNal dans $Titre.nal OnRevientDuBoulot return $Dir/$Titre.nal } proc BlastTestDir {} { set BlastTestDir "/blast/BlastTest" return $BlastTestDir } proc BlastDatabaseSizeNice {B {DoBlastIfNecessary ""} {DefaultSize ""}} { return [BlastDatabaseSize $B $DoBlastIfNecessary $DefaultSize "Nice"] } proc BlastDatabaseSize {B {DoBlastIfNecessary ""} {DefaultSize ""} {Nice ""}} { #rR Rend le nombre de séquences et le nombre de lettres si on le trouve N L sinon N #rR Initialement écrit par Mickael Joly #rR S'il existe un blast déjà fait sur cette base on va y chercher la taille #rR Sinon on va voir dans formatdb.log #rR Si c'est un .pal on cumule les tailles des sousbases set Info [exec /biolo/blast/bin/blastdbcmd -info -db $B] if { [regexp {([0-9\,]+) sequences; ([0-9\,]+) total residues} $Info Match NbSeq NbRes]} { regsub -all {\,} $NbSeq "" NbSeq regsub -all {\,} $NbRes "" NbRes return "$NbRes letters $NbSeq sequences" } set BlastTestDir "/blast/BlastTest" if {$DefaultSize==""} { set DefaultSize 3608421 } if { ! [regexp "^/" $B]} { set B "/blast/$B" } set queue [file tail $B] set FichierBlast "[BlastTestDir]/$queue.test.blast" if {[file exists $FichierBlast]} { if {[regexp {([0-9\,]+) sequences} [ContenuDuFichier $FichierBlast] Match NAV]} { regsub -all "\," $NAV "" N if {[regexp {([0-9\,]+) total letters} [ContenuDuFichier $FichierBlast] Match LAV]} { regsub -all "\," $LAV "" L return "$L letters $N sequences" } return $N } } else { if {[string equal -nocase "DoBlastIfNecessary" $DoBlastIfNecessary] || [OuiOuNon "$FichierBlast does not exist ... Do I create it ... It will take some time" 0]} { set FichierQuery "[BlastTestDir]/queryBidon.tfa" set creationBlast [BlastForTest $FichierQuery $FichierBlast $B] set Size [BlastDatabaseSize $B $DefaultSize] return $Size } } set FicFormat "$B.formatdb.log" set total 0 if {[file exists $FicFormat]} { foreach Ligne [LesLignesDuFichier $FicFormat] { if {![regexp {Formatted ([0-9]+) sequences} $Ligne Match N]} {continue} incr total $N } return $total } foreach Ext {pal nal} { set FicPal "$B.$Ext" Espionne $FicPal set total 0 if {[FileAbsent $FicPal]} { continue } set Dir [file dirname $FicPal] foreach Ligne [LesLignesDuFichier $FicPal] { if {![regexp {^DBLIST } $Ligne]} {continue} regsub -all {[ \t]+} $Ligne " " Ligne set LesMots [split $Ligne " "] foreach SousBase [lrange $LesMots 1 end] { if {! [regexp "^/" $SousBase]} { set SousBase "$Dir/$SousBase" } Espionne $SousBase set N [BlastDatabaseSize $SousBase "No" 0] scan $N "%d" N incr total $N Espionne $N } } return $total } return $DefaultSize } proc BlastDatabaseSizePourTous {} { set LesBanques [split [BlastDatabaseInventory ListOf ProBestFirst]] set LesNouveaux {} foreach Banque $LesBanques { set Queue [file tail $Banque] set FichierBlast "[BlastTestDir]/$Queue.test.blast" set FichierQuery "[BlastTestDir]/queryBidon.tfa" Espionne "$Queue $Banque $FichierBlast" if {[FileAbsent $FichierBlast]} { BlastForTest $FichierQuery $FichierBlast $Banque "GetFilename" "Wait" } set Size [BlastDatabaseSize $Banque] Espionne $Size lappend LesSize "$Size $FichierBlast" } return $LesSize } proc BlastForTest {FichierEntree {FichierSortie ""} {Banque ""} {GetWhat ""} {Wait ""}} { #rR on s'en sert surtout pour créer les blast qui permettent d'en extraire la taille par BlastDatabaseSize if {$GetWhat==""} { set GetWhat "GetFilename" } if {[string equal -nocase $GetWhat "GetPid"]} { set Wait "Wait" } set Wait [string equal -nocase $Wait "Wait"] if {[PourWscope]} { if {[regexp "\.\." $FichierSortie]} { return "Sorry. You are not allowed to create $FichierSortie]" } if { ! [regexp [BlastTestDir] $FichierSortie] && ! [regexp "magasin" $FichierSortie]} { return "Sorry. You are not allowed to create $FichierSortie]" } } if { [file exists $FichierSortie] && [string equal -nocase $Action "Lire"] } {return [ContenuDuFichier $FichierSortie]} set commande "tcsh -c \"/biolo/ncbi/bin/blastall -i $FichierEntree -a 8 -d $Banque -p blastp -F T -o $FichierSortie.tmp -K 0 -v 33 -b 33 -e 1.0e-33 ; mv $FichierSortie.tmp $FichierSortie;\"" if {$Wait} { eval exec $commande if {[string equal -nocase $GetWhat "Lire"] } { return [ContenuDuFichier $fichierSortie] } return $FichierSortie } set Pid [eval exec $commande &] return "blast was launched with command\n$commande\npid=$Pid Result will be available in $FichierSortie" } proc BlastDatabaseInventory {{Qui ""} {Quoi ""} {RepBan ""}} { global BDI if {$Qui=="ResetAll"} { if {[info exists BDI]} { unset BDI } return "" } if {$Qui==""} { set Qui "Usage" ; set Quoi "" } if {$Quoi=="Size"} { return [BlastDatabaseSizeNice $Qui] } if {[info exists BDI($Qui,$Quoi)] } { return $BDI($Qui,$Quoi) } if {[info exists BDI("EstCharge")]} { return "" } set BDI("EstCharge") 1 if {$RepBan==""} { set RepBan "/blast" } set BDI(Dir,) $RepBan set LesNal {} set LesProBest [list \ protall \ uniprot \ protein \ swissprot \ trembl \ pdb \ varsplic \ refseq-prot \ uniref90 \ ] set LesNucBest [list \ genembl \ genbank \ refseq-nuc \ est \ HUMAN \ MOUSE \ ] set ToutesLesBanques [lsort [glob -nocomplain "$RepBan/*"]] foreach Fichier $ToutesLesBanques { set Banque [file tail $Fichier] set B $Banque if { ! [regexp {(\.pal|\.phr|\.nhr|\.nal)$} $Banque] } { continue } if {[regexp {\.pal$} $Banque]} { regsub {\.pal$} $Banque "" B set EstPal($B) $B } if {[regexp {\.nal$} $Banque]} { regsub {\.nal$} $Banque "" B set EstNal($B) $B } } foreach Fichier $ToutesLesBanques { # if {[file type $Fichier]=="link"} { continue } set Banque [file tail $Fichier] set B $Banque if { ! [regexp {(\.pal|\.phr|\.nhr|\.nal)$} $Banque] } { continue } lappend BDI(ListOf,All) $Banque if {[regexp {\.pal$} $Banque]} { regsub {\.pal$} $Banque "" B set ContentOf($B) [ContenuDuFichier $Fichier] foreach Ligne [LesLignesDuFichier $Fichier] { if {[regexp "^TITLE" $Ligne]} { set Title($B) [StringSuivant "TITLE " dans $Ligne] } if {[regexp "^DBLIST" $Ligne]} { set Filles [StringSuivant "DBLIST " dans $Ligne] regsub -all " +" $Filles " " Filles set LesFilles [split [string trim $Filles] " "] set LesFillesDe($B) {} foreach Fille $LesFilles { if { ! [regexp "^/" $Fille] && [FileAbsent "$RepBan/$Fille.pal"] && [FileAbsent "$RepBan/$Fille.phr"]} { continue FaireLire "$RepBan/$Fille.phr ou .pal introuvable" } lappend LesMeresDe($Fille) $B lappend LesFillesDe($B) $Fille } } } if { ! [info exists Title($B)]} { set Title($B) "" } if {$LesFillesDe($B)=={}} { continue } lappend LesPal $B set BDI($B,TITLE) $Title($B) set BDI($B,DBLIST) $LesFillesDe($B) set BDI($B,CONTENT) $ContentOf($B) } if {[regexp {\.nal$} $Banque]} { regsub {\.nal$} $Banque "" B set ContentOf($B) [ContenuDuFichier $Fichier] foreach Ligne [LesLignesDuFichier $Fichier] { if {[regexp "^TITLE" $Ligne]} { set Title($B) [StringSuivant "TITLE " dans $Ligne] } if {[regexp "^DBLIST" $Ligne]} { set Filles [StringSuivant "DBLIST " dans $Ligne] regsub -all " +" $Filles " " Filles set LesFilles [split [string trim $Filles] " "] set LesFillesDe($B) {} foreach Fille $LesFilles { if {[FileAbsent "$RepBan/$Fille.nal"] && [FileAbsent "$RepBan/$Fille.nhr"]} { continue FaireLire "$RepBan/$Fille.nhr ou .nal introuvable" } lappend LesMeresDe($Fille) $B lappend LesFillesDe($B) $Fille } } } if { ! [info exists Title($B)]} { set Title($B) "" } if {$LesFillesDe($B)=={}} { continue } lappend LesNal $B set BDI($B,TITLE) $Title($B) set BDI($B,DBLIST) $LesFillesDe($B) set BDI($B,CONTENT) $ContentOf($B) } if {[info exists DejaVu($B)]} { FaireLire "$B\n$Fichier\n$DejaVu($B)" } set DejaVu($B) $Fichier } set LesPhr {} set LesNhr {} foreach Fichier $ToutesLesBanques { set Banque [file tail $Fichier] set B $Banque if { ! [regexp {(\.phr|\.nhr)$} $Banque] } { continue } if {[regexp {\.phr$} $Banque]} { regsub {\.phr$} $Banque "" B if {[regexp {(unigene)[0-9]+$} $B] } { continue } if {[regexp {(part|\.)[0-9]+$} $B] && [info exists LesMeresDe($B)]} { continue } lappend LesPhr $B lappend LesProWithTitle "[format %-33s $B] :" } if {[regexp {\.nhr$} $Banque]} { regsub {\.nhr$} $Banque "" B if {[regexp {(unigene)[0-9]+$} $B] } { continue } if {[regexp {(part|\.|unigene)[0-9]+$} $B] && [info exists LesMeresDe($B)]} { continue } lappend LesNhr $B } } foreach {K V} [array get LesMeresDe] { set BDI($K,PartOf) $V } set LesPro [lsort [concat $LesPal $LesPhr]] set LesNuc [lsort [concat $LesNal $LesNhr]] set LesProBestExistant {} foreach B $LesProBest { if {[lsearch $LesPro $B]<0} { continue } lappend LesProBestExistant $B } set LesNucBestExistant {} foreach B $LesNucBest { if {[lsearch $LesNuc $B]<0} { continue } lappend LesNucBestExistant $B } set LesProBestFirst [ListeSansDoublon [concat $LesProBestExistant $LesPro]] set LesNucBestFirst [ListeSansDoublon [concat $LesNucBestExistant $LesNuc]] foreach X [list "Pro" "Nuc" "ProBestFirst" "NucBestFirst"] { set Les${X}WithTitle {} foreach B [set Les${X}] { set T "" if {[info exists Title($B)]} { set T $Title($B) } lappend Les${X}WithTitle "[format %-33s $B] : $T" } } set BDI(ListOf,ProWithTitle) [join $LesProWithTitle "\n"] set BDI(ListOf,Pro) [join $LesPro "\n"] set BDI(ListOf,Pal) [join $LesPal "\n"] set BDI(ListOf,Phr) [join $LesPhr "\n"] set BDI(ListOf,NucWithTitle) [join $LesNucWithTitle "\n"] set BDI(ListOf,Nuc) [join $LesNuc "\n"] set BDI(ListOf,Nal) [join $LesNal "\n"] set BDI(ListOf,Nhr) [join $LesNhr "\n"] set BDI(ListOf,ProBestFirst) [join $LesProBestFirst "\n"] set BDI(ListOf,NucBestFirst) [join $LesNucBestFirst "\n"] set BDI(ListOf,ProBestFirstWithTitle) [join $LesProBestFirstWithTitle "\n"] set BDI(ListOf,NucBestFirstWithTitle) [join $LesNucBestFirstWithTitle "\n"] set BDI(ListOf,ProNucBestFirstWithTitle) "$BDI(ListOf,ProBestFirstWithTitle)\n$BDI(ListOf,NucBestFirstWithTitle)" foreach B $LesPal { set BDI($B,Type) "Pal" } foreach B $LesPhr { set BDI($B,Type) "Phr" } foreach B $LesNal { set BDI($B,Type) "Nal" } foreach B $LesNhr { set BDI($B,Type) "Nhr" } set LesUs [array names BDI] set LesUsages {} foreach Us $LesUs { if {[regexp "EstCharge" $Us]} { continue } lassign [split $Us ","] A B if {[info exists BDI($A,PartOf)] || [info exists BDI($A,Type)]} { set A "BlastDatabank" } lappend LesUsages "BlastDatabaseInventory $A $B" } lappend LesUsages "BlastDatabaseInventory ResetAll" lappend LesUsages "BlastDatabaseInventory Usage" set LesUsages [lsort -unique $LesUsages] set BDI(Usage,) [join $LesUsages "\n"] return [BlastDatabaseInventory $Qui $Quoi] }