#rR gscope_go.tcl #rR Depuis 2016/04/30 on a stocké dans fiches les GO et Nom et Gn #rR car on profite des banques OrthoInspector Oi ;) #rR du coup faire dans l'ordre #rR InformeFromOiPourTous #rR InformeGoPourTous #rR MyGenesFromGo #rR MyGOsFromGene proc VerifieDoublonsDansGo {} { foreach Ligne [LesLignesDuFichier [Fiches "NomGnGOs.txt"]] { set LesGOs [lrange [split $Ligne " "] 1 end] if {[llength $LesGOs]!=[llength [lsort -unique $LesGOs]]} { Espionne $Ligne } } } proc AllForGo {} { InformeFromOiPourTous InformeGoPourTous MyGenesFromGo MyGOsFromGene } proc InformeGoPourTous {{LesNoms ""}} { #rR 2017/02/10 on ne met plus dans les info car il existe MyGOsFromGene et MyGenesFromGO if {$LesNoms==""} { set LesNoms [ListeDesPABs] } if {[regexp {[ \n\,\t\;\r]} $LesNoms]} { set LesNoms [LesMotsDuTexte $LesNoms] } set N 0 set LesGOs {} foreach Nom $LesNoms { Espionne $Nom set Gn "" if {$Gn==""} { set Gn [ExtraitInfo $Nom "ValiGN:"] } if {$Gn==""} { set Gn [ExtraitInfo $Nom "GN:"] } if {$Gn==""} { set Gn [ExtraitInfo $Nom "DraftGN:"] } if {$Gn==""} { continue } regsub -all {\'} $Gn "prime" Gn set GOs "" # set GOs [ExtraitInfo $Nom "GOs:"] if {$GOs==""} { set GOs [GoGetFromGene $Gn GoAcc "" "" Up] } Espionne $GOs if {[incr N]%100==0} { Espionne "$Nom:Gn:$Gn GOs: $GOs" } if {$GOs==""} { continue } #InformeSansDemander $Nom "=GOs: $GOs" lappend LesGOs "$Nom:$Gn:GOs: $GOs" } return [SauveLesLignes $LesGOs dans [Fiches "NomGnGOs.txt"]] } proc MyGOsFromGene {{Qui ""} {Quoi ""} {JoinCar ""} {RecordJoinCar ""}} { #rR Attention il faut avoir fait InformeGoPourTous (c'est fait automatiquement mais vaut mieux le faire avant) global MyGOsFromGene if {$JoinCar=="space"} { set JoinCar " " } if {$RecordJoinCar=="space"} { set RecordJoinCar " " } if {$JoinCar==""} {set JoinCar "=" } if {$RecordJoinCar==""} {set RecordJoinCar "\n" } if {$Quoi==""} { set Quoi "GOs" } if {[info exists MyGOsFromGene($Qui,$Quoi)]} { return $MyGOsFromGene($Qui,$Quoi) } if {[info exists MyGOsFromGene("EstCharge")]} { if { ! [info exists MyGOsFromGene($Qui,GOs)]} { set QUI [string toupper $Qui] if {$QUI!=$Qui} { return [MyGOsFromGene $QUI $Quoi $JoinCar $RecordJoinCar] } return "" } set NoBrace [regexp -nocase "nobrace" $Quoi] regsub -nocase "nobrace" $Quoi "" Quoi set LesGo $MyGOsFromGene($Qui,GOs) foreach Go $LesGo { set LeRecord "" foreach Q [split $Quoi ","] { set R [GoGetFromGo $Go $Q] if {$NoBrace} { regsub -all {[\{\}]} $R "" R } lappend LeRecord $R } set Record [join $LeRecord $JoinCar] lappend LeTout $Record } set Tout [join $LeTout $RecordJoinCar] return $Tout } set MyGOsFromGene("EstCharge") 1 set MyGOsFromGene(File,MyGOsFromGene) [Fiches "MyGOsFromGene.txt"] if {[file exists MyGOsFromGene(File,MyGOsFromGene)]} { array set [ContenuDuFichier $MyGOsFromGene(File,MyGOsFromGene)] return [MyGOsFromGene $Qui $Quoi $JoinCar $RecordJoinCar] } set MyGOsFromGene(File,NomGnGos) [Fiches "NomGnGOs.txt"] set MyGOsFromGene(File,GoNoms) [Fiches "GoNoms.txt"] set MyGOsFromGene(File,GoGns) [Fiches "GoGns.txt"] if {[FileAbsent $MyGOsFromGene(File,NomGnGos)]} { FaireLire "l vaut mieux faire InformeGoPourTous avant MyGOsFromGene.\nJe le fais maintenant ... cela peut prendre du temps" InformeGoPourTous return [MyGOsFromGene $Qui $Quoi $JoinCar $RecordJoinCar] } set TousLesGo {} set TousLesNom {} set TousLesGn {} foreach Ligne [LesLignesDuFichier $MyGOsFromGene(File,NomGnGos)] { lassign [split $Ligne ":"] Nom Gn lappend TousLesNom $Nom lappend TousLesGn $Gn set LesGo [lrange [split $Ligne " "] 1 end] set MyGOsFromGene($Nom,GOs) $LesGo set MyGOsFromGene($Gn,GOs) $LesGo set MyGOsFromGene([string toupper $Gn],GOs) $LesGo } set MyGOsFromGene(ListOf,Go) [ListeSansDoublon $TousLesGo] set MyGOsFromGene(ListOf,Nom) [ListeSansDoublon $TousLesNom] set MyGOsFromGene(ListOf,Gn) [ListeSansDoublon $TousLesGn] Sauve [array get MyGOsFromGene] dans $MyGOsFromGene(File,MyGOsFromGene) return [MyGOsFromGene $Qui $Quoi $JoinCar $RecordJoinCar] } proc MyGenesFromGo {{Qui ""} {Quoi ""}} { #rR Attention il faut avoir fait InformeGoPourTous global MyGenesFromGo if {$Quoi==""} { set Quoi "Noms" } if {[info exists MyGenesFromGo($Qui,$Quoi)]} { return $MyGenesFromGo($Qui,$Quoi) } if {[info exists MyGenesFromGo("EstCharge")]} { return "" } set MyGenesFromGo("EstCharge") 1 set MyGenesFromGo(File,MyGenesFromGo) [Fiches "MyGenesFromGo.txt"] if {[file exists MyGenesFromGo(File,MyGenesFromGo)]} { array set [ContenuDuFichier $MyGenesFromGo(File,MyGenesFromGo)] return [MyGenesFromGo $Qui $Quoi] } set MyGenesFromGo(File,NomGnGos) [Fiches "NomGnGOs.txt"] set MyGenesFromGo(File,GoNoms) [Fiches "GoNoms.txt"] set MyGenesFromGo(File,GoGns) [Fiches "GoGns.txt"] if {[FileAbsent $MyGenesFromGo(File,NomGnGos)]} { FaireLire "Il vaut mieux faire InformeGoPourTous avant MyGenesFromGo.\nJe le fais maintenant ... cela peut prendre du temps" InformeGoPourTous return [MyGenesFromGo $Qui $Quoi] } set TousLesGo {} set TousLesNom {} set TousLesGn {} foreach Ligne [LesLignesDuFichier $MyGenesFromGo(File,NomGnGos)] { lassign [split $Ligne ":"] Nom Gn lappend TousLesNom $Nom lappend TousLesGn $Gn set LesGo [lrange [split $Ligne " "] 1 end] foreach Go $LesGo { lappend TousLesGo $Go lappend NomsDuGo($Go) $Nom lappend GnsDuGo($Go) $Gn } } set TousLesGo [lsort -unique $TousLesGo] set LesGoNoms {} set LesGoGns {} foreach Go $TousLesGo { set NomsDuGo($Go) [ListeSansDoublon $NomsDuGo($Go)] set GnsDuGo($Go) [ListeSansDoublon $GnsDuGo($Go)] set MyGenesFromGo($Go,Noms) $NomsDuGo($Go) set MyGenesFromGo($Go,Gns) $GnsDuGo($Go) lappend LesGoNoms "$Go [join $NomsDuGo($Go) { }]" lappend LesGoGns "$Go [join $GnsDuGo($Go) { }]" } set MyGenesFromGo(ListOf,Go) $TousLesGo set MyGenesFromGo(ListOf,Nom) [ListeSansDoublon $TousLesNom] set MyGenesFromGo(ListOf,Gn) [ListeSansDoublon $TousLesGn] Sauve [array get MyGenesFromGo] dans $MyGenesFromGo(File,MyGenesFromGo) SauveLesLignes $LesGoNoms dans $MyGenesFromGo(File,GoNoms) SauveLesLignes $LesGoGns dans $MyGenesFromGo(File,GoGns) return [MyGenesFromGo $Qui $Quoi] } proc ShowGo {What Selection {NomDuFichierOrgine ""}} { if {[regexp "\n" $Selection]} { set LesF {} foreach Sel [split $Selection "\n"] { lappend LesF [ShowGo $What $Sel $NomDuFichierOrgine] } return $LesF } set Action "Go$What" if {[info proc $Action]==""} { return "" } regsub "=.*" $Selection "" Acc regsub " " $Selection "_" S set LesReponses {} foreach Name [$Action $Acc "acc,name" "="] { regsub -all {[\{\}]} $Name "" Name lappend LesReponses $Name } set Clavier "Postpone" TouchePour $Clavier NouvelleCouleur "Magenta" TouchePour $Clavier "GO Ancestors" "ShowGo Ancestors \[selection get\] Ancestors_$NomDuFichierOrgine" TouchePour <2> "/Parents" "ShowGo Parents \[selection get\] Parents_$NomDuFichierOrgine" TouchePour <3> "/Children" "ShowGo Children \[selection get\] Children_$NomDuFichierOrgine" return [AfficheListe $LesReponses "" "${What}_of_${S}_from_${NomDuFichierOrgine}"] } proc ShowGOs Nom { set GOs [ExtraitInfo $Nom "GOs:"] if {$GOs==""} { return "" } set LesName {} foreach Go [split $GOs " "] { set Name [GoGetFromGo $Go "acc,name" "="] regsub -all {[\{\}]} $Name "" Name lappend LesName $Name } set Clavier "Postpone" TouchePour $Clavier NouvelleCouleur "Magenta" TouchePour $Clavier "GO Ancestors" "ShowGo Ancestors \[selection get\] Ancestors_$Nom" TouchePour <2> "/Parents" "ShowGo Parents \[selection get\] Parents_$Nom" TouchePour <3> "/Children" "ShowGo Children \[selection get\] Children_$Nom" return [AfficheListe $LesName "" "GOs_from_$Nom"] } proc GoStore {} { return "[HomeRipp]/GxWww/GoStore" } proc GoGetInFile {Fichier args} { #rR c'est trop long de passer par Wscope, on memorise direct dans un fichier ... Pour GO2000 en particulier set Res [eval $args] return [Sauve $Res dans $Fichier] } proc CompareDeuxSetsDeGenes {} { set LesHere [split [ContenuDuFichier mfHere.txt] " "] set iOk 0 foreach H $LesHere { if {[regexp {Gm[0-9]+} $H]} { continue } if {[regexp {n\-} $H]} { continue } incr iOk } Espionne $iOk set LesDown [split [ContenuDuFichier mfDown.txt] " "] set LesDiff [ListsComplement $LesDown $LesHere] set LesInte [ListsIntersection $LesHere $LesDown] Espionne [llength $LesHere] Espionne [llength $LesDiff] Espionne [llength $LesDown] # Espionne [expr [llength $LesDown] - $iGm] Espionne [llength $LesInte] Affiche [lrange $LesHere 0 100] "" LesHere Affiche [lrange $LesDiff 0 100] "" LesDiff } proc GoGetAncestorsForSet {{GoSet ""} {GetWhat ""} {WhatJoinCar ""} {JoinCar ""} {RecordsJoinCar ""} {ListJoinCar ""}} { set UpDown "Bidon" UpDownCommeIlFaut UpDown JoinCar RecordsJoinCar ListJoinCar if {[regexp "/" $GoSet]} { set GoSet [split $GoSet "/"] } #rR par defaut on rend GO=GOacc name@Goparent name@GOacc name puis à la ligne etc. if {$GetWhat==""} { set GetWhat "GOacc,name" } if {$WhatJoinCar ==""} { set WhatJoinCar " " } if {$JoinCar ==""} { set JoinCar "@" } if {$RecordsJoinCar==""} { set RecordsJoinCar "=" } if {$ListJoinCar ==""} { set ListJoinCar "\n" } set LesGo {} foreach Ligne $GoSet { scan $Ligne "%s" Go if {$Go=="" || $Go=="all"} { continue } lappend LesGo $Go set Id [GoInfo $Go Id] set InSet($Id) 1 lappend LesId $Id set IdDuGo($Go) $Id } set IdDuAll [GoInfo "all" GOid] foreach Id $LesId { foreach A [GoAncestors $Id] { if {$A=="" || $A==$IdDuAll} { continue } if { ! [info exists InSet($Id)]} { continue } lappend KeepedAncestors($Id) [GoInfo $A $GetWhat $WhatJoinCar] } } set LeResultat {} foreach Go $LesGo { set Id $IdDuGo($Go) lappend LeResultat [join [list $Go [join $KeepedAncestors($Id) $JoinCar]] $RecordsJoinCar] } return [join $LeResultat $ListJoinCar] } proc GoOntology {Go} { CanalSqlGeneOntology if { ! [regexp {^GO\:[0-9]+$} $Go]} { set Go [GoGetFromGo $Go "GOacc"] } set Sql "select term_type from term where acc='$Go'" set O [SqlExec $Sql] return $O } proc GoGetInfosFromGeneListByGO {LesGenes {GetWhat ""} {Quoi ""} {UpDown ""}} { if {$GetWhat==""} { set GetWhat "GetGoCountGenes" } set LesGeneAvecGos [GoGetFromGeneListAsLists $LesGenes $Quoi $UpDown] set LesGo {} foreach GeneGosInfos $LesGeneAvecGos { lassign $GeneGosInfos Gene LesInfos foreach GoInfos $LesInfos { set Go [lindex $GoInfos 0] lappend LesGo $Go lappend GenesFrom($Go) $Gene set Infos($Go) $GoInfos } } set LesGos [lsort -unique $LesGo] set LesGoCount {} set LesGoCountGenes {} foreach Go $LesGos { set MyGenes [lsort -unique $GenesFrom($Go)] set N [llength $MyGenes] set Info [join $Infos($Go) " "] lappend LesGoCount [list $Info $N] lappend LesGoCountGenes [list $Info $N $MyGenes] } if {$GetWhat=="GetGoCount"} { return $LesGoCount } if {$GetWhat=="GetGoCountGenes"} { return $LesGoCountGenes } return $LesGoCountGenes } proc GoGetFromGeneListAsLists {LesGenes {Quoi ""} {UpDown ""}} { if {$UpDown==""} { set UpDown "Up" } if {$Quoi==""} { set Quoi "GOacc,name" } set JC "@" set RJ "!" if {[PourWscope]} { set LesGosParGene [GoGetFromGeneList $LesGenes $Quoi $JC $RJ GetList $UpDown] } else { #rR attention il faudrait appeler la bonne science BON, GOMF ou EVImm set LesGosParGene [QuestionDeScience EVImm "ret GoGetFromGeneList $LesGenes $Quoi $JC $RJ GetList $UpDown"] } set LesGeneAvecGos {} foreach GeneGosInfos $LesGosParGene { if { ! [regexp {([^=]+)=(.*)} $GeneGosInfos Match Gene GosInfos]} { continue } set LesGosInfos [split $GosInfos $RJ] set LesInfos {} foreach GoInfos $LesGosInfos { set LesInfosDuGo [split $GoInfos $JC] lappend LesInfos $LesInfosDuGo } lappend LesGeneAvecGos [list $Gene $LesInfos] } return $LesGeneAvecGos } proc GoGetEnrichment {{GenesA ""} {GenesB ""} {GetWhat ""}} { if {$GenesA==""} { set GenesA [ContenuDuFichier "[GoStore]/genesA.txt"] } if {$GenesB==""} { set GenesB [ContenuDuFichier "[GoStore]/genesB.txt"] } #Sauve $GenesA dans [HomeRipp]/geneA.txt #Sauve $GenesB dans [HomeRipp]/geneB.txt if {$GetWhat=="" && [PourWscope]} { set GetWhat "GetText" } set LesGenesA [split $GenesA ","] set LesGenesB [split $GenesB ","] set LA [Maxi 1 [llength $LesGenesA]] set LB [Maxi 1 [llength $LesGenesB]] set LesInfosA [GoGetInfosFromGeneListByGO $GenesA "GetGoCountGenes" "GOacc,name" Up] set LesInfosB [GoGetInfosFromGeneListByGO $GenesB "GetGoCountGenes" "GOacc,name" Up] set LesGo {} set LesGoA {} set LesGoB {} foreach Infos $LesInfosA { set GoInfo [lindex $Infos 0] set N [lindex $Infos 1] set GnA [lindex $Infos 2] set Go [scan $GoInfo "%s"] lappend LesGo $Go lappend LesGoA $Go set CountADe($Go) $N set InfoADe($Go) $GoInfo set InfoDe($Go) $GoInfo set GnADe($Go) $GnA } foreach Infos $LesInfosB { set GoInfo [lindex $Infos 0] set N [lindex $Infos 1] set GnB [lindex $Infos 2] set Go [scan $GoInfo "%s"] lappend LesGo $Go lappend LesGoB $Go set CountBDe($Go) $N set InfoBDe($Go) $GoInfo set InfoDe($Go) $GoInfo set GnBDe($Go) $GnB } set LesGo [lsort -unique $LesGo] foreach Go $LesGo { set GnAB {} if {[info exists GnADe($Go)] && [info exists GnBDe($Go)]} { set GnAB [ListsIntersection $GnADe($Go) $GnBDe($Go)] } set NAB [llength $GnAB] set NA 0 ; if {[info exists CountADe($Go)]} { set NA $CountADe($Go) } set NB 0 ; if {[info exists CountBDe($Go)]} { set NB $CountBDe($Go) } set SA [expr int(floor((1000.*$NA)/$LA+0.5))] set SB [expr int(floor((1000.*$NB)/$LB+0.5))] if {$SB==0} { set AB 99.99 } else { set AB [expr 1.0*$SA/$SB] } lappend LeR [format "Q/R %5.2f = %4d / %4d %4d %4d %4d %s" $AB $SA $SB $NA $NB $NAB $InfoDe($Go)] } set LeR [lsort -decreasing -command CompareGoCounts $LeR] if {$GetWhat=="GetText"} { return [join $LeR "\n"] } return $LeR } proc CompareGoCounts {X Y} { regsub -all {[^ 0-9\.]} $X " " X regsub -all {[^ 0-9\.]} $Y " " Y scan $X "%f %d %d %d %d %d" ABx SAx SBx NAx NBx NABx scan $Y "%f %d %d %d %d %d" ABy SAy SBy NAy NBy NABy if {$ABx<$ABy} { return -1 } if {$ABx>$ABy} { return 1 } if {$SAx<$SAy} { return -1 } if {$SAx>$SAy} { return 1 } if {$SBx<$SBy} { return 1 } if {$SBx>$SBy} { return -1 } if {$NAx<$NAy} { return -1 } if {$NAx>$NAy} { return 1 } if {$NBx<$NBy} { return 1 } if {$NBx>$NBy} { return -1 } return 0 } proc ihr {} { set Header "genename humangenesymbol altnames species detectionmethod stage1 stage2 stage3 stage4 moumsechromodist mgd humanchromoloc omim mousemappingref humanmappingref expressionref typeofprotein abnormalitiesinmutant" set LesHeader [split $Header "\t"] set NewHeader [join $LesHeader ";"] lappend LeNew $NewHeader foreach Ligne [LesLignesDuFichier "[HomeRipp]/GenoretWww/ImAnno/ImAnnoEar/mousegene.txt"] { if { ! [regexp -nocase {[a-z]} $Ligne]} { continue } regsub -all {\;} $Ligne ".," Ligne set LesMots [split $Ligne "\t"] set N [llength $LesMots] Espionne [lindex $LesMots 14] if {$N==14} { lappend LesMots "" } if {$N>15} { set LesMots [lrange $LesMots 0 14] } set New [join $LesMots ";"] lappend LeNew $New } SauveLesLignes $LeNew dans "[HomeRipp]/GenoretWww/ImAnno/ImAnnoEar/mousegeneRR.txt" AfficheVariable [join $LeNew "\n"] } proc GoTestAll {} { Espionne [GoSpecies] Espionne [GoSpecies] Espionne [GoSpecies "Homo sapiens" "SetDefault"] Espionne [GoSpecies] Espionne [GoSpecies "Mus musculus" "SetDefault"] Espionne [GoSpecies] Espionne [GoSpecies "ncbi_taxa_id9606" "SetDefault"] Espionne [GoSpecies] Espionne [GoSpecies "Mus musculus" "SetDefault"] #rR et ca marche sans quote avec underscore ( _ est mieux pour le web) Espionne [GoSpecies Mus_musculus "genus,species,common_name"] Espionne [GoGetFromGo "cyclin protein" GENE] Espionne [GoGetFromGo "cyclin protein" PFAM] Espionne [GoGetFromGo "cyclin binding" "GENEsymbol,full_name" "="] EspionneL [GoGetFromGene pax6 "GOacc,name,a.assocdate" "" "GetList"] } proc GoTermType {} { if {[OnTraite "GOMF"]} { return [list "molecular_function"] } if {[OnTraite "BON"]} { return [list "molecular_function"] } return [list "biological_process" "cellular_component" "molecular_function"] } proc GoTermTypeIn {} { set Types [join [GoTermType] "','"] set In "('$Types')" return $In } proc GoSpecies {{Qui ""} {Quoi ""} {JoinCar ""} {RecordsJoinCarNeSertPasEncore ""}} { global GoSpecies if {$Quoi=="All"} { set Quoi "*" } if {$Qui=="" && [info exists GoSpecies]} { return $GoSpecies } set DefSpe "" if {$DefSpe=="" && [regexp -nocase "hu" [RepertoireDuGenome]]} { set DefSpe "Homo sapiens" } ;#rR a ameliorer !! if {$DefSpe=="" && [OnTraite "BON"]} { set DefSpe "Homo sapiens" } if {$DefSpe=="" && [OnTraite "GOSc"]} { set DefSpe "Saccharomyces cerevisiae S288c" } if {$DefSpe=="" && [NotreOX]!=""} { set DefSpe "ncbi_taxa_id_[NotreOX]" } if {$DefSpe==""} { set DefSpe "Mus musculus" } if {$Qui==""} { set Qui $DefSpe } if {$Quoi==""} { set Quoi "id" } set SetDefault [expr [string equal -nocase $Quoi "SetDefault"]] if {$SetDefault} { set Quoi "id" } CanalSqlGeneOntology if {[regexp "select " $Qui]} { return [SqlExec $Sql] } set Where "id=$Qui" if {[regexp -nocase "^ncbi_taxa_id" $Qui]} { regsub -all {[^0-9]} $Qui "" NcbiTaxaId set Where "ncbi_taxa_id=$NcbiTaxaId" } elseif {[regexp {[ _]} $Qui]} { regsub "_" $Qui " " Qui scan $Qui "%s" Genre regsub "$Genre " $Qui "" Espece set Where "genus='$Genre' and species='$Espece'" } set Sql "select $Quoi from species where $Where" set R [SqlExec $Sql] if {$JoinCar!=""} { set R [join $R $JoinCar] } if {$SetDefault} { set GoSpecies $R } return $R } proc EstUpDown {UD} { return [regexp -nocase {^\+?(Up|Down|Here|\-?[0-9]+)$} $UD] } proc UpDownCommeIlFaut {aUpDown aJoinCar aRecordsJoinCar {aListJoinCar ""}} { upvar $aUpDown UpDown upvar $aJoinCar JoinCar upvar $aRecordsJoinCar RecordsJoinCar if {$aListJoinCar!=""} { upvar $aListJoinCar ListJoinCar } else { set ListJoinCar "" } set L [list $JoinCar $RecordsJoinCar $ListJoinCar $UpDown] set I 0 foreach E $L { if {[EstUpDown $E]} { break } incr I } if {$I >= [expr [llength $L]-1]} { foreach Car [list JoinCar RecordsJoinCar ListJoinCar] { if {[set $Car]=="nl"} { set $Car "\n" } if {[set $Car]=="tab"} { set $Car "\t" } } return } set N [lreplace $L $I $I] lappend N [lindex $L $I] lassign $N JoinCar RecordsJoinCar ListJoinCar UpDown foreach Car [list JoinCar RecordsJoinCar ListJoinCar] { if {[set $Car]=="nl"} { set $Car "\n" } if {[set $Car]=="tab"} { set $Car "\t" } } return } proc GoGetFromPfamList {List {Quoi ""} {JoinCar ""} {RecordsJoinCar ""} {ListJoinCar ""} {UpDown ""} } { UpDownCommeIlFaut UpDown JoinCar RecordsJoinCar ListJoinCar set List [string trim $List " ,;"] if {[regexp {[\,;]} $List]} { set List [split $List ",;"] } else { set List [list $List] } set LePV {} foreach Pfam $List { lappend LePV "$Gene=[GoGetFromPfam $Pfam $Quoi $JoinCar $RecordsJoinCar $UpDown]" } if {$ListJoinCar=="" || $ListJoinCar=="GetList"} { return $LePV } return [join $LePV $ListJoinCar] } proc GoGetFromPfam {{Qui ""} {Quoi ""} {JoinCar ""} {RecordsJoinCar ""} {UpDown ""}} { UpDownCommeIlFaut UpDown JoinCar RecordsJoinCar CanalSqlGeneOntology if {$Quoi==""} { set Quoi "GO" } if { ! [regexp -nocase "^GO" $Quoi]} { set Sql "select $Quoi from dbxref where xref_key='$Qui' and xref_dbname = 'Pfam'" set R [SqlExec $Sql] if {$JoinCar!=""} { set R [join $R $JoinCar] } return $R } regsub -nocase "^GO" $Quoi "" Quoi if {$Quoi==""} { set Quoi "id" } set DbId [lindex [GoGetFromPfam $Qui "id"] 0] if {$DbId==""} {return ""} set LesTQ {} foreach Q [split $Quoi ","] { set TQ "t.$Q" if {[regexp {\.} $Q]} { set TQ $Q } lappend LesTQ $TQ } set TQs [join $LesTQ ","] set Sql "select distinct $TQs from dbxref d, term_dbxref l, term t \ where $DbId=d.id \ and d.id=l.dbxref_id \ and l.term_id=t.id \ and t.term_type in [GoTermTypeIn] ;" set FlatOuList "" set DoList [expr ! [string equal $RecordsJoinCar ""] || ! [string equal $JoinCar ""]] if {$DoList} { if {$RecordsJoinCar=="GetList"} { set RecordsJoinCar "" } set FlatOuList "-list" } set R [SqlExec $Sql $FlatOuList] if {$DoList} { set LesRecords {} foreach r $R { if {$JoinCar!=""} { set r [join $r $JoinCar] } lappend LesRecords $r } set R $LesRecords set JoinCar $RecordsJoinCar } if {$JoinCar!=""} { set R [join $R $JoinCar] } return $R } proc GoGetFromGeneList {List {Quoi ""} {JoinCar ""} {RecordsJoinCar ""} {ListJoinCar ""} {UpDown ""}} { JeMeSignale UpDownCommeIlFaut UpDown JoinCar RecordsJoinCar ListJoinCar set List [string trim $List " ,;"] if {[regexp {[\,;]} $List]} { set List [split $List ",;"] } else { set List [list $List] } package require md5 set MD5 [md5::md5 -hex $List] set GoStoreFile "[GoStore]/$MD5.txt" if {[FileExists $GoStoreFile]} { LogWscope "On va utiliser $GoStoreFile pour une liste de longueur [llength $List]" set LeGV [ContenuDuFichier $GoStoreFile] } else { LogWscope "On va faire GoGetFromGeneList sur une liste de longueur [llength $List]" set LeGV {} foreach Gene $List { LogWscope $Gene set GV "$Gene=[GoGetFromGene $Gene $Quoi $JoinCar $RecordsJoinCar $UpDown]" lappend LeGV $GV } if {[llength $List]>10} { Sauve $LeGV dans $GoStoreFile } } LogWscope "GoGetFromGeneList va renvoyer [llength $LeGV] records" if {$ListJoinCar=="" || $ListJoinCar=="GetList"} { return $LeGV } return [join $LeGV $ListJoinCar] } proc GoGetFromGene {{Qui ""} {Quoi ""} {JoinCar ""} {RecordsJoinCar ""} {UpDown ""}} { UpDownCommeIlFaut UpDown JoinCar RecordsJoinCar CanalSqlGeneOntology if {$Quoi==""} { set Quoi "GO" } if { ! [regexp -nocase "^GO" $Quoi]} { set Sql "select $Quoi from gene_product g where symbol='$Qui' and species_id=[GoSpecies]" #Espionne $Sql set R [SqlExec $Sql] if {$R=={}} { set Sql "select g.$Quoi from gene_product g, gene_product_synonym s where g.species_id=[GoSpecies] \ and s.product_synonym='$Qui' and s.gene_product_id=g.id" set R [SqlExec $Sql] } if {$JoinCar!=""} { set R [join $R $JoinCar] } return $R } set DoUp [expr {[string equal -nocase $UpDown "Up"] && [regexp -nocase "^GO" $Quoi]}] regsub -nocase "^GO" $Quoi "" Quoi if {$Quoi==""} { set Quoi "id" } set GpId [lindex [GoGetFromGene $Qui "id"] 0] if {$GpId==""} { return "" } set LesTQ {} foreach Q [split $Quoi ","] { set TQ "t.$Q" if {[regexp {\.} $Q]} { set TQ $Q } lappend LesTQ $TQ } set TQs [join $LesTQ ","] set Sql "select distinct $TQs from term t, gene_product g, association a \ where $GpId=g.id \ and g.id=a.gene_product_id \ and a.is_not=0 \ and a.term_id=t.id \ and t.term_type in [GoTermTypeIn] ;" #LogWscope $Sql set FlatOuList "" set DoList [expr ! [string equal $RecordsJoinCar ""] || ! [string equal $JoinCar ""]] if {$DoList} { if {$RecordsJoinCar=="GetList"} { set RecordsJoinCar "" } set FlatOuList "-list" } set R [SqlExec $Sql $FlatOuList] if {$DoUp} { set LeNouveauR {} foreach r $R { lappend LeNouveauR $r set r [lindex $r 0] set LesAncetres [GoGetFromGo $r $Quoi "" "" Up] foreach a $LesAncetres { lappend LeNouveauR $a } } set LeNouveauR [lsort -unique $LeNouveauR] set R $LeNouveauR } if {$DoList} { set LesRecords {} foreach r $R { if {$JoinCar!=""} { set r [join $r $JoinCar] } lappend LesRecords $r } set R $LesRecords set JoinCar $RecordsJoinCar } if {$JoinCar!=""} { set R [join $R $JoinCar] } return $R } proc GoGetFromGoList {List {Quoi ""} {JoinCar ""} {RecordsJoinCar ""} {ListJoinCar ""} {UpDown ""}} { UpDownCommeIlFaut UpDown JoinCar RecordsJoinCar ListJoinCar set List [string trim $List " ,;"] if {[regexp ";" $List]} { set List [split $List ";"] } elseif {[regexp "\," $List]} { if {[regexp {^([0-9]+|GO\:[0-9]+)(\,([0-9]+|GO\:[0-9]+))*$} $List]} { set List [split $List ","] } } else { set List [list $List] } set LeGV {} foreach Go $List { lappend LeGV "$Go=[GoGetFromGo $Go $Quoi $JoinCar $RecordsJoinCar $UpDown]" } if {$ListJoinCar=="" || $ListJoinCar=="GetList"} { return $LeGV } return [join $LeGV $ListJoinCar] } proc GoGetFromGo {{IdOrNameOrAcc ""} {Quoi ""} {JoinCar ""} {RecordsJoinCar ""} {UpDown ""}} { UpDownCommeIlFaut UpDown JoinCar RecordsJoinCar if {$UpDown ==""} { set UpDown "Here" } if {$Quoi ==""} { set Quoi "GOid" } if {$IdOrNameOrAcc==""} { set IdOrNameOrAcc "molecular_function" } CanalSqlGeneOntology set Id "" if {[regexp {^[0-9]+$} $IdOrNameOrAcc]} { set Id $IdOrNameOrAcc } if {$Id==""} { set Id [GoInfo $IdOrNameOrAcc "id"] } if {$Id==""} { regsub -all "_" $IdOrNameOrAcc " " Name set Id [GoInfo $Name "id"] } if {$Id==""} { return "" } GoCollectInfo "ReSeT" set MaxLevel "" set Moi "0" if {[regexp {^\+} $UpDown]} { set Moi "+0" regsub {^\+} $UpDown "" UpDown } if {[regexp {^\-?[0-9]+$} $UpDown Level]} { if {$Level<0} { set UpDown "Up" } else { set UpDown "Down" } set MaxLevel [expr abs($Level)] if {$MaxLevel==0} { set UpDown "Here" } } GoWalk $UpDown $Id $Moi $Quoi $MaxLevel $JoinCar set LesInfos [GoCollectInfo "GeTiT"] set LesUniques {} if {$JoinCar==""} { foreach LesSousInfos $LesInfos { foreach Info $LesSousInfos { lappend LesUniques $Info } } } else { set LesUniques $LesInfos } # set LesUniques [lsort -unique $LesUniques] set LesUniques [ListeSansDoublon $LesUniques] if {$RecordsJoinCar!="" && $RecordsJoinCar!="GetList" } { set LesUniques [join $LesUniques $RecordsJoinCar] } return $LesUniques } proc GoCollectInfo {Info} { global GoCollectInfo if {$Info=="ReSeT"} { if {[info exists GoCollectInfo]} { unset GoCollectInfo } return {} } if {$Info=="GeTiT"} { if {[info exists GoCollectInfo]} { return $GoCollectInfo } return {} } LConcat GoCollectInfo $Info return $GoCollectInfo } proc GoInfo {Id Keys {JoinCar ""} {RecordsJoinCar ""}} { regsub -all "'" $Id "''" Id if {$Id==""} { set Id "NotFindableId" } set LesValeurs {} CanalSqlGeneOntology if {[regexp -nocase "^PFAM" $Keys]} { regsub -nocase "PFAM" $Keys "" Keys if {$Keys==""} { set Keys "xref_key" } set LesK {} set ListeVide {} foreach K [split $Keys ","] { set TK "d.$K" if {[regexp {\.} $K]} { set TK $K } lappend LesTK $TK lappend ListeVide "" } set TKs [join $LesTK ","] set Sql "select $TKs from dbxref d, term_dbxref td, term t \ where t.id = $Id \ and t.id = td.term_id \ and td.dbxref_id = d.id \ and (d.xref_dbname = 'Pfam' or d.xref_dbname = 'PfamB');" } elseif {[regexp -nocase "^GENE" $Keys]} { regsub -nocase "GENE" $Keys "" Keys if {$Keys==""} { set Keys "symbol" } set LesK {} set ListeVide {} foreach K [split $Keys ","] { set TK "g.$K" if {[regexp {\.} $K]} { set TK $K } lappend LesTK $TK lappend ListeVide "" } set TKs [join $LesTK ","] set SpeciesId [GoSpecies] set Sql "select $TKs from term t, gene_product g, association a \ where g.species_id=$SpeciesId \ and a.gene_product_id=g.id \ and a.is_not=0 \ and a.term_id=t.id \ and t.id=$Id;" } else { regsub "^GO" $Keys "" Keys if {$Keys==""} { set Keys "id" } set LesK {} set ListeVide {} foreach K [split $Keys ","] { set TK "$K" if {[regexp {\.} $K]} { set TK $K } lappend LesTK $TK lappend ListeVide "" } set Where "where name='notFindableGo'" if {[regexp {[a-z]} $Id]} { set Where "where name='$Id' and is_obsolete=0" } if {[regexp {^[0-9]+$} $Id]} { set Where "where id=$Id and is_obsolete=0" } if {[regexp {^GO\:} $Id]} { set Where "where acc='$Id' and is_obsolete=0" } set Sql "select $Keys from term $Where;" } set LesValeurs [SqlExec $Sql "-list"] if {$JoinCar==""} { if {$LesValeurs=={}} { return {} } return [list $LesValeurs] } if {$LesValeurs=={}} { set LesValeursJointes [join $ListeVide $JoinCar] } else { set LesValeursJointes {} foreach LesChamps $LesValeurs { set Valeur [join $LesChamps $JoinCar] lappend LesValeursJointes $Valeur } } if {$RecordsJoinCar=="" || $RecordsJoinCar=="GetList"} { return $LesValeursJointes } if {$RecordsJoinCar=="GetFirstvalue"} { return [lindex $LesValeursJointes 0]} return [join $LesValeursJointes $RecordsJoinCar] } proc GoAncestors {Id {Quoi ""} {JoinCar ""} {RecordsJoinCar ""}} { return [GoGetFromGo $Id $Quoi $JoinCar $RecordsJoinCar "Up"] } proc GoChildren {IdOrNameOrAcc {Quoi ""} {JoinCar ""} {RecordsJoinCar ""}} { set Id "" if {[regexp {^[0-9]+$} $IdOrNameOrAcc]} { set Id $IdOrNameOrAcc } if {$Id==""} { set Id [GoInfo $IdOrNameOrAcc "id"] } if {$Id==""} { regsub -all "_" $IdOrNameOrAcc " " Name set Id [GoInfo $Name "id"] } if {$Id==""} { return "" } return [GoNext "Down" $Id $Quoi $JoinCar $RecordsJoinCar] } proc GoParents {IdOrNameOrAcc {Quoi ""} {JoinCar ""} {RecordsJoinCar ""}} { set Id "" if {[regexp {^[0-9]+$} $IdOrNameOrAcc]} { set Id $IdOrNameOrAcc } if {$Id==""} { set Id [GoInfo $IdOrNameOrAcc "id"] } if {$Id==""} { regsub -all "_" $IdOrNameOrAcc " " Name set Id [GoInfo $Name "id"] } if {$Id==""} { return "" } return [GoNext "Up" $Id $Quoi $JoinCar $RecordsJoinCar] } proc GoNext {UpDown Id {Quoi ""} {JoinCar ""} {RecordsJoinCar ""}} { CanalSqlGeneOntology if {$Id=="" || $Id=="{}"} { return {} } if {[string equal -nocase $UpDown "Down"]} { set Source "term1_id" set Destin "term2_id" } else { set Source "term2_id" set Destin "term1_id" } regsub -nocase "^GO" $Quoi "" Quoi if {$Quoi==""} { set Quoi "id" } set LesTQ {} foreach Q [split $Quoi ","] { set TQ "t.$Q" if {[regexp {\.} $Q]} { set TQ $Q } lappend LesTQ $TQ } set TQs [join $LesTQ ","] if { ! [regexp {^[0-9]+$} $Id]} { set Id [GoInfo $Id "id"] } set FlatOuList "-flatlist" if {$JoinCar!=""} { set FlatOuList "-list" } set IsA [SqlExec "select id from term where name='is_a'"] set PartOf [SqlExec "select id from term where name='part_of'"] set Relatives [SqlExec "select $TQs from term t, term2term l \ where l.$Source=$Id \ and l.$Destin=t.id \ and (l.relationship_type_id=$IsA or l.relationship_type_id=$PartOf)\ and t.is_obsolete=0;" $FlatOuList] if {$JoinCar!=""} { set LesR {} foreach R $Relatives { set Champ [join $R $JoinCar] lappend LesR $Champ } set Relatives $LesR } if {$RecordsJoinCar!=""} { set Relatives [join $Relatives $RecordsJoinCar] } return $Relatives } proc GoWalk {UpDown Id Level Keys {MaxLevel ""} {JoinCar ""} } { if {$MaxLevel==""} { set MaxLevel 999999 } #Espionne "Walk [string repeat " " $Level] $Id [GoInfo $Id "acc,name" "=" "GetFirstValue"]" #rR on met +1 pour ne pas prendre le starting GO mais que les fils if {[regexp {^\+} $Level]} { regsub {^\+} $Level "" Level } else { GoCollectInfo [GoInfo $Id $Keys $JoinCar] } if {[string equal -nocase $UpDown "Here"]} { return } incr Level if {$Level>$MaxLevel} { return } set Relatives [GoNext $UpDown $Id] foreach R $Relatives { if {$R==1} { continue } GoWalk $UpDown $R $Level $Keys $MaxLevel $JoinCar } return }