#rR EleGen_proc.tcl #rR attention il y a une version dans /home/ripp/gscope/AtelierGScope/EleGen_proc.tcl #rR et dans /home/nguefack/EleGen/EleGen_proc.tcl #rR Penser à les synchroniser !!! #rR On peut tout refaire avec DoAllPourTous #rR Et interroger avec EleGen et AllEleGen #rR On crée des simili genomes avec des 1 2 3 4 5 6 7 8 9 ou X (ce sont les Xdni) #rR X=exon 9=FirstExon 8=5UTR 7=3UTR 6=Boundary 5=Promoter 4=Intron 3=1to5kb 2=Enhancer 1=Intergen (voir AnnotType) #rR On crée aussi un Final qui contient ces types en mettant en priorité X puis 9 puis 8 ... #rR le 9 8 7 sont sytématiquement écrasés par X car ce sont aussi des eXons #rR Pour pouvoir les détecter j'ai voulu faire la chose suivante : #rR J'ai rajouté un truc Ultime (=7 par exemple) pour créer les Xdn sans tenir compte de X 9 8 (pour l'exemple 7) ... etc. #rR Mais ça ne marche pas comme je crois ... #rR A supprimer je pense. #rR En parallele j'ai aussi créé des MotifsMapping7.txt qui ne contiennent que les types concernés. #rR On ppeut les créer avec les EleGen Chri 7 ListOf D mais comme les D ne sont pas contigus #rR il faudrait faire des de ChriInfos7 et ChriBornes7 qui permettraient la contiguite. proc AnnotRep {} { return "/genomics/link/EleGen/code" # return "/home/nguefack/EleGen/motifsNor_15-4" } proc DoAllPourTous {{Premier ""} {Dernier ""}} { #rR c'est ici qu'on lance tout ... #rR Attention les noms de fiheirs ne sont pas encore spécifique au MappingOfMotifsWithLengtAndCardinality ... A faire. if {$Premier==""} { set Premier 1 } if {$Dernier==""} { set Dernier 24 } CreateChrAnnotFiles set LesFicInfos {} foreach Chr [ListOfChr] { Espionne $Chr AnnotXdn $Chr AnnotXdnFinal $Chr set FicInfos [InfosEtBornesDuFinal $Chr] lappend LesFicInfos $FicInfos } CreateAllChrFinal DecompteGeneral CreateMotifsMapping "" return "All is done" } proc CreateMotifRecouvertParExon {FichierATrier} { set Fichier $FichierATrier set LeNew {} foreach Ligne [LesLignesDuFichier $Fichier] { # ici j'ai pas de slash if { ! [regexp / $Ligne]} { lappend LeNew $Ligne ; continue } # ici j'ai un slash set LesMots [LesMotsDeLaLigne $Ligne] lassign $LesMots Chr D F L T1 DO1 FO1 C1 Start1 Stop1 CC1 SS1 FF1 Length1 Brin1 Id1 Ucsc1 Gi1 Gn1 Type1 Slash T2 DO2 FO2 C2 Start2 Stop2 CC2 SS2 FF2 Length2 Brin2 Id2 Ucsc2 Gi2 Gn2 Type2 # 1er cas if {$D<=$FO1} { set NewLigne "$Chr $D $F [expr $FO1-$D+1] $T1 $DO1 $FO1 $C1 $Start1 $Stop1 $CC1 $SS1 $FF1 $Length1 $Brin1 $Id1 $Ucsc1 $Gi1 $Gn1 $Type1" lappend LeNew $NewLigne ; continue } # 2eme cas if {$F>=$DO1} {set NewLigne2 "$Chr $D $F [expr $F-$DO1+1] $T1 $DO1 $FO1 $C1 $Start1 $Stop1 $CC1 $SS1 $FF1 $Length1 $Brin1 $Id1 $Ucsc1 $Gi1 $Gn1 $Type1" lappend LeNew $NewLigne2 } } SauveLesLignes $LeNew dans $Fichier } proc EssaieListeRandom { FichierATrier } { set LeNew {} set Fichier $FichierATrier set LesLignes [LesLignesDuFichier $Fichier] set LesLignes [lsort -command TrieListRandom -increasing $LesLignes] SauveLesLignes $LesLignes dans $Fichier } proc TrieListRandom { a b } { lassign $a a0 a1 a2 lassign $b b0 b1 b2 if {$a0 > $b0} {return 1} if {$a0 < $b0} {return -1} if {$a1 > $b1} {return 1} if {$a1 < $b1} {return -1} if {$a2 > $b2} {return 1} if {$a2 < $b2} {return -1} if {$a2 == $b2} {return 0} } proc TranfoChr {FichierATranfoLeChr} { set Fichier $FichierATranfoLeChr set LeNew {} foreach Ligne [LesLignesDuFichier $FichierATranfoLeChr] { set LesMots [LesMotsDeLaLigne $Ligne] lassign $LesMots Chr S E L Strand Symbol Type set Chr [BonChr $Chr] set NewLigne "$Chr $S $E $L $Strand $Symbol $Type" lappend LeNew $NewLigne } SauveLesLignes $LeNew dans $Fichier } ####### à reverifier EditMotifsFile proc EditMotifsFileAvecArgument {FichierAEditer} { set Fichier $FichierAEditer set i 0 set LeNew {} foreach Ligne [LesLignesDuFichier $Fichier] { if {[regexp "^Code" $Ligne]} {incr i ; continue} if {[regexp "^Sequence" $Ligne]} {continue} set LesMots [split $Ligne ","] if {$LesMots=={}} {continue} lassign $LesMots Sequence S E L F U set Chr [BonChr $Chr] set NewLigne "Chr$i $S $E $L $F $U" lappend LeNew $NewLigne } SauveLesLignes $LeNew dans $Fichier } proc EditMotifsFileSansArgument {} { set Fichier "/home/nguefack/random/problem/ChrAll_5_5_Ran.bed" set i 0 set LeNew {} foreach Ligne [LesLignesDuFichier $Fichier] { if {[regexp "^Code" $Ligne]} {incr i ; continue} if {[regexp "^Sequence" $Ligne]} {continue} if {[regexp "^ " $Ligne]} {continue} set LesMots [split $Ligne ","] if {$LesMots=={}} {continue} lassign $LesMots Sequence S E L F U set NewLigne "Chr$i $S $E" lappend LeNew $NewLigne } SauveLesLignes $LeNew dans "/home/nguefack/random/problem/MotifRan_5_5.txt" } proc MappingOfMotifsWithLengtAndCardinalityPourTousRandomLevure {{NbCodon ""} {Cardinalite ""} {Coderandom ""} {AllFicBed ""}} { #rR Creation du nouveau mapping des m if {$AllFicBed==""} { set AllFicBed "/home/nguefack/random/levure/levure_R64/MotifLevure_${NbCodon}_${Cardinalite}_${Coderandom}.txt" } Sauve "" dans $AllFicBed foreach Chr [ListOfChr] { set FicBed [MappingOfMotifsWithLengtAndCardinalityRandomLevure $Chr $NbCodon $Cardinalite $Coderandom] AppendAuFichier $AllFicBed [ContenuDuFichier $FicBed] } return $AllFicBed } proc MappingOfMotifsWithLengtAndCardinalityRandomLevure {Chr {NbCodon ""} {Cardinalite ""} {Coderandom ""} {FicBed ""}} { if {$NbCodon==""} { set NbCodon 5 } set Window [expr $NbCodon*3] if {$Cardinalite==""} { set Cardinalite 4 } if {$FicBed==""} { set FicBed "/home/nguefack/random/rando/${Chr}_${NbCodon}_${Cardinalite}_${Coderandom}.txt" } set chr [string tolower $Chr] regsub "chr0" $chr "chr" chr set Fasta "/home/nguefack/random/levure/levure_R64/$chr.fa" if {[FileAbsent $Fasta]} { Espionne "$Fasta dosn no exist. I skip." ; continue } # exec /home/ripp/gscope/AtelierGscope/RunCC.sh $Fasta $Window $Cardinalite $FicBed exec /home/nguefack/gscoperso/RunRanAllCC.sh $Fasta $Window $Cardinalite $Coderandom $FicBed return $FicBed } proc MappingOfMotifsWithLengtAndCardinalityPourTousRandom {{NbCodon ""} {Cardinalite ""} {Coderandom ""} {AllFicBed ""}} { #rR Creation du nouveau mapping des m if {$AllFicBed==""} { set AllFicBed "/home/nguefack/random/Human/Motif_${NbCodon}_${Cardinalite}_${Coderandom}.txt" } Sauve "" dans $AllFicBed foreach Chr [ListOfChr] { set FicBed [MappingOfMotifsWithLengtAndCardinalityRandom $Chr $NbCodon $Cardinalite $Coderandom] AppendAuFichier $AllFicBed [ContenuDuFichier $FicBed] } return $AllFicBed } proc MappingOfMotifsWithLengtAndCardinalityRandom {Chr {NbCodon ""} {Cardinalite ""} {Coderandom ""} {FicBed ""}} { if {$NbCodon==""} { set NbCodon 5 } set Window [expr $NbCodon*3] if {$Cardinalite==""} { set Cardinalite 4 } if {$FicBed==""} { set FicBed "/home/nguefack/random/rando/${Chr}_${NbCodon}_${Cardinalite}_${Coderandom}.txt" } set chr [string tolower $Chr] regsub "chr0" $chr "chr" chr regsub "chr23" $chr "chrX" chr regsub "chr24" $chr "chrY" chr set Fasta "/home/nguefack/stage/human-ucsc-hg19/transfo-test/motif_15-4/$chr.txt" if {[FileAbsent $Fasta]} { Espionne "$Fasta dosn no exist. I skip." ; continue } # exec /home/ripp/gscope/AtelierGscope/RunCC.sh $Fasta $Window $Cardinalite $FicBed exec /home/nguefack/gscoperso/RunRanAllCC.sh $Fasta $Window $Cardinalite $Coderandom $FicBed return $FicBed } proc MappingOfMotifsWithLengtAndCardinalityPourTousLevure {{NbCodon ""} {Cardinalite ""} {AllFicBed ""}} { #rR Creation du nouveau mapping des m if {$AllFicBed==""} { set AllFicBed "/home/nguefack/random/levure/levure_R64/MotifNormo_${NbCodon}_${Cardinalite}.txt" } Sauve "" dans $AllFicBed foreach Chr [ListOfChr] { set FicBed [MappingOfMotifsWithLengtAndCardinalityLevure $Chr $NbCodon $Cardinalite] AppendAuFichier $AllFicBed [ContenuDuFichier $FicBed] } return $AllFicBed } proc MappingOfMotifsWithLengtAndCardinalityLevure {Chr {NbCodon ""} {Cardinalite ""} {FicBed ""}} { if {$NbCodon==""} { set NbCodon 5 } set Window [expr $NbCodon*3] if {$Cardinalite==""} { set Cardinalite 4 } if {$FicBed==""} { set FicBed "/home/nguefack/random/normo/${Chr}_${NbCodon}_${Cardinalite}.txt" } set chr [string tolower $Chr] regsub "chr0" $chr "chr" chr set Fasta "/home/nguefack/random/levure/levure_R64/$chr.fa" if {[FileAbsent $Fasta]} { Espionne "$Fasta dosn no exist. I skip." ; continue } exec /home/ripp/gscope/AtelierGscope/RunCC.sh $Fasta $Window $Cardinalite $FicBed return $FicBed } proc MappingOfMotifsWithLengtAndCardinalityPourTous {{NbCodon ""} {Cardinalite ""} {AllFicBed ""}} { #rR Creation du nouveau mapping des m if {$AllFicBed==""} { set AllFicBed "/home/nguefack/random/Human/MotifNormoHuman_${NbCodon}_${Cardinalite}.bed" } Sauve "" dans $AllFicBed foreach Chr [ListOfChr] { set FicBed [MappingOfMotifsWithLengtAndCardinality $Chr $NbCodon $Cardinalite] AppendAuFichier $AllFicBed [ContenuDuFichier $FicBed] } return $AllFicBed } proc MappingOfMotifsWithLengtAndCardinality {Chr {NbCodon ""} {Cardinalite ""} {FicBed ""}} { if {$NbCodon==""} { set NbCodon 5 } set Window [expr $NbCodon*3] if {$Cardinalite==""} { set Cardinalite 4 } if {$FicBed==""} { set FicBed "/home/nguefack/random/normo/${Chr}_${NbCodon}_${Cardinalite}.bed" } set chr [string tolower $Chr] regsub "chr0" $chr "chr" chr regsub "chr23" $chr "chrX" chr regsub "chr24" $chr "chrY" chr set Fasta "/home/nguefack/stage/human-ucsc-hg19/transfo-test/motif_15-4/$chr.txt" if {[FileAbsent $Fasta]} { Espionne "$Fasta dosn no exist. I skip." ; continue } exec /home/ripp/gscope/AtelierGscope/RunCC.sh $Fasta $Window $Cardinalite $FicBed return $FicBed } proc BonChr Chr { #rR Nous nommerons toujours les chromosomes Chr01 à Chr25 (X=23, Y=24, M=25) regsub -nocase "Chr" $Chr "Chr" Chr if {[regexp -nocase {^Chr([1-9])$} $Chr Match N]} { set Chr "Chr0$N" } regsub -nocase "ChrX" $Chr "Chr23" Chr regsub -nocase "ChrY" $Chr "Chr24" Chr regsub -nocase "ChrM" $Chr "Chr25" Chr return $Chr } proc MotifMapping {Ou Qui Quoi} { global MotMap #rR Permet d'interroger les Motifs Mappes ... #rR à ne pas confondre avec EleGen ou AllEleGen ... #rR MotifMapping F ListOf Gn #rR MotifMapping X ListOf Gn #rR MotifMapping 6 ListOf Gn #rR MotifMapping X Nb Motif #rR MotifMapping 8 ListOf NbMotifPerId #rR MotifMapping X 3_Motifs ListOfId #rR etc. voir ci-dessous if {[regexp -nocase "^F" $Ou]} { set Ou "F" } else { set Ou [AnnotType $Ou T] } if {$Ou==""} { return "usage: MotifMapping X ListOf Gn or MotifMapping Intron ADAM30 ListOfD" } if {[info exists MotMap($Ou,$Qui,$Quoi)]} { return $MotMap($Ou,$Qui,$Quoi) } if {[info exists MotMap($Ou,"EstCharge")]} { return "" } set MotMap($Ou,"EstCharge") 1 if {$Ou=="F"} { set FichierMotifsMapping "[AnnotRep]/MotifsMapping.txt" } else { set FichierMotifsMapping "[AnnotRep]/MotifsMapping$Ou.txt" } if {[FileAbsent $FichierMotifsMapping]} { set FichierMotifsMapping [CreateMotifsMapping] } #Chr01 41215 41244 30 1 41082 64090 1 41082 64090 chr1 41082 64090 23009 * intergenic:2 NA NA NA hg19_genes_intergenic set Ieme 0 foreach Ligne [lrange [LesLignesDuFichier $FichierMotifsMapping] 0 end] { incr Ieme #if {$Ieme%10==1} { Espionne $Ligne } set LesMots [LesMotsDeLaLigne $Ligne] foreach K {Slash T2 DO2 FO2 C2 Start2 Stop2 CC2 SS2 FF2 Length2 Brin2 Id2 Ucsc2 Gi2 Gn2 Type2} { set $K "" } if {$Ou=="F"} { lassign $LesMots Chr D F L T1 DO1 FO1 C1 Start1 Stop1 CC1 SS1 FF1 Length1 Brin1 Id1 Ucsc1 Gi1 Gn1 Type1 Slash T2 DO2 FO2 C2 Start2 Stop2 CC2 SS2 FF2 Length2 Brin2 Id2 Ucsc2 Gi2 Gn2 Type2 } else { lassign $LesMots Chr D F L T1 DO1 FO1 CC1 SS1 FF1 Length1 Brin1 Id1 Ucsc1 Gi1 Gn1 Type1 Slash T2 DO2 FO2 C2 Start2 Stop2 CC2 SS2 FF2 Length2 Brin2 Id2 Ucsc2 Gi2 Gn2 Type2 set C1 $T1 set Start1 $DO1 set Stop1 $FO1 } lappend MotMap($Ou,$T1,ListOf,Id) $Id1 lappend MotMap($Ou,ListOf,Id) $Id1 lappend MotMap($Ou,$Id1,ListOfD) $D lappend MotMap($Ou,$Id1,ListOfF) $F set MotMap($Ou,$Id1,Strand) $Brin1 incr MotMap($Ou,Nb,Motif) #if {$Ieme%10==1} { Espionne "Mots $LesMots" } if {$Gn1!="" && $Gn1!="NA"} { lappend MotMap($Ou,$T1,ListOfGn) $Gn1 lappend MotMap($Ou,ListOf,Gn) $Gn1 lappend MotMap($Ou,$Gn1,ListOfD) $D lappend MotMap($Ou,$Gn1,ListOfF) $F set MotMap($Ou,$Gn1,Strand) $Brin1 } if {0 && $Slash!=""} { if {0} { Espionne $Ligne foreach K {Chr D F L T1 DO1 FO1 C1 Start1 Stop1 CC1 SS1 FF1 Length1 Brin1 Id1 Ucsc1 Gi1 Gn1 Type1 Slash T2 DO2 FO2 C2 Start2 Stop2 CC2 SS2 FF2 Length2 Brin2 Id2 Ucsc2 Gi2 Gn2 Type2} { Espionne "$K [set $K]" } exit } if {$Gn2!="NA"} { lappend MotMap($Ou,ListOf,Gn) $Gn2 } lappend MotMap($Ou,$Gn2,ListOfD) $D lappend MotMap($Ou,$Gn2,ListOfF) $F } } foreach T [AnnotType ListOf T] { if { ! [info exists MotMap($Ou,$T,ListOfGn)]} { set MotMap($Ou,$T,ListOfGn) {} } if { [info exists MotMap($Ou,$T,ListOfGn)]} { set MotMap($Ou,$T,ListOfGn) [lsort -unique $MotMap($Ou,$T,ListOfGn)] } if { ! [info exists MotMap($Ou,$T,ListOfId)]} { set MotMap($Ou,$T,ListOfId) {} } if { [info exists MotMap($Ou,$T,ListOfId)]} { set MotMap($Ou,$T,ListOfId) [lsort -unique $MotMap($Ou,$T,ListOfId)] } } if { ! [info exists MotMap($Ou,ListOf,Gn)]} { set MotMap($Ou,ListOf,Gn) {} } set MotMap($Ou,ListOf,Gn) [lsort -unique $MotMap($Ou,ListOf,Gn)] set MotMap($Ou,Nb,Gn) [llength $MotMap($Ou,ListOf,Gn)] foreach Gn $MotMap($Ou,ListOf,Gn) { set N [llength $MotMap($Ou,$Gn,ListOfD)] set MotMap($Ou,$Gn,NbMotif) $N lappend MotMap($Ou,ListOf,NbMotifPerGn) $N lappend MotMap($Ou,${N}_Motifs,ListOfGn) $Gn } if { ! [info exists MotMap($Ou,ListOf,NbMotifPerGn)]} { set MotMap($Ou,ListOf,NbMotifPerGn) {} } set MotMap($Ou,ListOf,NbMotifPerGn) [lsort -integer -unique $MotMap($Ou,ListOf,NbMotifPerGn)] if { ! [info exists MotMap($Ou,ListOf,Id)]} { set MotMap($Ou,ListOf,Id) {} } set MotMap($Ou,ListOf,Id) [lsort -unique $MotMap($Ou,ListOf,Id)] set MotMap($Ou,Nb,Id) [llength $MotMap($Ou,ListOf,Id)] foreach Id $MotMap($Ou,ListOf,Id) { set N [llength $MotMap($Ou,$Id,ListOfD)] set MotMap($Ou,$Id,NbMotif) $N lappend MotMap($Ou,ListOf,NbMotifPerId) $N lappend MotMap($Ou,${N}_Motifs,ListOfId) $Id } if { ! [info exists MotMap($Ou,ListOf,NbMotifPerId)]} { set MotMap($Ou,ListOf,NbMotifPerId) {} } set MotMap($Ou,ListOf,NbMotifPerId) [lsort -integer -unique $MotMap($Ou,ListOf,NbMotifPerId)] return [MotifMapping $Ou $Qui $Quoi] } proc CreateMotifsMapping {{FichierATester ""} {TypeATester ""}} { #rR Ici on cree les fichier MotifsMapping.txt MotifsMappingX.txt MotifsMapping9.txt ... MotifsMapping1.txt #rR chacun concernant un type d'élément donné. #rR Pour cela on combine le fichier motif_list.bed avec les appels à 'EleGen Chr T ListOf D' et 'EleGen Chr T ListOf F' #rR Mais attention il y a deux manières de parcourir les ListOf D et F #rR - quand on traite le fichier final (MotifsMapping.txt) qui contient toutes les bornes contigues on peut avancer tranquille #rR - quand on traite les fichiers X 9 8 ... (MotifsMappingX.txt ... ) il faut recommencer à relire tous les ListOf D depuis le début. if {$TypeATester=="DoAll"} { set LesCrees {} foreach T [AnnotType ListOf T] { lappend LesCrees [CreateMotifsMapping $T] } lappend LesCrees [CreateMotifsMapping ""] return $LesCrees } set Contigu [string equal $TypeATester ""] if {$TypeATester==""} { set FichierMotifsMapping $FichierATester regsub ".txt" $FichierMotifsMapping "_Mapping.txt" FichierMotifsMapping ### set FichierMotifsMapping "/home/nguefack/EleGen/MotifsMappingAll15-4.txt" } else { set FichierMotifsMapping $FichierATester regsub ".txt" $FichierMotifsMapping "_Mapping$TypeATester.txt" FichierMotifsMapping } if {$TypeATester==""} { set TypeATester "F" } set ChrPrec "" set LeResultat {} # set onyest 0 foreach Ligne [LesLignesDuFichier $FichierATester] { # if {[regexp "Chr12 53689819 53689833" $Ligne]} {set onyest 1 } #Chr12 53689819 53689833 #Chr12 53689822 53689836 # if {!$onyest} {continue} lassign [LesMotsDeLaLigne $Ligne] Chr D F set Chr [BonChr $Chr] if { ! [regexp -nocase "Chr" $Chr]} { Espionne "Ligne incorrecte =$Ligne=" ; continue } if {$Chr!=$ChrPrec} { set K 0 set LesD [EleGen $Chr $TypeATester ListOf D] set LesF [EleGen $Chr $TypeATester ListOf F] set I 0 set DC [lindex $LesD $I] set FC [lindex $LesF $I] } set ChrPrec $Chr incr K # if {$K%100==1} { Espionne "$Chr $ChrPrec $K $I $D $F //// [lrange $LesD $I-3 $I+3]" } # Espionne "$I motif $Ligne" set Trouve 0 if { ! $Contigu } { set I 0 } #rR Attention on recommence au debut pour checher le motif courant. if { $I > 0 } { incr I -2 } while 1 { # if { [regexp "Chr12 53689819 53689833" $Ligne] } { continue } # {#Espionne "entre avec $I $DC $FC" set DC [lindex $LesD $I] set FC [lindex $LesF $I] if {$DC <= $D && $D <=$FC} { # Espionne " D entre avec $I $DC $FC" # set J $I # incr J # Espionne " D J $J [lindex $LesD $J] [lindex $LesF $J] " set Trouve 1 break } incr I set DC [lindex $LesD $I] set FC [lindex $LesF $I] # } # Espionne "entre avec $I $DC $FC" # if {[regexp "Chr12 53689819 53689833" $Ligne]} {Espionne "-- $I $DC $FC"} #Espionne "$I $DC $FC $Ligne" if {$DC==""} { break; FaireLire "Aie Aie Aie DC non trouve en $I $Chr $D $F" ; break } if {$FC==""} { break; FaireLire "Aie Aie Aie FC non trouve en $I $Chr $D $F" ; break } } if { ! $Trouve } { Espionne "non trouve $DC $FC de =$Ligne= " continue # exit } set TduD [EleGen $Chr $TypeATester $DC E] set TduF [EleGen $Chr $TypeATester $FC E] set Info [EleGen $Chr $TypeATester $DC Info] set DebutMessage "$Chr $D $F [expr $F-$D+1]" set LaSuiteDuMessage [list "$TduD $Info"] if { ! $Contigu } { set I 0 } #rR Attention on recommence au debut pour chercher le motif courant. set Trouve 0 set PremiereFois 1 while 1 { if {$DC <= $F && $F <=$FC} { Espionne " F entre avec $I $DC $FC" set Trouve 1 if { ! $PremiereFois } { lappend LaSuiteDuMessage "$TduF $Info" } break } set PremiereFois 0 #rR Ici on n'a pas trouve la fin dans le meme morceau ... incr I set DC [lindex $LesD $I] set FC [lindex $LesF $I] set TduF [EleGen $Chr $TypeATester $FC E] set Info [EleGen $Chr $TypeATester $DC Info] if {$Contigu} { lappend LaSuiteDuMessage "$TduF $Info" } if {$DC==""} { break; FaireLire "Aie Aie Aie DC non trouve $Chr $D $F" ; break } if {$FC==""} { break; FaireLire "Aie Aie Aie FC non trouve $Chr $D $F" ; break } } if { ! $Trouve } { continue Espionne "non trouve $Ligne" #exit } set LaSuiteDuMessage [lsort -decreasing $LaSuiteDuMessage] set Message "$DebutMessage [join $LaSuiteDuMessage { / }]" #Espionne $Message lappend LeResultat $Message } SauveLesLignes $LeResultat dans $FichierMotifsMapping return "ok" } proc VerifieAllChrFinal {} { set ChrPrecedent "" set Status Ok foreach Ligne [LesLignesDuFichier "[AnnotRep]/AllChrFinalWithT.txt"] { lassign [LesMotsDeLaLigne $Ligne] Chr D F if {$Chr eq $ChrPrecedent && $D!=[incr FPrecedent]} { FaireLire "oups $Chr $FPrecedent $D $F" ; set Status "Bad" } set FPrecedent $F set ChrPrecedent $Chr } return $Rate } proc DecompteGeneral {} { set LaSortie {} foreach T [AnnotType ListOf T] { set Code [AnnotType $T Code] lappend LesHeader [format "%8s %s" $Code $T] } lappend LaSortie " [join $LesHeader { }]" foreach Chr [ListOfChr] { set LaLigne {} foreach T [AnnotType ListOf T] { if { ! [info exists Compte(All,$T)]} { set Compte(All,$T) 0 } set N [llength [EleGen $Chr $T ListOf D]] incr Compte(All,$T) $N lappend LaLigne [format "%10d" $N] } lappend LaSortie "$Chr [join $LaLigne { }]" } set LaLigne {} foreach T [AnnotType ListOf T] { lappend LaLigne [format "%10d" $Compte(All,$T)] } lappend LaSortie "All [join $LaLigne { }]" set LaLigne {} foreach N [Decompte] { lappend LaLigne [format "%10d" $N] } lappend LaSortie "Final [join $LaLigne { }]" set Sortie [join $LaSortie "\n"] return [Sauve $Sortie dans "[AnnotRep]/DecompteGeneral.txt"] } proc Decompte {{GetWhat ""}} { foreach Ligne [LesLignesDuFichier "[AnnotRep]/AllChrFinal.txt"] { set T [lindex [LesMotsDeLaLigne $Ligne] 4] incr Decompte($T) # Espionne "$T $Decompte($T)" } foreach T [AnnotType ListOf T] { set Code [AnnotType $T Code] if { ! [info exists Decompte($T)]} { set Decompte($T) 0 } lappend LeDecompte $Decompte($T) lappend LeBeauDecompte [format "%s %7d %s" $T $Decompte($T) $Code] } Espionne $LeDecompte if {$GetWhat=="Nice"} { return $LeBeauDecompte } return $LeDecompte } proc CreateAllChrFinal {{Fichier ""}} { if {$Fichier==""} { set Fichier "[AnnotRep]/AllChrFinal.txt" } set LeTout {} foreach I [list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24] { set L [EleGen Chr$I F ListOf All] LConcat LeTout $L } return [SauveLesLignes $LeTout dans $Fichier] } proc BaseCount {} { foreach T [concat [AnnotType ListOf T] [list F]] { set Total 0 foreach Chr [ListOfChr] { foreach D [EleGen $Chr $T ListOf D] F [EleGen $Chr $T ListOf F] { set Size [expr $F-$D+1] incr Total $Size } } if {0} { set FichierMotMap "[AnnotRep]/MotifsMapping.txt" set Type [AnnotType $T Type] if {$T==7 || $T==8 || $T==9} { set FichierMotMap "[AnnotRep]/MotifsMapping$T.txt" } if {$T=="F"} { set NbMotif [MotifMapping $T Nb Motif] } else { set NbMotif [exec grep -c $Type $FichierMotMap] } } set Ratio 0 if {$NbMotif!=""} { set Ratio [expr (1000000000*$NbMotif)/$Total] } set Code [AnnotType $T Code] Espionne [format "%9s %7d %11d %7d pour 1Gb" $Code $NbMotif $Total $Ratio] } } proc TestAllEleGen {} { set SizeFMin 99999999999 set SizeFMax -1 foreach Gn [AllEleGen ListOf Gn] { if {$Gn=="" || $Gn=="NA"} { continue } set Size [AllEleGen $Gn Size] if {$Size>1000000} { continue; Espionne $Gn } if {$Size==""} { continue } if { ! [info exists SizeMin(F)]} { set SizeMin(F) $Size ; set SizeMax(F) $Size } set SizeMin(F) [Mini $SizeMin(F) $Size] set SizeMax(F) [Maxi $SizeMax(F) $Size] foreach T [AnnotType ListOf T] { set Size [AllEleGen $Gn Size $T] if {$Size==""} { continue } if { ! [info exists SizeMin($T)]} { set SizeMin($T) $Size ; set SizeMax($T) $Size } set SizeMin($T) [Mini $SizeMin($T) $Size] set SizeMax($T) [Maxi $SizeMax($T) $Size] } } lappend LaSortie [format "%9s %9d %9d" Final $SizeMin(F) $SizeMax(F)] foreach T [lreverse [AnnotType ListOf T]] { set Code [AnnotType $T Code] if { ! [info exists SizeMin($T)]} { continue } lappend LaSortie [format "%9s %9s %9s" $Code $SizeMin($T) $SizeMax($T)] } return $LaSortie } proc AllEleGen {{Qui ""} {Quoi ""} {Ou ""}} { global AllEleGen #rR EleGene permet d'interroger tous les chromosomes en même temps #rR Ce n'est qu'une mémorisation de EleGen Chromo par Chromo #rR Attention ! Pour le charger plus vite il exists un fichier Memo #rR Si onchange quelque chose (programme ou données de départ il faut le recharger #rR pour cela qds Zero AllEleGen Redo_ #rR (doit être fait en qds (donc au nom de ripp) pour avoir les droits !!!!!!) set FichierMemo "[AnnotRep]/AllEleGen.txt" if {[regexp -nocase "^ReDo_" $Qui]} { if {[file exists $FichierMemo]} { file delete $FichierMemo } if {[info exists AllEleGen]} { unset AllEleGen } regsub -nocase "^ReDo_" $Qui "" Qui return [AllEleGen $Qui $Quoi $Ou] } if {$Ou!=""} { set Ou [AnnotType $Ou "T"] } if {[info exists AllEleGen($Qui,$Quoi,$Ou)]} { if { 0 && [PourWscope]} { return "
[join $AllEleGen($Qui,$Quoi,$Ou) \n]\n" } return $AllEleGen($Qui,$Quoi,$Ou) } if {[info exists AllEleGen("EstCharge")]} { if { 0 && [info exists AllEleGen($Qui,$Quoi,)]} { Espionne coucou; return $AllEleGen($Qui,$Quoi,) } return "" } set AllEleGen("EstCharge") 1 if {[file exists $FichierMemo]} { array set AllEleGen [ContenuDuFichier $FichierMemo] return [AllEleGen $Qui $Quoi $Ou] } foreach Chr [lrange [ListOfChr] 0 end] { set LesGn [EleGen $Chr "F" ListOf Gn] set AllEleGen($Chr,ListOfGn,) $LesGn foreach Gn $LesGn { lappend AllEleGen(ListOf,Gn,) $Gn set AllEleGen($Gn,Chr,) $Chr set AllEleGen($Gn,ListOfD,) [EleGen $Chr "F" $Gn ListOfD] set AllEleGen($Gn,ListOfF,) [EleGen $Chr "F" $Gn ListOfF] set Left [lindex $AllEleGen($Gn,ListOfD,) 0] set Right [lindex $AllEleGen($Gn,ListOfF,) end] set AllEleGen($Gn,Cover,) "$Left $Right" set AllEleGen($Gn,Size,) [expr $Right-$Left+1] } foreach T [AnnotType ListOf T] { foreach Gn [EleGen $Chr $T ListOf Gn] { if {$Gn=="" || $Gn=="NA"} { continue } lappend AllEleGen(ListOf,Gn,$T) $Gn set AllEleGen($Gn,ListOfD,$T) [EleGen $Chr $T $Gn ListOfD] set AllEleGen($Gn,ListOfF,$T) [EleGen $Chr $T $Gn ListOfF] set Left [lindex $AllEleGen($Gn,ListOfD,$T) 0] set Right [lindex $AllEleGen($Gn,ListOfF,$T) end] set AllEleGen($Gn,Cover,$T) "$Left $Right $Chr" set AllEleGen($Gn,Size,$T) [expr $Right-$Left+1] set AllEleGen($Gn,ListOf,Id) [EleGene $Chr $T $Gn ListOfId] foreach Id $AllEleGen($Gn,ListOf,Id) { set AllEleGen($Id,Gn,) $Gn } } #rR on pourrait encore tout mémoriser pour les Id ... } } Sauve [array get AllEleGen] dans $FichierMemo return [AllEleGen $Qui $Quoi $Ou] } proc EleGen {{Chr ""} {Type ""} {Qui ""} {Quoi ""}} { global EleGen #rR EleGen permet d'interrgoger les annotations des ELEments du GENome #rR EleGen Chr01 X ListOf Gn #rR EleGen Chr01 X NOTCH2 ListOfD #rR EleGen Chr01 X NOTCH2 ListOfF #rR EleGen Chr01 X NOTCH2 ListOfId #rR EleGen Chr01 X ListOf Id #rR EleGen Chr01 X ListOf All #rR EleGen Chr01 X exon:57053 D #rR #rR EleGen Chr01 6 ListOf Id #rR ^ the type can be 0 1 2 3 4 5 6 7 8 9 X #rR use AnnotType ListOf T to get the possible list of one letter types #rR and AnnotType 6 Type to get the Type #rR or AnnotType 6 Type to get its Code #rR use AnnotType ListOf Code to get the possible codes #rR use AnnotType ListOf Type to get the possible types #rR #rR Chr01 to Chr25 (it's also possible to use ChrX=Chr23, ChrY=Chr24, ChrM=Chr25) #rR 2017/02/24 #rR Raymond if {$Chr==""} { set Chr "Help" } if {[string equal -nocase $Chr "Help"]} { foreach Ligne [split [info body EleGen] "\n"] { if { ! [regexp "^ +#rR " $Ligne]} { continue } regsub "^ +#rR " $Ligne "" Ligne lappend LeHelp $Ligne } return [join $LeHelp "\n"] } regsub -nocase "Chr" $Chr "Chr" Chr if {[regexp -nocase {^Chr([1-9])$} $Chr Match N]} { set Chr "Chr0$N" } regsub -nocase "ChrX" $Chr "Chr23" regsub -nocase "ChrY" $Chr "Chr24" regsub -nocase "ChrM" $Chr "Chr25" set T [AnnotType $Type T] Espionne $T if {[info exists EleGen($Chr,$T,$Qui,$Quoi)]} { if {0 && [PourWscope]} { return "
[join $EleGen($Chr,$T,$Qui,$Quoi) \n]\n" } if {1 && [PourWscope]} { return [join $EleGen($Chr,$T,$Qui,$Quoi) \n] } return $EleGen($Chr,$T,$Qui,$Quoi) } if {[info exists EleGen($Chr,$T,EstCharge)]} { return "" } set EleGen($Chr,$T,EstCharge) 1 # 176049 176602 chr12 176049 176602 554 + exon:415858 uc001qhw.2 440073 IQSEC3 hg19_genes_exons set FicInfo "[AnnotRep]/${Chr}_Infos$T" if {[FileAbsent $FicInfo]} { return "" } set EleGen($Chr,$T,Filename,) $FicInfo foreach Ligne [LesLignesDuFichier $FicInfo] { set LesMots [LesMotsDeLaLigne $Ligne] if {$T=="F"} { lassign $LesMots D F E DO FO C Start Stop Length Brin Id Ucsc Gi Gn Type } else { lassign $LesMots D F C Start Stop Length Brin Id Ucsc Gi Gn Type set E $T set DO $Start set FO $Stop } lappend EleGen($Chr,$T,ListOf,Id) $Id lappend EleGen($Chr,$T,ListOf,Gn) $Gn lappend EleGen($Chr,$T,ListOf,D) $D lappend EleGen($Chr,$T,ListOf,F) $F set EleGen($Chr,$T,$Id,D) $D set EleGen($Chr,$T,$Id,F) $F set EleGen($Chr,$T,$Id,Gn) $Gn set EleGen($Chr,$T,$Id,E) $E set EleGen($Chr,$T,$D,D) $D set EleGen($Chr,$T,$D,F) $F set EleGen($Chr,$T,$D,Id) $Id set EleGen($Chr,$T,$D,Gn) $Gn set EleGen($Chr,$T,$D,E) $E set EleGen($Chr,$T,$F,D) $D set EleGen($Chr,$T,$F,F) $F set EleGen($Chr,$T,$F,Id) $Id set EleGen($Chr,$T,$F,Gn) $Gn set EleGen($Chr,$T,$F,E) $E lappend EleGen($Chr,$T,$Gn,ListOfId) $Id lappend EleGen($Chr,$T,$Gn,ListOfD) $D lappend EleGen($Chr,$T,$Gn,ListOfF) $F lappend EleGen($Chr,$T,$E,ListOfId) $Id lappend EleGen($Chr,$T,$E,ListOfD) $D lappend EleGen($Chr,$T,$E,ListOfF) $F set EleGen($Chr,$T,$D,Info) $Ligne lappend EleGen($Chr,$T,ListOf,All) "$C $D $F [expr $F-$D+1] $E $Id $Gn $Type" lappend EleGen($Chr,$T,ListOf,Info) "$C $E $Ligne" } set EleGen($Chr,$T,ListOf,Id) [lsort -unique $EleGen($Chr,$T,ListOf,Id)] set EleGen($Chr,$T,ListOf,Gn) [lsort -unique $EleGen($Chr,$T,ListOf,Gn)] return [EleGen $Chr $T $Qui $Quoi] } proc AnnotType {{Qui ""} {Quoi ""}} { global AnnotType if {[info exists AnnotType($Qui,$Quoi)]} { return $AnnotType($Qui,$Quoi) } if {[info exists AnnotType("EstCharge")]} { set QUI [string range [string toupper $Qui] 0 3] if {[info exists AnnotType($QUI,$Quoi)]} { return $AnnotType($QUI,$Quoi) } return "" } set AnnotType("EstCharge") 1 set LesTypesCodes {} lappend LesTypesCodes "genes_intergenic 1 Intergene" lappend LesTypesCodes "enhancers_fantom 2 Enhancer" lappend LesTypesCodes "genes_1to5kb 3 1to5kb" lappend LesTypesCodes "genes_introns 4 Intron" lappend LesTypesCodes "genes_promoters 5 Promoter" lappend LesTypesCodes "genes_intronexonboundaries 6 Boundary" lappend LesTypesCodes "genes_3UTRs 7 3UTR" lappend LesTypesCodes "genes_5UTRs 8 5UTR" lappend LesTypesCodes "genes_firstexons 9 1stExon" lappend LesTypesCodes "genes_exons X Exon" foreach TC $LesTypesCodes { scan $TC "%s %s %s" Type T Code lappend AnnotType(ListOf,Type) $Type lappend AnnotType(ListOf,T) $T lappend AnnotType(ListOf,Code) $Code set AnnotType($Type,Type) $Type set AnnotType($Type,T) $T set AnnotType($Type,Code) $Code set AnnotType($T,Type) $Type set AnnotType($T,T) $T set AnnotType($T,Code) $Code set AnnotType($Code,Type) $Type set AnnotType($Code,T) $T set AnnotType($Code,Code) $Code set AnnotType([string range [string toupper $Code] 0 3],Type) $Type set AnnotType([string range [string toupper $Code] 0 3],T) $T set AnnotType([string range [string toupper $Code] 0 3],Code) $Code } set AnnotType(F,Type) Final set AnnotType(F,T) F set AnnotType(F,Code) Final return [AnnotType $Qui $Quoi] } proc CreateChrAnnotFiles {} { set N 0 foreach I [list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 X Y M] { incr N set NN [format "%2.2d" $N] set Nom "Chr$NN.annot" exec sh -c "grep '\"chr$I\"' annotations_genes.txt | sort -n -k 2 > [AnnotRep]/$Nom" lappend LesCrees $Nom } return $LesCrees } proc ListOfChr {{Premier ""} {Dernier ""}} { if {$Premier==""} { set Premier 1 } if {$Dernier==""} { set Dernier 25 } set LesChr {} foreach N [NombresEntre $Premier $Dernier] { set NN [format "%2.2d" $N] set Chr "Chr$NN" lappend LesChr $Chr } return $LesChr } proc AnnotXdn {{Chr ""}} { set Rep [AnnotRep] set FichierAnnot "$Rep/$Chr.annot" set FichierTypes "$Rep/AnnotTypes.txt" # "chr19" 481674 481793 120 "*" "enhancer:28085" NA NA NA "hg19_enhancers_fantom" # "chr19" 10654633 10655632 1000 "+" "promoter:66212" "uc010dxj.3" "84971" "ATG4D" "hg19_genes_promoters" set LesXdn {} set Min 999999999999 set Max -1 foreach Ligne [LesLignesDuFichier $FichierAnnot] { regsub -all {\"} $Ligne "" Ligne set LesMots [LesMotsDeLaLigne $Ligne] lassign $LesMots Ch Start Stop Length Brin Id Ucsc Gi Gn Type regsub {[a-z]+[0-9]+_} $Type "" Type lappend LesBornes($Type) "$Start $Stop" set InfoDe($Type,$Stop) $Ligne lappend LesGn $Gn set Min [Mini $Start $Min] set Max [Maxi $Stop $Max] } foreach Type [AnnotType ListOf Type] T [AnnotType ListOf T] { Espionne Espionne $Type if { ! [info exists LesBornes($Type)]} { Espionne "Bornes pour $Type non trouve"; continue } set I 0 set LesDF $LesBornes($Type) set LesDFTries [lsort -integer -index 0 $LesDF] Espionne "[llength $LesDFTries] element a traiter" set LesDFRetenus $LesDFTries set Superpose 1 set I 0 set J 1 set DF1 [lindex $LesDFTries $I] set DF2 [lindex $LesDFTries $J] set LesBons {} set LesInfos {} Espionne "$J $DF1 $DF2 avant boucle pour $Type" while 1 { if {$J%100==1} { Espionne "$J $DF1 $DF2" } lassign $DF1 D1 F1 lassign $DF2 D2 F2 if {$D1==$D2} { set F2 [Maxi $F1 $F2] set DF1 "$D1 $F2" incr J set DF2 [lindex $LesDFTries $J] if {$DF2==""} { # Espionne $DF1 lappend LesBons $DF1 lassign $DF1 D F lappend LesInfos "$DF1\t$InfoDe($Type,$F)" break } # Espionne "D1=D2" continue } if {$D2<=$F1} { set DF1 "$D1 [Maxi $F1 $F2]" incr J set DF2 [lindex $LesDFTries $J] if {$DF2==""} { # Espionne $DF1 lappend LesBons $DF1 lassign $DF1 D F lappend LesInfos "$DF1\t$InfoDe($Type,$F)" break } # Espionne "D2<=F1" continue } if {$F2<=$F1} { incr J set DF2 [lindex $LesDFTries $J] if {$DF2==""} { # Espionne $DF1 lappend LesBons $DF1 lassign $DF1 D F lappend LesInfos "$DF1\t$InfoDe($Type,$F)" break } # Espionne "F2<=F1" continue } if {$F1==$D2} { set DF1 "$D1 $F2" incr J set DF2 [lindex $LesDFTries $J] if {$DF2==""} { # Espionne $DF1 lappend LesBons $DF1 lassign $DF1 D F lappend LesInfos "$DF1\t$InfoDe($Type,$F)" break } # Espionne "F1=D2" continue } if {$F1<$D2} { # Espionne "$DF1" lappend LesBons "$DF1" lassign $DF1 D F lappend LesInfos "$DF1\t$InfoDe($Type,$F)" set DF1 $DF2 incr J set DF2 [lindex $LesDFTries $J] if {$DF2==""} { lappend LesBons "$DF1" lassign $DF1 D F lappend LesInfos "$DF1\t$InfoDe($Type,$F)" break } # Espionne "F1