Index by: file name | procedure name | procedure call | annotation
gscope_affiche.tcl (annotations | original source)

#rR gscope_affiche.tcl

proc PagePropre W {
    global PagePropre
    if {[info exists PagePropre($W)]} { return $PagePropre($W) }
    return ""
}

proc RechercheDansInfo {Texte {GetWhat ""}} {
    return [SearchInInfo $Texte $GetWhat]
}

proc SearchInInfo {Texte {GetWhat ""}} {
    #rR on stocke la Liste des Contenu Info
    global LCI NomDuLCI

    set Texte [string toupper $Texte]

    if { ! [info exists LCI]} {
	set LCI [list "TrululuLalere"]          ;#rR pour commencer la numérotation à 1     
	set I 0
	foreach Nom [ListeDesPABs] {
	    incr I
	    set Info [ExtraitInfo $Nom]
	    if {$Info != ""} {
		lappend LCI [string toupper $Info]
	    } else {
		lappend LCI [string toupper "Nom: $Nom"]
	    }
	    set NomDuLCI($I) $Nom
	}
    }
    set LesI [lsearch -all -regexp $LCI $Texte]
    set LesNomsTrouves {}
    foreach I $LesI {
	set Nom $NomDuLCI($I)
	lappend LesNomsTrouves $Nom
	lappend LesInfosTrouves "$Nom\n[lindex $LCI $I]\n"
    }
    if {[regexp -nocase "info" $GetWhat]} {
	return $LesInfosTrouves
    }
    return $LesNomsTrouves
}

proc DernierPAB {{Comment ""} {Format ""}} {
    if {$Comment==""} { set Comment "DansLaListe"} 
    switch $Comment {
	"EnPosition"  { scan [lindex [LesPABsDansLOrdre] end] "%s" Dernier }
	"DansLaListe" { set Dernier [lindex [ListeDesPABs] end] }
	"EnNumero"    { set Dernier [lindex [lsort [ListeDesPABs]] end] }
	default { FaireLire "wrong argument in DernierPAB" ; return [DernierPAB] }
    }
    if {$Format=="AvecBornes"} {
	return "$Dernier [Box $Dernier debut] [Box $Dernier fin] [Box $Dernier orient]"
    } else {
	return $Dernier
    }
}

proc TousToTFA {} {
    foreach F [glob "*.nuc"] {
	regsub ".nuc$" $F ".tfa" T
	regsub ".nuc$" $F "" T
	if {[file exists "$T.tfa"]} { continue }
	set TFA [SequenceFormatTFA [ContenuDuFichier $F] ">$T" "gcg"]
	Espionne [Sauve $TFA dans "$T.tfa"]
    }
    exit
}

proc ShowBlastFromSelection {Selection {Dir ""}} {
    if { ! [regexp "/" $Dir]} { set Dir "[RepertoireDuGenome]/$Dir" }
    foreach Mot [LesMotsDeLaLigne $Selection] {
	regsub -all {[><=\+]} $Mot "" Mot
	set Fichier "$Dir/$Mot"
	if {[FileExists $Fichier]} { return [AfficheFichier $Fichier "AvecSegAlignement"] }
    }
    return ""
}

proc SendToWeb Texte {
    Log "SendToWeb $Texte" [HomeRipp]/log/gscopehtmlserver.log
#   regsub -all {<} $Texte "\&lt;" Texte
#   regsub -all {>} $Texte "\&gt;" Texte
    return "<pre>$Texte</pre>"
}

proc Dismiss w {
    global PagePropre
    if {[info exists PagePropre($w)]} { unset PagePropre($w) }
    if {[PourWscope]} { return "<script language='javascript'>window.close()</script>'" }
    catch {after 10 destroy $w}
    return $w    
}

proc Affiche {Page {Maniere ""} {NomDuFichierOrigine ""}} {
    return [AfficheVariable $Page $Maniere $NomDuFichierOrigine]
}

proc AfficheVariable {Page {Maniere ""} {NomDuFichierOrigine ""}} {
    Wup "Cette proc est le coeur de Gscope"
    Wup "Most used procedure ... : "
    Wup "Shows the text Page in a listbox, with a lot of buttons."
    Wup "Copyright 1999 Raymond Ripp"
    
    Gs "Frame"
    
    if {$Page==""} { return "" }
    
    global VariableDeRetour
    global LesFenetresDePAB
    global PagePropre
    global CurrentGenome
    
    
    regsub -all {[;\[\]]} $NomDuFichierOrigine " " NomDuFichierOrigine ; #rR pour éviter les mauvaises surprises car il rique d'être interprété
	
	
    set Nom ""
    set Queue [file tail $NomDuFichierOrigine]
    
    set w [NomDe fenetre]
    
    set PagePropre($w) $Page
    regsub -all {\t} $PagePropre($w) "       " PagePropre($w)
    if {[info procs EstPABouTROUouTRNAouARN]!=""} {
	set NomPossible [file tail $NomDuFichierOrigine]
	if {$Nom==""} {
	    set NomPossible [file tail $NomDuFichierOrigine]
	    if { [EstPABouTROUouTRNAouARN $NomPossible] } { set Nom $NomPossible }
	}
	if {$Nom==""} {
	    set NomPossible [lindex [split $NomDuFichierOrigine "_"] 0]
	    if { [EstPABouTROUouTRNAouARN $NomPossible] } { set Nom $NomPossible }
	}
	if {$Nom==""} {
	    set NomPossible [lindex [split $NomDuFichierOrigine "_"] end]
	    if { [EstPABouTROUouTRNAouARN $NomPossible] } { set Nom $NomPossible }
	}
    }
    
    #    if {[PourWscope]} { return [Html_DuTexteTelQuel [set PagePropre($w)]] } 
    
    lappend LesFenetresDePAB($Queue) $w
    
    regsub -all " " $NomDuFichierOrigine "_" NomDuFichierOrigine
    
    if { $NomDuFichierOrigine == "" } {
	set NomDuFichierOrigine "Tsointsoin"
    }
    if {$Maniere=="AutoManiere" || $Maniere==""} {
	set Maniere [LaManierePourAffiche $NomDuFichierOrigine]
    }
    if {$Nom!="" && [info procs NomDeScene]!="" && [NomDeScene $Nom]!=""} {
	set Titre "[NomDeScene $Nom]   $NomDuFichierOrigine"
    } else {
	set Titre "$NomDuFichierOrigine"
    }
    set Header ""
    #    if { ! [OnTraite "RetGene"]&& [PourWscope]} { return [Html_TextToListbox  [set PagePropre($w)] $Titre $Header "" "ResetAndWaqqqitForButtons"] } 
    
    set Clavier $w.buttons
    if { ! [PourWscope]} {
	toplevel $w
	wm title $w "$Titre"
	wm iconname $w "$Titre"
	
	label $w.msg -wraplength 4i -justify left -text "$Titre"
	pack  $w.msg -side top
	
	frame  $Clavier
	pack   $Clavier -side bottom -fill x -padx 3m -pady 1m
    }
    
    set ForValidateOnly 0
    TouchePour $Clavier NouvelleGamme
    TouchePour $Clavier NouvelleCouleur "red"
    if { [regexp "AvecRetour" $Maniere] } {
	if {[regexp "AvecRetourPourInforme" $Maniere]} {
	    TouchePour $Clavier "Validate" "InformeSansDemanderParWscope $Nom \[selection get\]" "" "green"
	} else {
	    TouchePour $Clavier "Validate sel." "set VariableDeRetour($w) \[selection get\]"      "" "green"
	    TouchePour <2>      " /All"         "set VariableDeRetour($w) \[set PagePropre($w)\]" ""
	    TouchePour <3>      " / No!"        "set VariableDeRetour($w) {}"
	}
	if {[PourWscope]} { set ForValidateOnly 1 }
	TouchePour $Clavier NouvelleCouleur "pink"
    }
    TouchePour $Clavier "Dismiss"     "Dismiss $w" 
    TouchePour $Clavier "Dismiss_all" "DismissToutCePAB $Queue" "NoWeb"
    
    TouchePour $Clavier NouvelleCouleur "grey"
    TouchePour $Clavier "Display sel." "SendToWeb \[selection get\]"      "WebOnly"
    TouchePour <2>      "/Select all"   "onclick='return selectAll();'"   "WebOnly"
    TouchePour $Clavier "Save all"   "SaveAs      \[set PagePropre($w)\]" "NoWeb"
    TouchePour <2>      "/sel."      "SaveAs      \[selection get\]"      "NoWeb"
    TouchePour <3>      " /Edit"     "EditAndShow \[set PagePropre($w)\]" "NoWeb"
    TouchePour $Clavier "Memorize sel." "MemoSelection $w Memorize"       "NoWeb" "lightyellow"
    TouchePour <2>      "/Recall"       "MemoSelection $w Recall"         "NoWeb"
    TouchePour $Clavier NouvelleCouleur "grey"
    TouchePour $Clavier "Print"         "ImprimeLeTexte \[set PagePropre($w)\]"
    TouchePour <2>      "/Sort"         "TrieEtAffiche \[set PagePropre($w)\] Alpha $Maniere $NomDuFichierOrigine"
    TouchePour <3>      "/ask"          "TrieEtAffiche \[set PagePropre($w)\] Ask   $Maniere $NomDuFichierOrigine"
    TouchePour $Clavier "Copy"          "clipboard clear ; clipboard append \[selection get\]" "NoWeb"
    TouchePour <2>      "/Append"       "clipboard append \[selection get\]"                   "NoWeb"
    TouchePour <3>      " /Font"        "PolicePourListBox Ask $w"                             "NoWeb"
    TouchePour $Clavier "Exec"          "ExecuteUnBoutonDe $w"                                 "NoWeb"
    TouchePour <2>      "/Small"        "RapetisseLesBoutonsDe $w"                             "NoWeb"
    TouchePour <3>      "/Kill"         "DetruitUnBoutonDe $w"                                 "NoWeb"

    TouchePour $Clavier NouvelleGamme
    TouchePour $Clavier NouvelleCouleur "grey"
    
    TouchePour $Clavier NouvelleGamme
    TouchePour $Clavier NouvelleCouleur "yellow"
    TouchePour $Clavier "Next"  "Focalise $w"     "NoWeb"
    TouchePour <2>      "/Top"  "Focalise $w top" "NoWeb" 
    TouchePour <3>      "/New"  "Focalise $w ask" "NoWeb"
    TouchePour $Clavier "Highlight [PreFixe]" "Illumine $Nom $w"                        "NoWeb"
    TouchePour <2>      "/Query"              "Illumine QUERY $w"                       "NoWeb"
    TouchePour $Clavier "High word"           "Illumine \[Entre\] $w"                   "NoWeb"
    TouchePour <2>      "/group"              "IllumineLeGroupeDe $Nom $w"              "NoWeb"
    TouchePour <3>      "/?"                  "IllumineLeGroupeDe $Nom $w Ask $Maniere" "NoWeb"
    TouchePour $Clavier "Sel. In"   "AfficheRognure \[set PagePropre($w)\] \[selection get\] $Maniere $NomDuFichierOrigine In"  
    TouchePour <2>      "/Out"      "AfficheRognure \[set PagePropre($w)\] \[selection get\] $Maniere $NomDuFichierOrigine Out"  
    TouchePour <3>      "/Alone"    "AfficheRognure \[set PagePropre($w)\] \[selection get\] $Maniere $NomDuFichierOrigine Alone"  
    
    if { $Nom!="" } {
	TouchePour $Clavier "Informe $Nom" "Informe $Nom"
	TouchePour $Clavier "Narcisse"   "FaireLire \[Narcisse $Nom\]"
	TouchePour <2>      "/fetch it"  "AfficheFetch \[Narcisse $Nom\]"
	TouchePour $Clavier "Ghost it "  "Fantomise $Nom ParDecret"
	TouchePour <2>      "/ask"       "Fantomise $Nom Ask"
	TouchePour $Clavier "Met it "    "MetIt $Nom ParDecret"
	TouchePour <2>      "/ask"       "MetIt $Nom Ask"
	TouchePour $Clavier "Reject it " "RejectIt $Nom ParDecret"
	TouchePour <2>      "/ask"       "RejectIt $Nom Ask"
	TouchePour <3>      "/NoRej"     "RejectIt $Nom {NoRejected ParDecret}"
    }
    TouchePour $Clavier "Search on board ..."   "SearchOnBoard \[selection get\]"
    if {$Nom==""} { set NomX x } else { set NomX $Nom } 
    TouchePour $Clavier "NewButton" "NouveauBouton $w New  $NomX $NomDuFichierOrigine" "NoWeb"
    TouchePour <2>      "/same"     "NouveauBouton $w Same $NomX $NomDuFichierOrigine" "NoWeb"
    TouchePour <3>      "/auto"     "NouveauBouton $w Auto $NomX $NomDuFichierOrigine" "NoWeb"
    
    if {$ForValidateOnly} { TouchePour $Clavier "RefuseAll" }
    
    TouchePour $Clavier NouvelleGamme
    TouchePour $Clavier NouvelleCouleur "lightgrey"
    TouchePour $Clavier "Description"       "AfficheLesDescriptifs $NomDuFichierOrigine   MemeOrdre"
    TouchePour <2>      "/all"              "AfficheLesDescriptifs $NomDuFichierOrigine   Natif"
    TouchePour <3>      "/page"             "AfficheLesDescriptifs \[set PagePropre($w)\] MemeOrdre {} {} {} $Nom"
    TouchePour $Clavier "Taxonomy"          "DessineMoiLaTaxonomy $NomDuFichierOrigine"
    TouchePour <2>      "/all"              "AfficheLesDescriptifs $NomDuFichierOrigine   Natif     {} {} {OX OC} $Nom"
    TouchePour <3>      "/page"             "AfficheLesDescriptifs \[set PagePropre($w)\] MemeOrdre {} {} {OX OC} $Nom"
    TouchePour $Clavier "FragFrom"          "FragFrom $Nom"	  
    TouchePour $Clavier "SeeDNA"            "SeeADN $NomDuFichierOrigine"
    TouchePour <2>      "/6PAB"             "VoisinADN $Nom"
    TouchePour <3>      "/6txt"             "VoisinADN \[set PagePropre($w)\]"
    TouchePour $Clavier "Compare to other"  "CompareADN \[set PagePropre($w)\]"
    TouchePour $Clavier "Frag"              "IsoleUnDomaine $Nom"	  
    TouchePour <2>      "/from page"        "IsoleUnDomaine \[set PagePropre($w)\]"	  
    TouchePour <3>      "/nuc"              "IsoleEtAfficheUnDomaineNucleique \[set PagePropre($w)\]"	  
    TouchePour $Clavier "PeptidSort"        "AffichePeptideSort $Nom \[set PagePropre($w)\]"	  
    TouchePour <2>      "/Enzym"            "AffichePeptideSort $Nom \[set PagePropre($w)\] ShowEnzymes"	  
    TouchePour $Clavier "Res Enzym"         "CheckRestrictionEnzymes for_$Nom All \[set PagePropre($w)\]"
    TouchePour <2>      "/Sign"             "CheckRestrictionEnzymes for_$Nom Signals \[set PagePropre($w)\]"
    TouchePour <3>      "/Ask"              "CheckRestrictionEnzymes for_$Nom \[Entre NdeI\] \[set PagePropre($w)\]"
    TouchePour $Clavier "Res Map $Nom"      "RestrictionMap $Nom"	  
    TouchePour <3>      "/Page"             "RestrictionMap \[set PagePropre($w)\]"	  
    TouchePour $Clavier "Codon usage"       "AfficheUsageDesCodons $Nom"
    TouchePour <2>      "/Rare"             "AfficheSlidingCodonRare \[set PagePropre($w)\]"
    TouchePour <3>      "/CPS"              "Cps \[selection get\] {} {} Show"
    TouchePour $Clavier "Hydrophobicities"  "AfficheVariable \[Hydrophobicities $NomDuFichierOrigine\] AutoManiere"
    TouchePour $Clavier "OrthoFamily"       "AfficheLesOrthologuesFamiliersDuBlastP $Nom"
    TouchePour $Clavier "Cluster X-HDA"     "AfficheLeClusterXHda $Nom"
    TouchePour <2>      "/MSF"              "AfficheMsfFamily $Nom"
    
    TouchePour $Clavier NouvelleGamme
    if { $Nom!="" && ! [regexp "SansSeeAby" $Maniere]} {
	TouchePour $Clavier NouvelleCouleur "lightgreen"
	set Nicolas "Nicolas"
	set Moumou  "Ordali"
	if {[OnTraiteUnGenome]}      { set SecondMSF "Para" }
	if {[OnTraiteUneCollection]} { set SecondMSF "MSF2" }
	if {[OnTraiteDesCDNAs]}      { set SecondMSF "Loc" ; set Moumou "allBN" ; set Nicolas "allBP"}
	if {[PreFixe]=="PEROX"}      { set SecondMSF "Loc" ; set Moumou "allBN" ; set Nicolas "allBP"}
	if {[OnTraiteBalibase]} {
	    TouchePour $Clavier "Macsim Rsf" "DessineMoiUnRSF     $Nom" "" "cyan"
	    TouchePour <2>      "/Xml"       "SeeAby MacsimXml $Nom"	    
	    TouchePour <3>      "/Html"      "HtmlFromXmlMacsim $Nom {} ShowHtml"	    
	}
	TouchePour $Clavier "Seq"          "SeeAby Seq         $NomDuFichierOrigine"
	TouchePour <2>      " /nuc"        "SeeAby Nuc         $NomDuFichierOrigine"
	TouchePour <3>      " /Show"       "SeeAby Show        $NomDuFichierOrigine"
	TouchePour $Clavier "Any"          "SeeAby MemoAny     $NomDuFichierOrigine"
	TouchePour <2>      "/choose"      "SeeAby ChooseAny   $NomDuFichierOrigine"
	TouchePour <3>      "/all"         "SeeAby AllAny      $NomDuFichierOrigine"
	TouchePour $Clavier "Blast"        "SeeAby MemoBlast   $NomDuFichierOrigine"
	TouchePour <2>      "/choose"      "SeeAby ChooseBlast $NomDuFichierOrigine"
	TouchePour <3>      "/all"         "SeeAby AllBlast    $NomDuFichierOrigine"
	TouchePour $Clavier "Msf"          "SeeAby MemoMsf     $NomDuFichierOrigine"
	TouchePour <2>      "/choose"      "SeeAby ChooseMsf   $NomDuFichierOrigine"
	TouchePour <3>      "/all"         "SeeAby AllMsf      $NomDuFichierOrigine"
	TouchePour $Clavier "ChangeDefaultDirs" "ReParDefaut"
	TouchePour $Clavier "Ordali"       "Ordali $Nom"
	if {[OnTraite "MAMA"] || [OnTraite "MAMB"] || [OnTraite "EcoliCDS"]} {
	    TouchePour $Clavier "ShowXMotifs 0" "ShowXMotifs $Nom 0 2 1"	
	    TouchePour <2>      " /1"           "ShowXMotifs $Nom 1 2 1"	
	    TouchePour <3>      " /2"           "ShowXMotifs $Nom 2 2 1"	
	}
	if {[file exists "[RepertoireDuGenome]/taxobla"]} {
	    TouchePour <2>      " /Taxo"       "TaxonomyDuBlast $Nom"
	    TouchePour <3>      "/Outliers"    "OutlierOrganismInBlast $Nom"
	}	
	if {[PourWscope]} {
	    TouchePour $Clavier  "Jalview" "JalviewHtml $Nom"
	}
	if {[file exists "[RepertoireDuGenome]/blastxmultiples"]} {
	    TouchePour $Clavier "Frameshift BlastX" "AfficheLesBlastXDesHitsMultiples $Nom"
	    TouchePour <2>      "/Loc"              "FaireLire \[PossibleFrameshift $Nom\]"
	}
	if {[file exists "[RepertoireDuGenome]/fiches/Domaines"]} {
	    TouchePour $Clavier "Show Domains" "IllustreLesDomaines $Nom"
	}
	TouchePour $Clavier "Files"        "SeeAby Other       $NomDuFichierOrigine"
	TouchePour <2>      "/Other"       "SeeAby OnList      $NomDuFichierOrigine"
	TouchePour <3>      "/WithDir"     "ShowDirectories \[set PagePropre($w)\] $NomDuFichierOrigine"
	if {[OnTraiteSpine]} {
	    TouchePour $Clavier "Xml Spine"  "SeeAby SpineXml $NomDuFichierOrigine" "" "Purple"
	    TouchePour <2>      "/Macsim"    "SeeAby MacsimXml $NomDuFichierOrigine"	    
	    TouchePour <3>      "/Html"      "HtmlFromXmlMacsim $Nom {} ShowHtml"	    
	}
    }
    if { [regexp "AvecBlaste" $Maniere] || [regexp "AvecFormate" $Maniere] } {
	TouchePour $Clavier NouvelleCouleur "lightgreen"
	TouchePour $Clavier "Run BlastP"   "Blaste P  \[set PagePropre($w)\]"
	TouchePour <2>      "/tN"          "Blaste tN \[set PagePropre($w)\]"
	TouchePour <3>      "/Choose"      "Blaste Choix \[set PagePropre($w)\]"
	TouchePour $Clavier "GenScan"      "RunGenScanEtAffiche      \[set PagePropre($w)\]"
	TouchePour <2>      "/RepMasker"   "RunRepeatMaskerEtAffiche \[set PagePropre($w)\]"
	
	TouchePour $Clavier NouvelleCouleur "lightgreen"
	TouchePour $Clavier "Change format" "AfficheVariable \[FormateSequence \[set PagePropre($w)\]\] AvecFormateAvecBlasteSansFetch [file tail $NomDuFichierOrigine]"
	TouchePour <2> "/sel."              "AfficheVariable \[FormateSequence \[selection get\]\] AvecFormateAvecBlasteSansFetch part_of_[file tail $NomDuFichierOrigine]"
	TouchePour $Clavier "Medline all"   "AfficheTousLesMedlinesDeLaSequence \[set PagePropre($w)\]\]"
	TouchePour <2>      "/sel."  "AfficheMedline \[selection get\]"
    }
    if { [regexp "AvecAligneurs" $Maniere] } {
	TouchePour $Clavier "DbCl +Anchors"     "RunDbClustal \[selection get\] $NomDuFichierOrigine"
	TouchePour <2>      " / -"              "RunDbClustal \[selection get\]"
	TouchePour $Clavier "Tfas of selection" "CreeUnTFAs \[selection get\] ShowIt"
	TouchePour $Clavier "BlastBase sel"     "CreeUneBanqueBlast \[selection get\] [file tail $NomDuFichierOrigine]"
	TouchePour <2>      "/all"              "CreeUneBanqueBlastDuBlast $NomDuFichierOrigine"
	TouchePour <3>      "/+q"               "CreeUneBanqueBlastDuBlast $NomDuFichierOrigine AvecQuery"
    }
    if { [regexp "AvecShow" $Maniere] } {
	TouchePour $Clavier "Show"   "AfficheLesFichiers \[selection get\] AutoManiereAvecShow"
	TouchePour <2>      "/File"  "AfficheLesFichiers \[selection get\] AutoManiereAvecShow"
	TouchePour <3>      "/Split" "OffreLesMots       \[selection get\]"
    }
    
    if { [regexp "AvecEtudeMSF" $Maniere] } {
	TouchePour $Clavier NouvelleGamme
	TouchePour $Clavier NouvelleCouleur  "lightblue"
	TouchePour $Clavier "Msfcolor"       "DessineMoiUnMSF \[set PagePropre($w)\] $NomDuFichierOrigine Ask" 
	TouchePour <2>      " /Xml"          "Ordali $Nom ForceXml"
	TouchePour <3>      " /RSF"          "DessineMoiUnRSF $NomDuFichierOrigine"
	TouchePour $Clavier "ClustalX"       "ClustalX \[set PagePropre($w)\] $NomDuFichierOrigine" 
	TouchePour <2>      " /NJPlot"       "NJPlotMSF \[set PagePropre($w)\] $NomDuFichierOrigine" 
	TouchePour <3>      " /ATV"          "ATV $NomDuFichierOrigine EnExec" 
	TouchePour $Clavier "NorMD"          "FaireLire \"memorized NorMD \[MDScore $NomDuFichierOrigine\]\"" 
	TouchePour <2>      "/Comput"        "FaireLire \"just computed NorMD \[MDScore \[set PagePropre($w)\] IsText\]\"" 
	TouchePour <3>      "/2Word"         "MSF2WordML $NomDuFichierOrigine" 
	TouchePour $Clavier "StartStop"      "TestCodonStartEtDeletionDuMSF $NomDuFichierOrigine"
	TouchePour <2>      " /Sort"         "AfficheReordonneMSF \[set PagePropre($w)\] Ask $NomDuFichierOrigine"
	TouchePour $Clavier "Ordali"         "Ordali $Nom [RepertoireDuGenome]/macsimXml/$Nom.xml {} {} ForceXml"
	TouchePour <2>      " /fromPage"     "OrdaliDuTexteMSF \[set PagePropre($w)\] $NomDuFichierOrigine -viewer"
	TouchePour <3>      " /sel."         "OrdaliDeLaSelection \[set PagePropre($w)\] \[selection get\] $NomDuFichierOrigine"
	TouchePour $Clavier "MSF familiar orgs" "AfficheMsfOfFamiliarOrganisms $NomDuFichierOrigine"	
	TouchePour $Clavier "MSF Reduce"        "AfficheReduceMsf              $NomDuFichierOrigine"	
	TouchePour <2>      "/Dist"             "AfficheSortedDistances        $NomDuFichierOrigine"	
	TouchePour <3>      "AliInOut"          "AfficheAliInOut $Nom"
	if {[PreFixe]=="TFIIH"} {
	    TouchePour $Clavier "Pid2a2" "Pid2a2 $Nom $NomDuFichierOrigine"
	}
    }
    if { [regexp "AvecGenoret" $Maniere] } {
	TouchePour $Clavier NouvelleGamme
	TouchePour $Clavier NouvelleCouleur "ForestGreen"
	TouchePour $Clavier "Show All Uploads" "ShowUploads"
	if {[regexp "AvecAllUploads" $Maniere]} { 
	    TouchePour $Clavier "Show sel. Upload" "ShowUpload \[selection get\]"
	}
	if {[regexp "AvecUpload" $Maniere]} { 
	    TouchePour $Clavier " SetGUs of sel."       "SetGUsWithUpload $NomDuFichierOrigine"
	}
	
	TouchePour $Clavier "ShowGUs" "ShowGUs"
	if {[regexp "AvecGUsList" $Maniere]} { 
	    TouchePour <2>      "/RemGUs"     "RemGUs \[selection get\]"
	}
    }
    if { [regexp "AvecXbgs" $Maniere] } {
	TouchePour $Clavier NouvelleGamme
	TouchePour $Clavier NouvelleCouleur "Magenta"
	TouchePour $Clavier "Spine"             "SpineSummary Show"
	TouchePour $Clavier "XML File"          "CreateSpineXML"
	TouchePour <2>      "/Show"             "CreateSpineXML Show"
	TouchePour <3>      "/sel"              "CreateSpineXML \[selection get\] Show"
	TouchePour $Clavier "Search Organisms"  "OrganismeDesXGSs"
	TouchePour $Clavier "Show SpineOnly"    "AfficheLesSpines \[set PagePropre($w)\]"
	TouchePour <2>      " /No"              "AfficheLesSpines \[set PagePropre($w)\] KO"
	TouchePour $Clavier "Change Owner"      "MemeOwner \[selection get\]"
	TouchePour <2>      "/XGS"              "XGSPourOwner \[selection get\]"
	TouchePour $Clavier "Def"               "AfficheSpineDefinitions"
	TouchePour <2>      " /Stat"            "HistoDesSpineTasks AllToGether Show"
	TouchePour <3>      " /SpOk"            "HistoDesSpineTasks SpineOnly Show"
    }
    
    if { [regexp "AvecLog" $Maniere] } {
	TouchePour $Clavier "Log" "AfficheLogDuMSF $NomDuFichierOrigine"
    }
    
    if { [regexp "AvecAide" $Maniere] } {
	TouchePour $Clavier "?" "AideEnLigne \[selection get\]" "" "blue"
    }
    
    if { [regexp "AvecSmallMSF" $Maniere] } {
	TouchePour $Clavier "Small align" "ShowDifferentielBlastAlignement \[selection get\]" "" "green"
    }
    
    if { [regexp "AvecProfileSegments" $Maniere] } {
	TouchePour $Clavier NouvelleGamme
	TouchePour $Clavier NouvelleCouleur "green"
	TouchePour $Clavier "ProfilSeg align"  "AfficheProfileSegment \[selection get\] $Maniere $NomDuFichierOrigine"
    }
    if { [regexp "AvecSegAlignement" $Maniere] } {
	TouchePour $Clavier NouvelleGamme
	TouchePour $Clavier NouvelleCouleur "lightblue"
	TouchePour $Clavier "Blast segment align"  "AfficheLesAliEnPage \[set PagePropre($w)\] \[selection get\] $NomDuFichierOrigine"
	TouchePour $Clavier "Mosaic"         "IllustreLeBlast $NomDuFichierOrigine"
	TouchePour <2>      "/Map"           "AfficheMapping $NomDuFichierOrigine \[selection get\]"
	TouchePour <3>      "/DrawBlast"     "DrawBlast $NomDuFichierOrigine"
	TouchePour $Clavier "Localise 0.001" "AfficheChaqueSegmentDuBlastN $Nom $NomDuFichierOrigine"
	TouchePour <2>      "/sel."          "AfficheChaqueSegmentDuBlastN $Nom $NomDuFichierOrigine \[selection get\]" 
	TouchePour $Clavier "Chromos"        "IllustreLesChromosomes"
	TouchePour <2>      "/Histo"         "ChoixHistogramme"
	
	TouchePour $Clavier "HitsPN"    "LesBandelettesDuBlast $NomDuFichierOrigine {} {} OnGraphe"
	TouchePour <2>      "/SeqSizes" "TailleDesSequencesAAligner $Nom"
	TouchePour <3>      "/ All"     "LesEntetesChevronneesDuBlast \[set PagePropre($w)\] Show $NomDuFichierOrigine"
	TouchePour $Clavier "Bandes"     "LesElusDuBlastPParBandelettes $NomDuFichierOrigine {} Show"
	TouchePour <2>      "/Mounir"    "LesElusDuBlastPParMounir $NomDuFichierOrigine {} Show"
	TouchePour <3>      "/AuChoix"   "LesElusDuBlastPParAuChoix $NomDuFichierOrigine {} Show"
	
	TouchePour $Clavier "Ballast" "AfficheBallastDuBlastP $NomDuFichierOrigine $Nom"
	TouchePour $Clavier "Rsf"     "AfficheLesSortiesDuBallast $NomDuFichierOrigine rsf"
	TouchePour <2>      "/lmsp"   "AfficheLesSortiesDuBallast $NomDuFichierOrigine lmsp"
	TouchePour <3>      "/pssm"   "AfficheLesSortiesDuBallast $NomDuFichierOrigine pssm"
	TouchePour $Clavier "TopSeq"  "AfficheLesSortiesDuBallast $NomDuFichierOrigine topseq"
	TouchePour <2>      "/Tabl"   "AfficheLesSortiesDuBallast $NomDuFichierOrigine table"
	TouchePour <3>      "/Anch"   "AfficheLesSortiesDuBallast $NomDuFichierOrigine anchors"
	if {[regexp -nocase "psiblast" $NomDuFichierOrigine]} {
	    TouchePour $Clavier "SplitPsiBlast" "ShowLesBlastsDuPsiBlast $NomDuFichierOrigine" "lightgreen"
	    TouchePour <2>      "/first"        "ShowLesBlastsDuPsiBlast $NomDuFichierOrigine 1"
	    TouchePour <3>      "/last"         "ShowLesBlastsDuPsiBlast $NomDuFichierOrigine end"
	}
	regsub {\.blast[pn]?$} $NomDuFichierOrigine "" NomDuFasta
	append NomDuFasta ".fasta"
	if {[file exists $NomDuFasta]} {
	    TouchePour $Clavier "Show fasta"  "AfficheVariable \[ContenuDuFichier $NomDuFasta\]" "blue"
	}
    }
    
    if { [regexp "AvecOpCom" $Maniere] } {
	TouchePour $Clavier NouvelleGamme
	TouchePour $Clavier NouvelleCouleur  "pink"
	TouchePour $Clavier "Operon ORFs" "ORFsDesOperonsCommuns \[selection get\] ORFsOfOperon"
    }
    
    if { ! [regexp "SansFetch" $Maniere]} {
	TouchePour $Clavier NouvelleGamme
	TouchePour $Clavier NouvelleCouleur "orange"
	set FichierAussi ""
	if {[OnTraiteUneCollection]} { set FichierAussi "$NomDuFichierOrigine" }
	if {[OnTraiteDesCDNAs]}      { set FichierAussi "OnVeutNucEMBL" } 
	
	TouchePour $Clavier "Fetch"          "AfficheFetch  \[selection get\] $FichierAussi"
	TouchePour <2>      " /nature"       "AfficheFetch  \[selection get\] OnVeutNature"
	TouchePour <3>      "/seq"           "AfficheFetch  \[selection get\] $NomDuFichierOrigine"
	TouchePour $Clavier "Split in words"     "OffreLesMots  \[selection get\]"
	TouchePour $Clavier "Contig"             "AfficheContigComplet \[selection get\]"
	TouchePour <2>      "/GenScan"           "AfficheGenscanDuContig \[selection get\]"
	TouchePour $Clavier "Kegg"               "IllustreLesPathwayDeLaBoite $Nom"
	TouchePour <2>      "/Dev"               "IllustreDevStage \[list $Nom\] 3 [Fiches]/SelectedEST" 
	TouchePour <3>      "/Tissue"            "IllustreTissueType \[list $Nom\] {} 3 \[Fiches\]/SelectedEST" 
	TouchePour $Clavier "Gene Identity Card" "GeneIdentityCard $Nom"
	TouchePour $Clavier "Show GOs"           "ShowGOs $Nom"
	TouchePour $Clavier NouvelleCouleur "cyan"
	if {[regexp "Tparva" [RepertoireDuGenome]]} {
	    TouchePour $Clavier "BlastP Sc" "ShowBlastFromSelection \[selection get\] blastpScReciproc"
	    TouchePour <2>        "/Yeast"  "YEAHshowYeast \[selection get\]"
	    TouchePour <3>        " /Info"  "Reciproc $Nom ShowInfo"
	    TouchePour $Clavier "BlastP Eh" "ShowBlastFromSelection \[selection get\] blastpEhistolica"
	    TouchePour <2>           "/ Pf" "ShowBlastFromSelection \[selection get\] blastpPfalciparumReciproc"
	    TouchePour <3>           "/ Tb" "ShowBlastFromSelection \[selection get\] blastpTbruceiReciproc"
	}
	
    }
    if { [regexp "AvecRecap" $Maniere]} {
	TouchePour $Clavier NouvelleGamme
	TouchePour $Clavier NouvelleCouleur "ForestGreen"
	TouchePour $Clavier "Blast"          "SeeAby MemoBlast   \[selection get\]"
	TouchePour <2>      "/choose"        "SeeAby ChooseBlast \[selection get\]"
	TouchePour <3>      "/all"           "SeeAby AllBlast    \[selection get\]"
	TouchePour $Clavier "BlastP"         "SeeAby blastp            \[selection get\]"
	TouchePour <2>      "/RefseqP"       "SeeAby blastprefseq-prot \[selection get\]"
	TouchePour $Clavier "Blastn wgs"     "SeeAby blastnwgs         \[selection get\]"
	TouchePour $Clavier "TBlastN wgs"    "SeeAby tblastnwgs        \[selection get\]"
	TouchePour <2>      "/Genomes"       "SeeAby tblastncompletegenomes \[selection get\]"
    }
    if {[OnTraiteDesClones]} {
	TouchePour $Clavier "My Oligos"  "IllustreLesPrimers $Nom" "" "Magenta"
	TouchePour <2>      "/vPPCR" "ShowLesVirtualPPCRsDuPGS $Nom"
	TouchePour <3>      "/VEs"   "ShowLesVEDidierDuPGS $Nom"
	if {1} {
	    TouchePour $Clavier "vPpcr "        "ShowVirtualPPCR \[selection get\]" "" "Magenta"
	    TouchePour <2>      "/choose"       "ShowVirtualPPCR \[selection get\] Choose"
	    TouchePour <3>      "/all"          "ShowVirtualPPCR \[selection get\] All"
	    TouchePour $Clavier "Rec1 of vPPCR" "ShowLesRec1DuVirtualPPCR \[selection get \]" "" "Magenta"
	    TouchePour $Clavier "Rec1 or 2 or fusion "  "ShowCorrespondingFile   \[selection get\]" "" "Magenta"
	    TouchePour $Clavier "ShowVEDidier"  "VEDidier \[selection get\] Show" "" "Magenta"	    
	}
    }
    if { ! [regexp "SansFetch" $Maniere] && \
	     [OnTraiteUneCollection] && ! [OnTraiteDesCDNAs] && \
	     [file tail $NomDuFichierOrigine]!=$Nom} {
	TouchePour $Clavier "Co-Fetch"    "AfficheAssocie $NomDuFichierOrigine copains"
	TouchePour <2>      "/BlastP"     "AfficheAssocie $NomDuFichierOrigine coblastp"
	TouchePour <3>      "/MSF"        "AfficheAssocie $NomDuFichierOrigine coclustalw"
	TouchePour $Clavier "Co-Info"     "AfficheAssocie $NomDuFichierOrigine coinfos"
	TouchePour <2>      "/tBlastN"    "AfficheAssocie $NomDuFichierOrigine cotblastn"
	TouchePour $Clavier "Co-modify"   "InformeLeCopain $NomDuFichierOrigine"
	TouchePour $Clavier "Co-rsf"      "AfficheLesSortiesDuBallast $NomDuFichierOrigine rsf"
	TouchePour <2>      "/lmsp"       "AfficheLesSortiesDuBallast $NomDuFichierOrigine lmsp"
	TouchePour <3>      "/pssm"       "AfficheLesSortiesDuBallast $NomDuFichierOrigine pssm"
    }
    
    if {[OnTraite "Topos"]} {
	TouchePour $Clavier NouvelleCouleur "magenta"
	TouchePour $Clavier HistoPiliers   "GrapheDuFichier [RepertoireDuGenome]/Piliers/$Nom dpvd"
	TouchePour $Clavier HistoInsertion "BlastAli $Nom DisplayStats"
    }
    if {[OnTraite "MSP"]} {
	TouchePour $Clavier NouvelleCouleur "magenta"
	TouchePour $Clavier "SeqCalage"  "SeqCalage $Nom"
    }
    if {[OnTraite "CilioCode"]} {
	TouchePour $Clavier NouvelleCouleur "magenta"
	TouchePour $Clavier "Cilio ForCilio"  "CilioBlastSummary     $Nom Show  blastpForCilio"
	TouchePour <2>      "/Expect"         "OrganismsInCilioBlast $Nom Graph blastpForCilio"
	TouchePour $Clavier "Cilio Protall"   "CilioBlastSummary     $Nom Show  blastpProtall"
	TouchePour <2>      "/Expect"         "OrganismsInCilioBlast $Nom Graph blastpProtall"
	TouchePour $Clavier "Cilio Ortholog"  "CilioBlastSummary     $Nom Show  blastpBanqueOrthologs"
	TouchePour <2>      "/Expect"         "OrganismsInCilioBlast $Nom Graph blastpBanqueOrthologs"
    }
    if {[OnTraiteDesClones]} {
	TouchePour $Clavier NouvelleGamme
	TouchePour $Clavier NouvelleCouleur "magenta"
	if {[regexp "AvecOli" $Maniere]} {
	    TouchePour $Clavier "Oligo "  "ShowOli \[selection get\]"
	    TouchePour <2>      "/choose" "ShowOli \[selection get\] Choose"
	    TouchePour <3>      "/all"    "ShowOli \[selection get\] All"
	    TouchePour $Clavier "ShowBlastN"  "ShowBlastOfOligo \[selection get\]"
	    TouchePour <2>      "/Order"      "AfficheFournisseur \[selection get\]"
	}
	if {[regexp "AvecShowItsOligos" $Maniere]} {
	    set NA ""
	    if {[regexp "AvecShowItsOligos_NA" $Maniere]} { set NA "_NA" }
	    TouchePour $Clavier "Show its oligos" "ShowItsOligos \[selection get\] $NA"
	}
	if {[regexp "AvecFiOl" $Maniere]} {
	    TouchePour $Clavier "ShowOligosFiles" "ShowOligosFiles \[selection get\]"
	}
	if {[regexp "AvecVirtualPPCR" $Maniere]} {
	    TouchePour $Clavier "vPpcr "        "ShowVirtualPPCR \[selection get\]"
	    TouchePour <2>      "/choose"       "ShowVirtualPPCR \[selection get\] Choose"
	    TouchePour <3>      "/all"          "ShowVirtualPPCR \[selection get\] All"
	    TouchePour $Clavier "Rec1 of vPPCR" "ShowLesRec1DuVirtualPPCR \[selection get \]"
	}
	if {[regexp "AvecShowItsPPCR" $Maniere]} {
	    set NA ""
	    if {[regexp "AvecShowItsPPCR_NA" $Maniere]} { set NA "_NA" }
	    TouchePour $Clavier "Show its PPCR" "ShowItsPPCR \[selection get\] $NA"
	}
	if {[regexp "AvecTriFragments" $Maniere]} {
	    TouchePour $Clavier "SortFragments all" "TriFragments \[set PagePropre($w)\] Ask"
	    TouchePour <2>      "/sel."             "TriFragments \[selection get\] Ask"
	}
    }
    if {[regexp "AvecTaxNCBI" $Maniere]} { 
	TouchePour $Clavier NouvelleGamme
	TouchePour $Clavier NouvelleCouleur "lightgreen"
	TouchePour $Clavier "BrowseTaxNCBI" "BrowseTaxNCBI"
	TouchePour $Clavier "Sel. Parent"   "BrowseTaxNCBI \[selection get\] Parent"
	TouchePour <2>      "/Children"     "BrowseTaxNCBI \[selection get\] Children"
	TouchePour <3>      "/?"            "BrowseTaxNCBI \[selection get\]"
	TouchePour $Clavier "All Parent"    "BrowseTaxNCBI \[set PagePropre($w)\] Parent"
	TouchePour <2>      "/Children"     "BrowseTaxNCBI \[set PagePropre($w)\] Children"
	TouchePour <3>      "/?"            "BrowseTaxNCBI \[set PagePropre($w)\]"
    }
    if {$ForValidateOnly} { TouchePour $Clavier "ReAcceptAll" }
    

    #rR 2016/02/02 On a peut-être Postponé des TouchePour ;)
    set LesPostpone [TouchePour "GetPostponeAndReset"]
    set Cla $w.buttons
    foreach Action $LesPostpone {
	regsub -all "@F@" $Action $w Action
	if {[regexp "<" [lindex $Action 0]]} {
	    TouchePour {*}$Action
	} else {
	    TouchePour $Cla {*}$Action
	}
    }
    
    set Largeur 90
    set Hauteur 35
    if { [regexp "GrandeLargeur" $Maniere] } { set Largeur 128 }
    if { [regexp {SetWidth([0-9]+)}  $Maniere Match Width] }  { set Largeur $Width }
    if { [regexp {SetHeight([0-9]+)} $Maniere Match Height] } { set Hauteur $Height }
    if { ! [PourWscope]} {
	frame $w.frame -borderwidth 10
	pack  $w.frame -side top -expand yes -fill both
	
	
	scrollbar $w.frame.yscroll -command "$w.frame.list yview"
	scrollbar $w.frame.xscroll -command "$w.frame.list xview" \
	    -orient horizontal
	listbox $w.frame.list -width $Largeur -height $Hauteur -setgrid 1 \
	    -yscroll "$w.frame.yscroll set" \
	    -xscroll "$w.frame.xscroll set" \
	    -selectmode extended \
	    -background "LightGrey" \
	    -foreground "Black" \
	    -selectbackground "LightYellow" \
	    -selectforeground "Black" \
	    -font [list Courier [PolicePourListBox]]

	bind $w.frame.list "<4>"         "%W yview scroll  1 units"
	bind $w.frame.list "<5>"         "%W yview scroll -1 units"
	bind $w.frame.list "<Control-4>" "%W xview scroll  1 units"
	bind $w.frame.list "<Control-5>" "%W xview scroll -1 units"
	
	grid $w.frame.list    -row 0 -column 0 -rowspan 1 -columnspan 1 -sticky nsew
	grid $w.frame.yscroll -row 0 -column 1 -rowspan 1 -columnspan 1 -sticky nsew
	grid $w.frame.xscroll -row 1 -column 0 -rowspan 1 -columnspan 1 -sticky nsew
	grid rowconfig    $w.frame 0 -weight 1 -minsize 0
	grid columnconfig $w.frame 0 -weight 1 -minsize 0
	
	set nLignes 0
	foreach Ligne [split [set PagePropre($w)] "\n"] {
	    incr nLignes
	    if { [regexp "AvecSegAlignement" $Maniere] && [regexp {^>[\./a-zA-Z]} $Ligne] \
		     && ! [regexp "AvecTout" $Maniere]} { break }
	    $w.frame.list insert end $Ligne
	}
    }
    if {[PourWscope]} {
	set R [Html_TextToListbox [set PagePropre($w)] $w $Titre $Header "" $Maniere]
	if { [regexp "AvecRetour" $Maniere] } {
	    return $R

	    global VariableDeRetour
	    package require Tk
	    tkwait variable VariableDeRetour($w)
	    set v $VariableDeRetour($w)
	    LogWscope "apres tkwait de $Var valeur $v"
	    unset  VariableDeRetour($w)
#	    catch {destroy $w}
	    return $v
	}
	return $R
    }
    if {$nLignes<30} { $w.frame.list configure -height [expr $nLignes+3] }
    
    if {[regexp "AvecEtude" $Maniere] && $Nom!=""} {
	Illumine $Nom $w
    }
    
    bind $w.frame.list <3>               "DecrisLaLigne %W %x %y"
    bind $w.frame.list <ButtonRelease-3> "DecrisLaLigne %W %x %y Efface"
    
    if {[regexp "AvecRetour" $Maniere]} {
	$w.frame.list configure -background "lightgreen"
    }
    if { [regexp "AvecRetourMaisSansWait" $Maniere] } {
	return $w
    }

    if { [regexp "AvecRetour" $Maniere] } {
	tkwait variable VariableDeRetour($w)
	set v $VariableDeRetour($w)
	unset  VariableDeRetour($w)
	catch {destroy $w}
	return $v
    } else {
	return $w
    }
}

proc QueFaitOn {} {
    global env
    return "[set env(GSCOPEDIR)] [set env(REPERTOIREDUGENOME)]"
}

proc Destroy w {
    global KanvaCourant
    destroy $w
    return 
}

proc AfficheAliInOut Nom {
    global RepertoireDuGenome

    set Fichier "$RepertoireDuGenome/aliinout/$Nom"
    if { ! [file exists $Fichier]} { return "" } 
    set Fen [AfficheFichier $Fichier]
    return [Illumine "accepted" $Fen]
}

proc OteSuperfluPourFetch Ligne {
    set Ligne [string trim $Ligne]
    regsub {^[0-9]+ +}             $Ligne ""  Ligne
    regsub    {^>}                 $Ligne ""  Ligne
    regsub -all ";"                $Ligne " " Ligne
    regsub {.*\. \:}               $Ligne " " Ligne
    regsub -nocase "chromosome"    $Ligne ""  Ligne
    regsub -nocase " contig "      $Ligne ":" Ligne
    regsub -nocase {^[a-z][a-z]\|} $Ligne ""  Ligne
    regsub -all {\|}               $Ligne " " Ligne
    return $Ligne
}

proc Gag {} {
    Gs "WindowText"
    
    # Cette procedure retourne la page du labo
    return [ContenuDuFichier "./logag.html"]
}

proc MessAide {{V ""}} {
    set M "$V.messaide"
    catch {destroy $M} 
    message $M \
	    -text [lindex [$V.baide configure -text] 4] \
	    -borderwidth 3 -font {Courier 8} -relief raise -width 250\
	    -background "lightyellow" -foreground "black"
    place $V.messaide -x 10 -y 300 -anchor nw
    after 1000 "catch {destroy $M}"
}

proc KanvaCourant {} {
    global KanvaCourant
    global CurrentGenome

    if {[info exists KanvaCourant]} { return $KanvaCourant }

    set KanvaCourant [GscopeBoard $CurrentGenome]
    return $KanvaCourant
}

proc Long {A B I J} {
    if {$I==0 ||$J==0} { return 0 } 
    set X [string index $A $I]
    set Y [string index $B $J]
    if {$X==$Y} { set R 1 } else { set R 0 }
    set M [Maxi [expr [Long $A $B [expr $I-1] [expr $J-1]]+$R] \
	    [Maxi [Long $A $B [expr $I-1] $J] [Long $A $B $I [expr $J-1]]] ]
    return $M
}

proc TestLong {} {
    set A "abcefdyeyf"
    set B "abcdxcef"
    puts [expr [Long $A $B [expr [string length $A]-1] [expr [string length $B]-1]]+1]
    exit
}

proc TestQuidSeq {} {
    
    set LesACOS [QuestionDeScience QuidSeq "QuidOSsOfACs P12345|P12345 "]
    regsub {[ \n]+$} $LesACOS "" LesACOS
    Espionne $LesACOS
    exit
}

proc DemarcationDesTRNAs {K VouH} {
    global RepertoireDuGenome

    foreach Ligne [LesLignesDuFichier "$RepertoireDuGenome/fiches/bornesdestrnas"] {
	scan $Ligne "%s %d %d %s" TRNA Debut Fin Orient
	set Milieu [expr ($Debut+$Fin)/2]
	set Milieux($TRNA,Moi) $Milieu
    }
    FaireLire "Please browse for the file bornesdestrnas of the other organism"
    set FichierLui [ButineArborescence "All" "$RepertoireDuGenome/"]
    set SonFichierADN "[file dirname $FichierLui]/../beton/adn"
    set LongueurLui [expr [string length [ContenuDuFichier $SonFichierADN]]-1]
    foreach Ligne [LesLignesDuFichier $FichierLui] {
	scan $Ligne "%s %d %d %s" TRNA Debut Fin Orient
	set Milieu [expr $LongueurLui - ($Debut+$Fin)/2]
	set Milieux($TRNA,Lui) $Milieu
	if {[info exists Milieux($TRNA,Moi)]} {
	    set XY($TRNA) "[set Milieux($TRNA,Moi)] $Milieu" 
	}
    }
    foreach {TRNA ValXY} [array get XY] {
	scan $ValXY "%d %d" X Y
	DemarcationEnPosition $K "vh" "SurADN_$X" "SurADN_$Y" $TRNA
    }
    return
}

proc AfficheNuc Boite {
    set Nom [Box $Boite nom]
    if { $Nom=="" } { return "" }
    set Debut  [Box $Boite debut]
    set Fin    [Box $Boite fin]
    set Orient [Box $Boite orient]
    set SeqNuc [BoutADN $Debut $Fin $Orient]
    set NucTFA [SequenceFormatTFA $SeqNuc "$Nom $Debut $Fin $Orient" "nucbrut"]
    return [AfficheVariable $NucTFA "AvecBlasteAvecFormateAvecVoisinsSansFetch" $Nom]
}

proc AccessDuPlusProcheDansDisphy {Nom OrgaCherche} {
    global RepertoireDuGenome

    foreach Ligne [LesLignesDuFichier "$RepertoireDuGenome/disphy/$Nom"] {
	scan $Ligne "%s %d %s" Orga Distance Access
	if {$Orga == $OrgaCherche} { return $Access }
    }
    return ""
}

proc AfficheBallastDuBlastP {FichierBlastP Nom} {
    set TexteBallast [Ballast $FichierBlastP [RepertoireDeTravail] "" "TexteSansFichier"]
    return [AfficheVariable $TexteBallast \
	    "AvecGrapheAvecSegAlignementAvecAligneurs" $Nom]
}

proc TrouveLaReferenceVoulue {ReferenceVoulue FichierPhylo} {

    Wup "Texte est un arbre phylo"
    Wup "Recherche l'Access qui correspond a l'organisme ReferenceVoulue"
    Wup " Ne marche bien que pour les synthetases... et encore ... j'ai tout change."

    set Texte [ContenuDuFichier $FichierPhylo]
    regsub -all {\(|\)|\:|\n} $Texte " " Texte
    foreach Mot [split $Texte " "] {
	if { ! [regexp -nocase {[A-Z]} $Mot]} { continue }
	if {0 && [regexp -indices {[0-9]} $Mot sChiffre]} {
	    scan $sChiffre "%d" iChiffre
	    puts "$sChiffre $iChiffre"
	    puts $Mot
	    set Mot "[string range $Mot 0 [incr iChiffre -1]]_[string range $Mot [incr iChiffre] end]"
	    puts $Mot
	}
	lappend LesMots $Mot
    }
    puts [join $LesMots " "]
   
    foreach Access $LesMots {
	if {[regexp $ReferenceVoulue [OrgaDuAccess $Access Court]]} { return $Access }
    }
    exit


    set LesReferencesPossibles {}
    if { [lsearch -regexp $LesMots $ReferenceVoulue] < 0 } {
	FaireLire "You have to tell me which organism I take as reference for [AutreCode $Nom]"
	set Reference [ChoixParmi $LesMots]
    } else {
	while {[set iReference [lsearch -regexp $LesMots $ReferenceVoulue]] > -1} {
	    lappend LesReferencesPossibles [lindex $LesMots $iReference]
	    set LesMots [lrange $LesMots [expr $iReference+1] end]
	}
	if {[llength $LesReferencesPossibles] == 2 && [AutreCode $Nom]=="glu"} {
	    set iReference [lsearch -regexp $LesReferencesPossibles "sye"]
	    if {$iReference > -1} {
		set Reference [lindex $LesReferencesPossibles $iReference]
	    } else {
		FaireLire "You have to tell me which organism I take as reference for [AutreCode $Nom]"
		set Reference [ChoixParmi $LesReferencesPossibles]
	    }
	} elseif {[llength $LesReferencesPossibles] == 2 && [AutreCode $Nom]=="gln"} {
	    set iReference [lsearch -regexp $LesReferencesPossibles "syq"]
	    if {$iReference > -1} {
		set Reference [lindex $LesReferencesPossibles $iReference]
	    } else {
		FaireLire "You have to tell me which organism I take as reference for [AutreCode $Nom]"
		set Reference [ChoixParmi $LesReferencesPossibles]
	    }
	} elseif {[llength $LesReferencesPossibles] > 1} {
	    FaireLire "You have to tell me which organism I take as reference for [AutreCode $Nom]"
	    set Reference [ChoixParmi $LesReferencesPossibles]
	} else {
	    set Reference [lindex $LesReferencesPossibles 0]
	}
    }
}

proc PhyloRankDuTamis {{Tam ""}} { 
    global NotreOrga
    CreeLaTableDuTamis $Tam "distancesphylo" "$NotreOrga" ".$NotreOrga"
}

proc PhyloRank {{OrgaDeReference ""} {Extension ""}} {
    global RepertoireDuGenome
    global NotreOS

    if {$OrgaDeReference==""} {
	FaireLire "Please give me the reference organism\n (to whom the distances will be calculate)."
	set Orga [Glossaire [Entre $NotreOS] Court]
    } else {
	set Orga [Glossaire $OrgaDeReference Court]
    }
    if {$Orga==""} { return "" }

    if {$Extension==""} {
	set Extension ".$Orga"
    }


    set FichierPIClustalw "$RepertoireDuGenome/fiches/piclustalw$Extension"

    Wup "Je pose la question maintenant, pour plus tard ..."
    set QuestionDejaPoseeEtOui 0
    if {[file exists $FichierPIClustalw] && [OuiOuNon "Do I replace $FichierPIClustalw" 0] \
	    || ! [file exists $FichierPIClustalw]} {
	set QuestionDejaPoseeEtOui 1
    }
    set FichierDistancesPhylo "$RepertoireDuGenome/fiches/distancesphylo$Extension"
    if { ! [file exists $FichierDistancesPhylo] || \
	     ! [OuiOuNon "The file distancesphylo already exists. Do I use it ?"]} {
	set FichierDistancesPhylo [CreeDistancesPhyloAvecLesMSFs $Orga $Extension]
    }
    if { ! [file exists $FichierDistancesPhylo]} {
	FaireLire "Sorry, $FichierDistancesPhylo does'nt exist."
    }

    if {$QuestionDejaPoseeEtOui || ! [file exists $FichierPIClustalw]} { 
	CreeLesFichiersPIClustalwEtPSClustalw $Orga $Extension
    }

    CreeLesTables "distancesphylo" $Orga $Extension
}
    
proc AfficheSequencesCorrelees {Fichier {Groupe ""}} {
    global RepertoireDuGenome
    
    JeMeSignale

    set Nom [file tail $Fichier]
    set Fichier "$RepertoireDuGenome/correlator/$Nom"
    if { ! [file exists $Fichier]} { return "" }
    set VasY 0
    set DejaVu 0
    set LesBons {}
    foreach Ligne [LesLignesDuFichier $Fichier] {
	if { ! [regexp -nocase {[a-z]} $Ligne]} { continue }
	if {$Groupe!=""} {
	    if {[regexp "groupe :" $Ligne]} {
		scan $Ligne "%s %s %d" Bidon DP GroupeLu
		if {$GroupeLu == $Groupe} {
		    set VasY 1
		    set DejaVu 1
		    continue
		} else {
		    if {$DejaVu} { break }
		}
	    }
	    if { ! $VasY } { continue }
	}
	regsub "^>" $Ligne "" Ligne
	lappend LesBons $Ligne
    }
    return [AfficheVariable [join $LesBons "\n"] ""]
}

proc CodonStartPossible Codon {
    global CodonStartPossible
    global RepertoireDuGenome

    Wup "Return 1 if Codon is a valid start codon"

    if { ! [info exists CodonStartPossible]} {
	set Fichier "$RepertoireDuGenome/fiches/codonstartpossible"
	while { ! [file exists $Fichier]} {
	    if {[OuiOuNon "For Possible Start Codon ... \nThe file $Fichier does'nt exists.\nDo you want to create it ?"]} {
		set Possibles [string trim [Entre "ATG TTG GTG"]]
		while {[regexp "  " $Possibles]} { regsub "  " $Possibles " " Possibles }
		if {$Possibles == ""} { continue }
		regsub -all " " $Possibles "\n" Possibles
		Sauve $Possibles dans $Fichier
	    } else {
		if {[OuiOuNon "Do I exit ? "]} { exit }
		if {[OuiOuNon "Do I continue without creating $Fichier ? "]} { return {} }
	    }
	}
	foreach Ligne [LesLignesDuFichier $Fichier] {
	    lappend CodonStartPossible $Ligne
	}
    }

    if {$Codon=="LaListeMerci"} { return $CodonStartPossible }

    foreach Possible $CodonStartPossible {
	if { ! [string compare -nocase $Possible $Codon]} { return 1 }
    }
    return 0
}

proc CodonStopPossible Codon {
    global CodonStopPossible
    global RepertoireDuGenome

    Wup "Return 1 if Codon is a valid stop codon"

    if { ! [info exists CodonStopPossible]} {
	set Fichier "$RepertoireDuGenome/fiches/codonstoppossible"
	while { ! [file exists $Fichier]} {
	    if {[OuiOuNon "For Possible Stop Codon ... \nThe file $Fichier doen't exists.\nDo you want to create it ?"]} {
		set Possibles [string trim [Entre "TAA TAG TGA"]]
		regsub -all { +} $Possibles " " Possibles
		if {$Possibles == ""} { continue }
		regsub -all " " $Possibles "\n" Possibles
		Sauve $Possibles dans $Fichier
	    } else {
		if {[OuiOuNon "Do I exit ? "]} { exit }
		if {[OuiOuNon "Do I continue without creating $Fichier ? "]} { 
		    #lm doit retourner un boolean
		    #return {} 
		    return 0
		}
	    }
	}
	foreach Ligne [LesLignesDuFichier $Fichier] {
	    lappend CodonStopPossible $Ligne
	}
    }
    
    if {$Codon=="LaListeMerci"} { return $CodonStopPossible }

    foreach Possible $CodonStopPossible {
	if { ! [string compare -nocase $Possible $Codon]} { return 1 }
    }
    return 0
}

proc AfficheMedline Selection {
    Wup "Calls Jean-Marie Wurtz's program to fetch medline's http file."
    foreach Ligne [split $Selection "\n"] {
	catch {unset Uid}
	if {[regexp "^RX" $Ligne]} {
	    catch {set Uid [IntegerApres "MEDLINE;" dans $Ligne]}
	} elseif {[regexp "PMID:" $Ligne]} {
	    catch {set Uid [IntegerApres "PMID:" dans $Ligne]}
	} else {
	    continue
	}
	if { ! [info exists Uid] || ! [regexp {^[0-9]+$} $Uid] } { continue }
	AfficheVariable [exec medhttp $Uid] "AvecRien"
    }
}

proc AfficheTousLesMedlinesDeLaSequence Sequence {
    Wup "Calls Jean-Marie Wurtz's program to fetch medline's http file."
    
    Gs "Frame"
    
    set LesLignes [split $Sequence "\n"]
    if {[llength $LesLignes] < 1} {
        FaireLire "$Sequence\nis n't a sequence."
        return ""
    }
    set iAccess [lsearch -regexp $LesLignes {^AC}]
    if {$iAccess<0} {
        FaireLire "Sorry I can't find the Access of the sequence"
        return ""
    }
    scan [lindex $LesLignes $iAccess] "%s %s" AC Access
    regsub ";" $Access "" Access
    return [AfficheVariable [exec meddata $Access] "AvecRien"]
}

proc Gscope {{V ""} {Top ""}} {
    global RepertoireDuGenome
    global FichierMiniConfig 
    global FichierMiniConfigSansGenome
    global GscopeAideSurLesBoutons
    global VersionDeGscopeAuBigBang

    VersionDeGscope
        
    if { ! [info exists RepertoireDuGenome]}  {RepertoireDuGenome}
    if { ! [info exists CurrentGenome]}       {CurrentGenome}
    if { ! [info exists RepertoireDeTravail]} {RepertoireDeTravail}
    
    CommandesExecPossibles

    if {[info exists GscopeAideSurLesBoutons] && $GscopeAideSurLesBoutons} {
	bind Button <Enter>       "+TuMontrerasCeQueFaitLeBouton %W"
	bind Button <Leave>       "+LacheLeBouton %W"
    }

    while {! [info exists VersionDeGscopeAuBigBang]} {
	if {[info exists FichierMiniConfig] && [file exists $FichierMiniConfig]} {
	    ChargeMiniConfig
	    continue
	} else {
	    Glossaire hsap Court
	    lappend LePrelude "It seems you want to create a new Gscope Project."
	    lappend LePrelude "Gscope can manage different kinds of projects :"
	    lappend LePrelude "      - a complete genome, starting with the DNA, creating the proteome"
	    lappend LePrelude "      - a collection of proteins, genes, cDNAs, or any type of sequences, etc. "
	    lappend LePrelude ""
	    lappend LePrelude "Gscope can manage proteins, nucleic sequences or BOTH :"
	    lappend LePrelude "      Gscope will ask you some questions about that."
	    lappend LePrelude ""
	    lappend LePrelude "Gscope starts reading you original data :"
	    lappend LePrelude "      it can be "
	    lappend LePrelude "       - a fasta file containing the genome"
	    lappend LePrelude "       - a fasta file containing all your sequences"
	    lappend LePrelude "       - a file with AccessNumbers"
	    lappend LePrelude "       - a file of filenames linking to your sequencess"
	    lappend LePrelude "       - a genbank file"
	    lappend LePrelude "       - etc."
	    lappend LePrelude ""
	    lappend LePrelude "It's very important to provide all important information concerning your sequences"
	    lappend LePrelude "     when you start the project. Gscope integrates easily organism name, genename,"
	    lappend LePrelude "     gene description, etc., if it is available in your files."
	    lappend LePrelude "     For example if your fasta files are as follow"
	    lappend LePrelude ">Genename Organism Definition"
	    lappend LePrelude ">AaEcR-A Aedes aegypti Ecdysone receptor isoforme-A"
	    lappend LePrelude "     or your file of filenames"
	    lappend LePrelude "AaEcr-A /home/yourdir/seq/Ecdy.tfa"
	    lappend LePrelude ""
	    lappend LePrelude "          Good luck !         (for any question phone to Raymond : 03 88 65 33 05)"
	    set Prelude [join $LePrelude "\n"]
	    FaireLire $Prelude
	    if {[OuiOuNon "Do you have a genomic dna sequence ?"]} {
		CreeLaBase
	    } elseif {[OuiOuNon "Is it a collection of proteins, genes, dna sequences, mRNAs, etc. ?"]} {
		CreeLaCollection
	    } else {
		if {[OuiOuNon "Do I start with \n$FichierMiniConfigSansGenome\n\n[ContenuDuFichier $FichierMiniConfigSansGenome]"]} {
		    set FichierMiniConfig $FichierMiniConfigSansGenome 
		    continue
		} else {
		    if {[OuiOuNon "Do we try later ... ?"]} { exit }
		}
	    }
	}
    }

    LesOrganismesTresProches

    if {$V=="NoVitrine"} { return }
    set Vitrine [Vitrine $V $Top]
    update idletasks
    if {0} {
	catch {Parle "Gscope est chargé. On peut commencer. Mais ! Malédiction ! Ils ont fait un crochet ... ils nous avaient donc repérés." "fr"}
    }
    return $Vitrine
}

proc CurrentGenome {{NewValue ""}} {
    #rR modifié 20150405 
    global RepertoireDuGenome
    global CurrentGenome
    Gs "Text"
    if {$NewValue!=""} { set CurrentGenome $NewValue }

    if { [info exists CurrentGenome]} {
	return $CurrentGenome
    } else {
	set CurrentGenome [file tail $RepertoireDuGenome]
    }
    return $CurrentGenome

    #rR la suite est largemet obsolete 
    if {[regexp {^aby$}    $RepertoireDuGenome]} { set CurrentGenome "Emilie" }
    if {[regexp {^bys$}    $RepertoireDuGenome]} { set CurrentGenome "Seraphin" }
    if {[regexp {casimir$} $RepertoireDuGenome]} { set CurrentGenome "Casimir" }
    if {[regexp {hor}      $RepertoireDuGenome]} { set CurrentGenome "Horikoshii" }
    if {[regexp {fur}      $RepertoireDuGenome]} { set CurrentGenome "Furiosus" }
    
    if { ! [info exists CurrentGenome]} { set CurrentGenome [file tail $RepertoireDuGenome] }
    return $CurrentGenome
}

proc Vitrine {{V ""} {Top ""}} {
    global VitrineCourante
    global RepertoireDuGenome
    global CurrentGenome
    global FichierGscopeHelp
    global FichierGscopeImage
    global FichierGscopeImage2
    global FichierGscopeLogoBInG
    global FichierGscopeLogoMacsim
    global FichierGscopeExitGscope
    global NotreOS Org1 Org2
    global LesBoutonsNonOpen
    global LesBoutonsDeVitrine
    global LesBoutonsDeVitrineCaches

    if {[regexp "GetVitrine" $V]} {
	if {[info exists VitrineCourante]} { return $VitrineCourante }
	if {[regexp "Create" $V]} {
	    Vitrine "" $Top
	    return [Vitrine "GetVitrine"]
	}
	return "NoCurrentVitrine"
    }

    set VitrineCourante $V

    if {$Top!=""} { toplevel $V }
    set SW [winfo screenwidth .]
    set SH [winfo screenheight .]
    set OffX [expr ($SW/2) - 500]
    set OffY [expr 200]	
    wm geometry . +${OffX}+${OffY}
	      
    set Bouton $V.bseqin
    lappend LesBoutons $Bouton
    lappend LesWebDeny $Bouton
    button $Bouton -text "Enter sequence/Show a file/ Edit"
      bind $Bouton <1> {AfficheVariable [SeqIn] "SansFetchAvecFormateAvecBlasteAvecAligneurs"}
      bind $Bouton <2> ShowFile
      bind $Bouton <3> EditeEtCreeFichier
    
    set Bouton $V.bvisu
    lappend LesBoutons $Bouton
    lappend LesWebDeny $Bouton
    button $Bouton -text "See Seq/Blast/MSF" 
      bind $Bouton <1> AfficheUneSequence
      bind $Bouton <2> BlastTools
      bind $Bouton <3> EtudieUneSortieMSF
      bind $Bouton <Shift-2> AfficheUneSortieBlast

    set Bouton $V.bcochealigneurs
    lappend LesBoutonsDeVitrineCaches $Bouton
    lappend LesWebDeny $Bouton
    button $Bouton -text "Choose multiple alignment program ..."
      bind $Bouton CocheAligneurs
    
    set Bouton $V.borgas
    lappend LesBoutons $Bouton
    lappend LesWebDeny $Bouton
    button $Bouton -text "Ontology/GOTools/Decrypthon"
      bind $Bouton <1> "GOPanel \[NomDe gopanel\]" 
      bind $Bouton <2> "GOTools"
      bind $Bouton <3> "AfficheDecrypthon"
    
    set Bouton $V.devtissue
    lappend LesBoutons $Bouton
    lappend LesWebDeny $Bouton
    button $Bouton -text "Develop Stage/Tissue Type/ Taxo"
      bind $Bouton <1> "IllustreDevStage"
      bind $Bouton <2> "IllustreTissueType"
      bind $Bouton <3> "BrowseTaxNCBI"
    
    set Bouton $V.bmenage
    lappend LesBoutonsDeVitrineCaches $Bouton
    lappend LesWebDeny $Bouton
    button $Bouton -text "Clean directory"
      bind $Bouton <1> {MenageLesTmp "Rename"}
    
    set Bouton $V.inventaire
    lappend LesBoutons $Bouton
    lappend LesWebDeny $Bouton
    button $Bouton -text "Inventory/Check /DbW"
      bind $Bouton <1> Inventaire
      bind $Bouton <2> CheckInventaire
      bind $Bouton <3> QuoiQuOnFait
    
    if {[PreFixe]=="HNR"} {
	set Bouton $V.orgatblastn
	lappend LesBoutons $Bouton
	lappend LesWebDeny $Bouton
	button $Bouton -text "OrgaInBlastP genomes/wgs"
	bind $Bouton <1> "GenomiqueComparativeParBlast tblastncompletegenomes"
	bind $Bouton <2> "GenomiqueComparativeParBlast tblastnwgs"
	set Bouton $V.orgablastn
	lappend LesBoutons $Bouton
	lappend LesWebDeny $Bouton
	button $Bouton -text "OrgaInBlastN wgs"
	bind $Bouton <1> "GenomiqueComparativeParBlast blastnwgs"
	set Bouton $V.orgatblastp
	lappend LesBoutons $Bouton
	lappend LesWebDeny $Bouton
	button $Bouton -text "OrgaInBlastP protall/ refseq"
	bind $Bouton <1> "GenomiqueComparativeParBlast blastp"
	bind $Bouton <2> "GenomiqueComparativeParBlast blastprefseq-prot"
    }
    
    if {[regexp "YEAH" [RepertoireDuGenome]]} {
	set Bouton $V.yeah
	lappend LesBoutons $Bouton
	lappend LesWebDeny $Bouton
	button $Bouton -text "YEAH Show / Find / What"
	bind $Bouton <1> YEAHshow
	bind $Bouton <2> YEAHfind
	bind $Bouton <3> YEAHshowYeast
	set Bouton $V.yeah2
	lappend LesBoutons $Bouton
	lappend LesWebDeny $Bouton
	button $Bouton -text "YEAH mouvement 340 319"
	bind $Bouton <1> YEAHmouvement
    }
    
    if {[regexp "Tparva" [RepertoireDuGenome]]} {
	set Bouton $V.genoComp
	lappend LesBoutons $Bouton
	lappend LesWebDeny $Bouton
	button $Bouton -text "ComparativeGenomic Tb/Pf/Eh"
	bind $Bouton <1> YesScNoTb
	bind $Bouton <2> YesScNoPf
	bind $Bouton <3> YesScNoEh
	set Bouton $V.genoCount
	lappend LesBoutons $Bouton
	lappend LesWebDeny $Bouton
	button $Bouton -text "ComparativeGenomic Counts/Combi"
	bind $Bouton <1> "PhyloDistribution {} {} Show"
	bind $Bouton <2> "PhyloDistribution ChooseCombi Name Show"
    }
    
    if {[OnTraite "MTM1"]} {
	set Bouton $V.clonage
	lappend LesBoutons $Bouton
	lappend LesWebDeny $Bouton
	button $Bouton -text "MTM1"
	bind $Bouton <1> "MTM1 show"
	bind $Bouton <2> "MTM1 show"
	bind $Bouton <3> "MTM1 show"
    }
    
    if {[OnTraiteDesClones]} {
	set Bouton $V.clonage
	lappend LesBoutons $Bouton
	lappend LesWebDeny $Bouton
	button $Bouton -text "Cloning /Show/ Order"
	bind $Bouton <1> InventaireDeLaDatabaseClonage
	bind $Bouton <2> InventaireDeLaDatabaseClonage
	bind $Bouton <3> GestionDesClones
    }
    
    if {0} {
	set Bouton $V.genoret
	lappend LesBoutons $Bouton
	lappend LesWebDeny $Bouton
	button $Bouton -text "Genoret GUs /ShowUploads"
	bind $Bouton <1> ShowGUs
	bind $Bouton <2> ShowUploads
    }
    
    if {[OnTraite "Bathy2010"]} {
	set Bouton $V.assemblybbtools
	lappend LesBoutons $Bouton
	lappend LesWebDeny $Bouton
	button $Bouton -text "AssemblyDbTools Bathymodiolus"
	bind $Bouton <1> "AssemblyDbTools Bathymodiolus"
    }

    if {[OnTraite "CilioCarta" "Like"] || [OnTraite "OI2017" "Like"]} {
	set Bouton $V.blastOutliers
	lappend LesBoutons $Bouton
	lappend LesWebDeny $Bouton
	button $Bouton -text "OlymClades /BlastOutliers Expect/Score"
	bind $Bouton <1> "OlymMedals"
	bind $Bouton <2> "BlastOutliers UseExpect"
	bind $Bouton <3> "BlastOutliers UseSCore"

	set Bouton $V.distri
	lappend LesBoutons $Bouton
	lappend LesWebDeny $Bouton
	button $Bouton -text "Clades Rank Distribution Average/ First Only"
	bind $Bouton <1> "CladesDistribution Average Rank"
	bind $Bouton <2> "CladesDistribution First Rank"
	bind $Bouton <3> ""

    }


    
    set Bouton $V.baide
    lappend LesBoutons $Bouton
    button $Bouton -text "ShowOrf/ChangeGenome/Exit\nDissmiss all windows"
      bind $Bouton <1> {SeeAby Show [Entre [PreFixe]]}
      bind $Bouton <2> ChangeGenome
      bind $Bouton <3> Boum
      bind $Bouton <Shift-1> "DismissToutesLesFenetres"
      if { ! [info exists AvecTintin]} { set AvecTintin 1 }
    if { ! [PourWscope] && $AvecTintin} {
	image create photo periscope  -file $FichierGscopeImage
	image create photo periscope2 -file $FichierGscopeImage2
	$Bouton configure -image periscope
	  bind $Bouton <Enter> "$Bouton configure -image periscope2"
	  bind $Bouton <Leave> "$Bouton configure -image periscope"
    }


    set Bouton $V.bgscope
    lappend LesBoutons $Bouton
    button $Bouton -text "View Linear/Circular/List of $CurrentGenome"
      bind $Bouton <1> "GscopeBoard $CurrentGenome"
      bind $Bouton <2> "RscopeBoard $CurrentGenome"
      bind $Bouton <3> "SeeAby Show \[ChoixParmi \[PresentationDesPABs\]\]"
    
    set Bouton $V.bmap
    if {[MapCliquable "Existe"]} {
	lappend LesBoutons $Bouton
    } else {
	lappend LesBoutonsDeVitrineCaches $Bouton
    }
    lappend LesWebDeny $Bouton
    button $Bouton -text "Clicable Map of  $CurrentGenome"
      bind $Bouton <1> MapCliquable
    
    set Bouton $V.bblaali
    set FichierDiffBlaAli "$RepertoireDuGenome/fiches/diffblaali"
    if {[file exists $FichierDiffBlaAli]} {
	lappend LesBoutons $Bouton
    } else {
	lappend LesBoutonsDeVitrineCaches $Bouton
	lappend LesWebDeny $Bouton
    }
    button $Bouton -text "BlastP vs DbClust / ClustOperon"
      bind $Bouton <1> "AfficheVariable \[ContenuDuFichier $FichierDiffBlaAli\] AvecSmallMSF"
      bind $Bouton <2> "AfficheOperonsCommunsAuxClusters"
    
    set Bouton $V.bvisupepcurrentgenome
    lappend LesBoutonsDeVitrineCaches $Bouton
    button $Bouton  -text "List prot/nuc of $CurrentGenome"
      bind $Bouton <1> {EtudieLesProteinesDe $CurrentGenome}
      bind $Bouton <2> {EtudieLesNucleiquesDe $CurrentGenome}
    
    if {[OnTraiteUnGenome]} {
	set Bouton $V.bdotplot
	lappend LesBoutons $Bouton
	button $Bouton -text "Proteome DotPlot vs ... "
	bind $Bouton <1> {eval DotPlot [Entre "genomes Ask Proches"]}
	
	set Bouton $V.bblastn
	lappend LesBoutons $Bouton
	lappend LesWebDeny $Bouton
	button $Bouton -text "BlastN of another Complete Genome"
	  bind $Bouton <1> BlastNDUnOrgaComplet
	
	set Bouton $V.bTGCA
	lappend LesBoutonsDeVitrineCaches $Bouton
	lappend LesWebDeny $Bouton
	button $Bouton -text "Show Two Gene Cluster Analysis ... "
	  bind $Bouton <1> RosaceDesTwoGenesCluster
    }
    if {[OnTraiteUnGenome] || [PreFixe]=="ANN"} {
	set Bouton $V.brangphylo
	lappend LesBoutons $Bouton
	button $Bouton -text "Phylogenic rank Show/New/Tamis"
	  bind $Bouton <1> DemandeEtDessineOrgaEtSesPlaces
	  bind $Bouton <2> PhyloRank 
	  bind $Bouton <3> PhyloRankDuTamis 
    }

    if {0} {
	set Bouton $V.bDHA
	lappend LesBoutons $Bouton
	lappend LesWebDeny $Bouton
	button $Bouton -text "X-HDA Show/Ask/New"
	#Jean a rajoute
	#bind $Bouton <1> "ShowHDACroises {}"
	bind $Bouton <1> "AfficheBilanXHda"
	bind $Bouton <2> "ShowHDACroises AskForFile"
	bind $Bouton <3> "NewHDACroises" 
    }

    set Bouton $V.bSetup
    lappend LesBoutons $Bouton
    lappend LesBoutonsNonOpen $Bouton
    lappend LesWebDeny $Bouton
    button $Bouton -text "SetupGscope/setenv / Bird"
      bind $Bouton <1> SetupGscope
      bind $Bouton <2> AfficheLEnvironnementDeGscope
      bind $Bouton <3> BirdGscopeSearch

    set Bouton $V.bbigbang
    lappend LesBoutons $Bouton
    lappend LesBoutonsNonOpen $Bouton
    lappend LesWebDeny $Bouton
    button $Bouton -text "Complete database/Start/Stop"
      bind $Bouton <1> CreeLaBaseOuLaCollection
      bind $Bouton <2> JeCommenceABosser
      bind $Bouton <3> TuArretesDeBosser
    
    set Bouton $V.environnement
    lappend LesBoutons $Bouton
    lappend LesBoutonsNonOpen $Bouton
    lappend LesWebDeny $Bouton
    button $Bouton -text "Gscope Sources / .tar / .exe"
    bind $Bouton <1> AfficheLesSourcesDeGscope
    bind $Bouton <2> TarDeGscope
    bind $Bouton <3> FreewrapGscope
    
    set Bouton $V.blittlebrother
    lappend LesBoutons $Bouton
    lappend LesBoutonsNonOpen $Bouton
    lappend LesWebDeny $Bouton
    button $Bouton -text "Gscope chez le Psy /Src/Environ"
    bind $Bouton <1> AfficheLesProcs
    bind $Bouton <2> AfficheLesSourcesDeGscope
    bind $Bouton <3> AfficheLEnvironnementDeGscope
    
    set ExistingPorts [DialogPort "GetAll"]
    set Bouton $V.dialog
    lappend LesBoutons $Bouton
    lappend LesBoutonsNonOpen $Bouton
    lappend LesWebDeny $Bouton
    button $Bouton -text "Dialog on [Hostname] $ExistingPorts /+"
      bind $Bouton <1> "DialogPort DisplayAll"
      bind $Bouton <2> "DialogPort New; DialogPort DisplayAll"
 
    set Bouton $V.bbigbrother
    lappend LesBoutons $Bouton
    lappend LesBoutonsNonOpen $Bouton
    lappend LesWebDeny $Bouton
    button $Bouton -text "Big Brother /Source/again"
    bind $Bouton <1> DemandeEtExecute
    bind $Bouton <2> ReSource
    bind $Bouton <3> "ReSource Precedent"

    set Bouton $V.bboum
    lappend LesBoutons $Bouton
    button $Bouton -text "Exit Gscope \!"
      bind $Bouton <1> Boum
      bind $Bouton <2> "CodeSecret 0"
      bind $Bouton <3> "CodeSecret 1"

    if {0 && ! [PourWscope] && $AvecTintin} {
	image create photo LogoBInG   -file $FichierGscopeLogoBInG
	image create photo ExitGscope -file $FichierGscopeExitGscope
	$Bouton configure -image LogoBInG
	bind $Bouton <Enter> "CodeSecret Enter ; $Bouton configure -image ExitGscope"
	bind $Bouton <Leave> "CodeSecret Leave ; $Bouton configure -image LogoBInG"
    }
    
    set nB [llength $LesBoutons]
    set iB $nB
    foreach b $LesBoutons {
	if {[PourWscope] && [lsearch -exact $LesWebDeny $b]>-1 } {
	    if {[catch {destroy $b} Message]} { Espionne $Message }
	    continue
	} 
	if { ! [GscopeIsOpen] && [lsearch -exact $LesBoutonsNonOpen $b]>-1 } { 
	    continue
	} 
	lappend LesBoutonsDeVitrine $b
	$b configure -background [Nuance [expr [incr iB -1]/(1.*$nB)]]
	$b configure -foreground black
	pack $b -fill both
	if { ! [PourWscope]} {
	    bind $b <Control-3> "if \[OuiOuNon \"Destroy this button ?\"\] { destroy $b }"
	}
    }
    foreach b $LesBoutonsDeVitrineCaches {
	$b configure -background "#654321"
	$b configure -foreground "#123456"
    }
    
    if {[OnTraiteDesClones]} {
	$V.clonage configure -background "magenta"
    }

    if { $V=="" } {
	set V .
    }
    
    set Ports [DialogPort "GetAll"]
    wm title $V "$CurrentGenome $Ports Gscope [VersionDeGscope]"
    return $V
}

proc DetruireLeBoard w {
    Wup "Kills and erase the board from the currentlist"
    global KanvaCourant
    global LesKanvasOuverts

    after 200 destroy $w

    set K $w.canvas

    set i [lsearch $LesKanvasOuverts $K]
    if {$i < 0} { return }
 
    set LesKanvasOuverts [lreplace LesKanvasOuverts $i $i]
    if {[info exists KanvaCourant] && $KanvaCourant==$K} {
	unset KanvaCourant
	if {[llength $LesKanvasOuverts] > 0} {
	    set KanvaCourant [lindex $LesKanvasOuverts end]
	}
    }
    return
}

proc CommandesExecPossibles {} {
    global Commandes CommandesDefaut

    set Commandes(integral)  "batch-integral.tclsh "
    set Commandes(dbclustal) "batch-dbclustal.tclsh "

    array set CommandesDefaut [array get Commandes]
}

proc OnColorieLesFrames {{X ""}} {
    global OnColorieLesFrames
    
    if { ! [info exists OnColorieLesFrames]} { set OnColorieLesFrames 0 }

    if {$X==""} {
	return $OnColorieLesFrames
    } else {
	return [set OnColorieLesFrames $X]
    }
}

proc ChoixColoration {} {

    set LesColor [ColorationsPossibles]
    set LesTradu [LaTraduction [ColorationsPossibles]]
    set LesRangs [ColorationsPossibles "" "OnVeutLesRangs"]
    foreach Rang $LesRangs {
	set iCoul [expr 0.1*int($Rang)]
	set CouleurDuTexte [Nuance $iCoul 0. 0.6]
	lappend LesCouleursDuTexte $CouleurDuTexte
    }
    return [ChoixParmiJoli $LesColor $LesCouleursDuTexte $LesTradu]
}

proc ColorationsPossibles {{SansTamis ""} {QueVeutOn ""}} {
    global LesColorationsPossibles LesColorationsPossiblesRangs

    set OnVeutLesRangs [string equal $QueVeutOn "OnVeutLesRangs"] 

    if { ! $OnVeutLesRangs && [info exists LesColorationsPossibles]} {
	return $LesColorationsPossibles
    }
    if { $OnVeutLesRangs && [info exists LesColorationsPossiblesRangs]} {
	return $LesColorationsPossiblesRangs
    }
    foreach Ligne [split [info body CouleurParTypeEtNom] "\n"] {
	if {[PourWscope] && [regexp "\#.* noWeb" $Ligne]} { continue }
	if { ! [regexp {\"Coloration_[^\$][^\"]+} $Ligne CoCo]} { continue }
	set Rang 9.9
	if {[regexp "\#" $Ligne]} { set Rang [FloatApres "\#" dans $Ligne] }
	if {$SansTamis!="" && [regexp "FromTamis" $Ligne]} { continue }
	regsub {\"Coloration_} $CoCo "" Coloration
	lappend LesRangCol "$Rang $Coloration"
    }
    set LesRangCol [lsort -command CompareLesFloatsEnDebut $LesRangCol]
    foreach RangCol $LesRangCol {
	scan $RangCol "%f %s" Rang Col
	lappend LesColorationsPossibles $Col
	lappend LesColorationsPossiblesRangs $Rang
    }
    if {$OnVeutLesRangs} {
	return $LesColorationsPossiblesRangs
    } else {
	return $LesColorationsPossibles
    }
}

proc BindLaRosace R {
	$R bind "Zone"      <1>               "GereLesZoneEtiquettee $R %x %y arc Point"
	$R bind "Zone"      <B1-Motion>       "GereLesZoneEtiquettee $R %x %y arc Motion"
	$R bind "Zone"      <ButtonRelease-1> "GereLesZoneEtiquettee $R %x %y arc Relache"
	$R bind "Zone"      <2>               "GereLesZoneEtiquettee $R %x %y arc Erase"
	$R bind "Zone"      <3>               "GereLesZoneEtiquettee $R %x %y arc ModifCouleur"
	$R bind "Zone"      <Shift-3>         "GereLesZoneEtiquettee $R %x %y arc ModifTaille"
	$R bind "Zone"      <Control-3>       "GereLesZoneEtiquettee $R %x %y arc ModifSens"
								    
	$R bind "Fleche"    <1>               "GereLesZoneEtiquettee $R %x %y line Point"
	$R bind "Fleche"    <B1-Motion>       "GereLesZoneEtiquettee $R %x %y line Motion"
	$R bind "Fleche"    <ButtonRelease-1> "GereLesZoneEtiquettee $R %x %y line Relache"
	$R bind "Fleche"    <2>               "GereLesZoneEtiquettee $R %x %y line Erase"
	$R bind "Fleche"    <3>               "GereLesZoneEtiquettee $R %x %y line ModifCouleur"
	$R bind "Fleche"    <Shift-3>         "GereLesZoneEtiquettee $R %x %y line ModifTaille"
	$R bind "Fleche"    <Control-3>       "GereLesZoneEtiquettee $R %x %y line ModifSens"
								    
	$R bind "Etiquette" <1>               "GereLesZoneEtiquettee $R %x %y text Point"
	$R bind "Etiquette" <B1-Motion>       "GereLesZoneEtiquettee $R %x %y text Motion"
	$R bind "Etiquette" <ButtonRelease-1> "GereLesZoneEtiquettee $R %x %y text Relache"
	$R bind "Etiquette" <2>               "GereLesZoneEtiquettee $R %x %y text Erase"
	$R bind "Etiquette" <3>               "GereLesZoneEtiquettee $R %x %y text ModifCouleur"
	$R bind "Etiquette" <Shift-3>         "GereLesZoneEtiquettee $R %x %y text ModifTaille"
	$R bind "Etiquette" <Control-3>       "GereLesZoneEtiquettee $R %x %y text ModifTexte"

	$R bind "TexteRosace" <1>               "GereLesZoneEtiquettee $R %x %y text Point"
	$R bind "TexteRosace" <B1-Motion>       "GereLesZoneEtiquettee $R %x %y text Motion"
	$R bind "TexteRosace" <ButtonRelease-1> "GereLesZoneEtiquettee $R %x %y text Relache"
	$R bind "TexteRosace" <2>               "GereLesZoneEtiquettee $R %x %y text Erase"
	$R bind "TexteRosace" <3>               "GereLesZoneEtiquettee $R %x %y text ModifCouleur"
	$R bind "TexteRosace" <Shift-3>         "GereLesZoneEtiquettee $R %x %y text ModifTaille"
	$R bind "TexteRosace" <Control-3>       "GereLesZoneEtiquettee $R %x %y text ModifTexte"
}

proc FlecheSurArc {R Id {Orientation "F"}} {
    Wup "Puts an arrow at the end of the arc Id (clock-wize if Forward ...)"   
    set PI 3.14159

    set DeltaAnglePourFlecheDeg 1.5
    set DeltaAnglePourFlecheRad [expr $DeltaAnglePourFlecheDeg*$PI/180.]

    scan [$R coords $Id] "%f %f %f %f" G H D B
    set Rayon [expr ($D-$G)/2]
    set InRayon  [expr $Rayon*(1-0.9*$DeltaAnglePourFlecheRad)]
    set OutRayon [expr $Rayon*(1+0.9*$DeltaAnglePourFlecheRad)]

    set Start   [$R itemcget $Id -start]
    set Extent  [$R itemcget $Id -extent]
    set Couleur [$R itemcget $Id -outline]

    Espionne "$Start $Extent"

    if {$Extent>0} {
	set NewExtent [expr $Extent-$DeltaAnglePourFlecheDeg]
	if {$Orientation=="F"} {
	    set NewStart [expr $Start+$DeltaAnglePourFlecheDeg]
	    set Pointe   $Start
	    set Queue    $NewStart 
	} else {
	    set NewStart $Start
	    set Queue    [expr $Start+$NewExtent]
	    set Pointe   [expr $Start+$Extent]
	}
    } else {
	set NewExtent [expr $Extent+$DeltaAnglePourFlecheDeg]
	if {$Orientation=="F"} {
	    set NewStart $Start
	    set Queue    [expr $Start+$NewExtent]
	    set Pointe   [expr $Start+$Extent]
	} else {
	    set NewStart [expr $Start+$DeltaAnglePourFlecheDeg]
	    set Pointe   $Start
	    set Queue    $NewStart 
	}
    }
    set Queue  [expr $Queue*$PI/180]
    set Pointe [expr $Pointe*$PI/180]
    
    $R itemconfigure $Id -start $NewStart -extent $NewExtent

    set InQueueX  [expr ($G+$D)/2  +  $InRayon*cos($Queue)]
    set InQueueY  [expr ($H+$B)/2  -  $InRayon*sin($Queue)]
    set OutQueueX [expr ($G+$D)/2  + $OutRayon*cos($Queue)]
    set OutQueueY [expr ($H+$B)/2  - $OutRayon*sin($Queue)]
    set PointeX   [expr ($G+$D)/2  +    $Rayon*cos($Pointe)]
    set PointeY   [expr ($H+$B)/2  -    $Rayon*sin($Pointe)]
    $R create polygon \
	    $PointeX $PointeY \
	    $InQueueX $InQueueY \
	    $OutQueueX $OutQueueY \
	    $PointeX $PointeY \
	    -fill $Couleur -outline $Couleur -tags "Fleche"
}

proc CouleurExquiseDeLaZone {Etiquette {VraieCouleur ""}} {
    Wup "Returns the color of the dotplot zone"
    Wup " appending the name of the label if not VraieCouleur"
    global RepertoireDuGenome
    global LaPaletteDesCouleursDeZoneEtiquettee

    if { ! [info exists LaPaletteDesCouleursDeZoneEtiquettee]} {
	foreach Ligne [LesLignesDuFichier "$RepertoireDuGenome/fiches/palettezoneetiquette"] {
	    scan $Ligne "%s %s" Couleur E
	    set LaCouleur($E) "$Couleur" 
	}
    }

    set PremiereLettre [string range $Etiquette 0 0] 
    if {$VraieCouleur==""} {
	return [set LaCouleur($PremiereLettre)]_$Etiquette
    } else {
	return [set LaCouleur($PremiereLettre)]
    }
}

proc ArcLaListe {ListeNomCouleur R Type {MilieuOuAngle "milieu"} {RayonMinimum ""} {RayonMaximum ""}} {
    Wup "Creates the arcs associated to each element of the list"
    global ParametresDuBoard

    Wup "Pour les fleches a l'envers c'est code 'Reverse\NomOuAngle' "

    set PI 3.14159

    set DeltaAnglePourFlecheDeg 1.5
    set DeltaAnglePourFlecheRad [expr $DeltaAnglePourFlecheDeg*$PI/180.]

    set CentreX [set ParametresDuBoard($R,CentreX)]
    set CentreY [set ParametresDuBoard($R,CentreY)]
    set RayonMoyen     [set ParametresDuBoard($R,RayonMoyen)]
    set OffsetRayonMin [set ParametresDuBoard($R,OffsetRayonMin)]
    set OffsetRayonMax [set ParametresDuBoard($R,OffsetRayonMax)]
    set IemeCouche     [set ParametresDuBoard($R,IemeCouche)]
    
    set Rayon  $RayonMinimum
    set Gauche [expr $CentreX-$Rayon]
    set Haut   [expr $CentreY-$Rayon]
    set Droite [expr $CentreX+$Rayon]
    set Bas    [expr $CentreY+$Rayon]

    set InRayon  [expr $Rayon*(1-0.9*$DeltaAnglePourFlecheRad)]
    set OutRayon [expr $Rayon*(1+0.9*$DeltaAnglePourFlecheRad)]

    set n [llength $ListeNomCouleur]

    set CumulF 0
    set CumulR 0
    set OldCouleur "CACADOIE"
    foreach {NomOuAngle Couleur} [concat $ListeNomCouleur [list "NomBidon" "CouleurPourFin"]] {
	if {[regexp {^Reverse_} $NomOuAngle]} {
	    set Orientation "R"
	    incr CumulR
	} else {
	    set Orientation "F"
	    incr CumulF
	}
	regsub {^Reverse_} $NomOuAngle "" NomOuAngle
	set Etiquette " "
	if {$Couleur != $OldCouleur && $OldCouleur != "CACADOIE"} {
	    if {$OldCouleur=="VIDE"} { set NonVide 0 } else { set NonVide 1 }
	    set i_ [string first "_" $OldCouleur]
	    if {$i_ < 0} {
		set VraieCouleur $OldCouleur
	    } else {
		set Etiquette [string range $OldCouleur [incr i_ 1] end] 
		set VraieCouleur [string range $OldCouleur 0 [incr i_ -2]]
	    } 
	    if {$CumulF>=$CumulR} {
		set Orientation "F"
		set NewStart [expr $Start+$DeltaAnglePourFlecheRad]
		set Queue    $NewStart
		set Pointe   $Start
	    } else {
		set Orientation "R"
		set NewStart $Start
		set Pointe [expr $Start+$Extent]
		set Queue  [expr $Pointe-$DeltaAnglePourFlecheRad] 
	    }
	    set NewExtent [expr $Extent-$DeltaAnglePourFlecheRad]

	    set Repeche 0
	    if {$Etiquette=="B" && [expr abs($Extent) < 2*$PI*5000./[LongueurADN]]} {
		set Repeche 1
	    }
	    set Noye 0
	    if {$Etiquette=="D5" && [expr abs($Extent) < 2*$PI*30000./[LongueurADN]]} {
		set Noye 1
	    }
	    Espionne "$Etiquette [expr $Extent*[LongueurADN]/(2*$PI)] $Repeche $Noye"
	    if {$Repeche || (! $Noye && $NonVide && [expr abs($Extent) > 2*$PI*19000./[LongueurADN]])} {
		set IdArc [$R create arc $Gauche $Haut $Droite $Bas -width 7 \
			-start [expr $NewStart*180/$PI] -extent [expr $NewExtent*180/$PI] \
			-style "arc" -outline $VraieCouleur -tags "Zone"]
		set InQueueX  [expr ($Gauche+$Droite)/2  +  $InRayon*cos($Queue)]
		set InQueueY  [expr ($Haut+$Bas)/2       -  $InRayon*sin($Queue)]
		set OutQueueX [expr ($Gauche+$Droite)/2  + $OutRayon*cos($Queue)]
		set OutQueueY [expr ($Haut+$Bas)/2       - $OutRayon*sin($Queue)]
		set PointeX   [expr ($Gauche+$Droite)/2  +    $Rayon*cos($Pointe)]
		set PointeY   [expr ($Haut+$Bas)/2       -    $Rayon*sin($Pointe)]
		if { 0 } {
		    $R create polygon \
			    $PointeX $PointeY \
			    $InQueueX $InQueueY \
			    $OutQueueX $OutQueueY \
			    $PointeX $PointeY \
			    -fill $VraieCouleur -outline $VraieCouleur -tags "Fleche"
		} else {
		    FlecheSurArc $R $IdArc $Orientation 
		}
		set EtiqX [expr ($Gauche+$Droite)/2  + 1.00*$OutRayon*cos($Start+$Extent/2)]
		set EtiqY [expr ($Haut+$Bas)/2       - 1.00*$OutRayon*sin($Start+$Extent/2)]
		$R create text $EtiqX $EtiqY -text $Etiquette \
			-anchor c \
			-font {Courier 10} \
			-tags "Etiquette"
	    }
	    unset Start
	    set CumulF 0
	    set CumulR 0
	}
	if {$Couleur == "CouleurPourFin"} { break }
	if {$MilieuOuAngle == "angle"} {
	    set Angle $NomOuAngle
	} elseif {$MilieuOuAngle == "milieu"} {
	    set Angle [AngleDansRosace $R $Nom]
	}
	if { ! [info exist Start]} { set Start $Angle }
	set Extent [EntreMinEtMax [expr $Angle-$Start] [expr -$PI] $PI]
	set OldCouleur $Couleur
    }
}
 
proc Plotte {Nous Vous NosPos VosPos {MinX ""} {MaxX ""} {MinY ""} {MaxY ""} {Orga ""} {PourGif ""}} {
    Wup "Creates the dotplot with the lists"
    global DotPlotDesProches
    global ScrollRectangleOriginal
    global IdScrollRectangle
    global LesDotPlotCourants
    global ParametresDuDotPlot
    global PlottePourBlastN
    global LesOrdresPourGif
    
    Gs "Canvas"
    
    set Titre "Dotplot of [NotreOS] versus $Orga" 

    if {$PourGif!="" || $MinX=="PourGif"} {
	set PourGif 1
    } else {
	set PourGif 0
    }
    if {$PourGif} {
	set Canvas    NeRienFaire
	set Bind      NeRienFaire
	set Pack      NeRienFaire
	set Fram      NeRienFaire
	set Button    NeRienFaire
	set Scrollbar NeRienFaire
	set Grid      NeRienFaire
	set FonctionRejetteLaBoite "RejetteLaBoite"
	set LesOrdresPourGif {}
	set w "PourGif"
	set K "OrdrePourGif"
    } else {
	set Canvas    canvas
	set Bind      bind
	set Pack      pack
	set Fram      frame
	set Button    button
	set Scrollbar scrollbar
	set Grid      grid
	set FonctionRejetteLaBoite "NeRejettePasLaBoite"
	set w [NomDe dotplot]
	catch {destroy $w}
	toplevel $w
	wm title $w "$Titre"
	wm iconname $w "$Titre"
	set K       $w.canvas
    }

    set xOld 0
    set yOld 0
    set CentreWindow 5
    set LargeurWindow [expr 2*$CentreWindow+1]
    set LesPentes {}
    set LesXaNoter {}
    set Premiere 0
    set PenteLisseeCourante 0
    set NosSuivants $NosPos 
    set VosSuivants $VosPos 
    foreach x $NosPos y $VosPos {
	set NosSuivants [lrange $NosSuivants 1 end]
	set VosSuivants [lrange $VosSuivants 1 end]
	if { ! [info exists DansLaColonne($x)]} { set DansLaColonne($x) 0 }
	incr DansLaColonne($x)

	set PenteLissee($x) $PenteLisseeCourante
	if {$DotPlotDesProches} {
	    set Pente 0
	    if { 0 } {
		if {[expr abs($y-$yOld) < 10*abs($x-$xOld)]} {
		    set Proches($x,$y) 1
		    set Proches($xOld,$yOld) 1
		}
	    } else {
		foreach xs $NosSuivants ys $VosSuivants {
		    if {$xs==$x} { continue }
		    set DX [expr abs($x-$xs)]
		    set DY [expr abs($y-$ys)]
		    if { $DX  > 5000 } { break }
		    if { [expr abs($DX-$DY)] < 500 } {
			set Proches($x,$y)   1
			set Proches($xs,$ys) 1
			break
		    }
		} 
	    }
	    if {[info exists Proches($x,$y)]} {
		if {[expr ($y-$yOld)*($x-$xOld) == 0]} {
		    set Pente 0
		} else {
		    set Pente [expr (($y-$yOld)*($x-$xOld))/abs(($y-$yOld)*($x-$xOld))]
		}
	    }
	    set xOld $x
	    set yOld $y

	    if {[llength $LesPentes] > 0} { set Premiere [lindex $LesPentes 0] }
	    if {[llength $LesXaNoter] == $CentreWindow} {
		set LesPentes [lreplace $LesPentes 0 0]
	    }		
	    if {[llength $LesPentes] == $LargeurWindow} {
		set LesPentes [lreplace $LesPentes 0 0]
		set PenteLisseeCourante [expr $PenteLisseeCourante - $Premiere]
	    }
	    lappend LesPentes $Pente
	    lappend LesXaNoter $x
	    set PenteLisseeCourante [expr $PenteLisseeCourante + $Pente]
	    set PenteLissee([lindex $LesXaNoter 0]) $PenteLisseeCourante
	}
    }

    if { $MinX == "" } {
	set MinX  99999999
	set MaxX -99999999
	set MinY  99999999
	set MaxY -99999999
	foreach x $NosPos y $VosPos {
	    set MinX [Mini $MinX $x]
	    set MaxX [Maxi $MaxX $x]
	    set MinY [Mini $MinY $y]
	    set MaxY [Maxi $MaxY $y]
	}
    }

    set MinXY [Mini $MinX $MinY]
    set MaxXY [Maxi $MaxX $MaxY]

    set LargeurMaxi [expr ($MaxX)]
    set HauteurMaxi [expr ($MaxY)]
    set LargeurVoulue [expr (512*$MaxX)/$MaxXY]
    set HauteurVoulue [expr (512*$MaxY)/$MaxXY]

    set CanvaScroMinX 0
    set CanvaScroMinY 0
    set CanvaScroMaxX $LargeurMaxi
    set CanvaScroMaxY $HauteurMaxi

    set ScroHor $w.hscroll
    set ScroVer $w.vscroll
    set KShSv   $w.grid
    set Boutons $w.buttons

    $Fram  $Boutons
    $Pack  $Boutons -side bottom -fill x -pady 2m
    
    $Button $Boutons.dismiss -text "Dismiss" -background "red" -command "DetruireLeDotPlot $w"
      $Pack $Boutons.dismiss -side left -expand 1
    $Button $Boutons.postscript -text "Zoom/UnZoom/Reset\nGif/Postscript/Print" -background "yellow"
      $Bind $Boutons.postscript <1>       "Gonfle $w all gonfle gonfle"
      $Bind $Boutons.postscript <2>       "Gonfle $w all degonfle degonfle"
      $Bind $Boutons.postscript <3>       "Gonfle $w all reset reset"
      $Bind $Boutons.postscript <Shift-1> "CanvaEnPNG $K"
      $Bind $Boutons.postscript <Shift-2> "CanvaEnPostscript $K Visible AskF"
      $Bind $Boutons.postscript <Shift-3> "CanvaEnImpression $K"
      $Pack $Boutons.postscript -side left -expand 1
    $Button $Boutons.manuel -text "Line manual  v/vh/h\nLines in file v/vh/h\nLines from TRNAs"
      $Bind $Boutons.manuel <1> "DemarcationEnPosition $K v"
      $Bind $Boutons.manuel <2> "DemarcationEnPosition $K vh"
      $Bind $Boutons.manuel <3> "DemarcationEnPosition $K h"
      $Bind $Boutons.manuel <Shift-1> "DemarcationEnPositionDansFichier $K v"
      $Bind $Boutons.manuel <Shift-2> "DemarcationEnPositionDansFichier $K vh"
      $Bind $Boutons.manuel <Shift-3> "DemarcationEnPositionDansFichier $K h"
      $Bind $Boutons.manuel <Control-1> "DemarcationDesTRNAs $K v"
      $Bind $Boutons.manuel <Control-2> "DemarcationDesTRNAs $K vh"
      $Bind $Boutons.manuel <Control-3> "DemarcationDesTRNAs $K h"
      $Pack $Boutons.manuel -side left -expand 1
    $Button $Boutons.saverest -text "Save/Replace/Append\nvertical lines"
      $Bind $Boutons.saverest <1> "SauveLaDemarcation     $K"
      $Bind $Boutons.saverest <2> "RestaureUneDemarcation $K"
      $Bind $Boutons.saverest <3> "AppendUneDemarcation   $K"
      $Pack $Boutons.saverest -side left -expand 1
    $Button $Boutons.demarcation \
	    -text "To Rosac/DotPl/ Recomb\nLabels vert/hori/all\nErase vert/hori/all" \
	    -background "green"
      $Bind $Boutons.demarcation <1> "DemarqueLaRosace  $K"
      $Bind $Boutons.demarcation <2> "DemarqueLeDotPlot $K"
      $Bind $Boutons.demarcation <3> "RosaceDuDotPlot  $K"
      $Bind $Boutons.demarcation <Shift-1> "Demarcation rev $K"
      $Bind $Boutons.demarcation <Shift-2> "Demarcation reh $K"
      $Bind $Boutons.demarcation <Shift-3> "Demarcation re  $K"
      $Bind $Boutons.demarcation <Control-1> "Demarcation dallv_ifyes $K "
      $Bind $Boutons.demarcation <Control-2> "Demarcation dallh_ifyes $K"
      $Bind $Boutons.demarcation <Control-3> "Demarcation dall_ifyes  $K"
      $Pack $Boutons.demarcation -side left -expand 1

    $Fram $KShSv
    $Scrollbar $ScroHor -orient horiz -command "$K xview"
    $Scrollbar $ScroVer               -command "$K yview"

    $Canvas $K \
	    -width  $LargeurVoulue \
	    -height $HauteurVoulue

    $K configure \
	    -scrollregion [list $CanvaScroMinX $CanvaScroMinY $CanvaScroMaxX $CanvaScroMaxY] \
	    -xscrollcommand "$ScroHor set" \
	    -yscrollcommand "$ScroVer set"

    set IdScrollRectangle($K) [$K create rectangle $CanvaScroMinX $CanvaScroMinY $CanvaScroMaxX $CanvaScroMaxY -outline "lightgrey" -tag [list "Cadre"]]
    set ScrollRectangleOriginal($K) "[$K coords [set IdScrollRectangle($K)]]"
    set ParametresDuDotPlot($K,MinX) $MinX 
    set ParametresDuDotPlot($K,MaxX) $MaxX 
    set ParametresDuDotPlot($K,MinY) $MinY 
    set ParametresDuDotPlot($K,MaxY) $MaxY 
    set ParametresDuDotPlot($K,LargeurMaxi) $LargeurMaxi 
    set ParametresDuDotPlot($K,HauteurMaxi) $HauteurMaxi 

    set PosCourbe 900
    set OldPosX 0 
    set OldPosY $PosCourbe
    set Tracons 0
    foreach Moi $Nous Toi $Vous MaPos $NosPos TaPos $VosPos {
	if { $DotPlotDesProches && ! [info exists Proches($MaPos,$TaPos)]} { continue }
	set MonC [expr (($MaPos-$MinX)*$LargeurMaxi)/($MaxX-$MinX)]
	set TonC [expr (($TaPos-$MinY)*$HauteurMaxi)/($MaxY-$MinY)]

	set PenteCourante [set PenteLissee($MaPos)]

	if {$PenteCourante < 0} {
	    set Couleur "blue"
	}
	if {$PenteCourante == 0} {
	    set Couleur "grey"
	}
	if {$PenteCourante > 0} {
	    set Couleur "red"
	}

#	$K create line $OldPosX $OldPosY $MonC [expr $PosCourbe-5*$PenteCourante]
	set OldPosX $MonC
	set OldPosY [expr $PosCourbe-5*$PenteCourante]
	
	if {[info exists PlottePourBlastN]} {
	    if {$Tracons} {
		set MonF $MonC
		set TonF [expr $HauteurMaxi-$TonC]
#		set Moi "$MoiD $MonC"
#		set Toi "$ToiD $TonC"
		if {$PourGif} {
		    set LesTags [list "WebEnter" "$Moi $Toi"]
		} else {
		    set LesTags [list "$Moi" "$Toi" "Coeur"]
		}
		$K create line $MonD $TonD $MonF $TonF -fill "red" -tags $LesTags
		set Tracons 0
	    } else {
		set MoiD $MonC
		set ToiD $TonC
		set MonD $MonC
		set TonD [expr $HauteurMaxi-$TonC]
		set Tracons 1
	    }
	    continue
	} else {
	    set L 300
	    if {$PourGif} {
		set LesTags [list "WebEnter" "$Moi $Toi"]
	    } else {
		set LesTags [list "$Moi" "$Toi" "Coeur"]
	    }
	    $K create rect \
		    [expr $MonC-$L] [expr $HauteurMaxi-$TonC-$L] \
		    [expr $MonC+$L] [expr $HauteurMaxi-$TonC+$L] \
		    -tags $LesTags \
		    -outline $Couleur \
		    -fill $Couleur
	}
    }
    
    $Grid rowconfig    $KShSv 0 -weight 1 -minsize 0
    $Grid columnconfig $KShSv 0 -weight 1 -minsize 0
    
    $Grid $K       -in $KShSv -padx 1 -pady 1  -row 0 -column 0  -rowspan 1 -columnspan 1  -sticky nsew
    $Grid $ScroVer -in $KShSv -padx 1 -pady 1  -row 0 -column 1  -rowspan 1 -columnspan 1  -sticky nsew
    $Grid $ScroHor -in $KShSv -padx 1 -pady 1  -row 1 -column 0  -rowspan 1 -columnspan 1  -sticky nsew
    $Pack $KShSv -expand yes -fill both -padx 1 -pady 1

    $K bind "Coeur" <1>       "PointeDotPlot $K %x %y"
    $K bind "Coeur" <Enter>   "EntreDansCoeur $K %x %y"
    $K bind "Coeur" <Leave>   "SortDeCoeur    $K %x %y"

    $K bind "Coeur" <Shift-1> "Demarcation v  $K %x %y"
    $K bind "Coeur" <Shift-2> "Demarcation vh $K %x %y"
    $K bind "Coeur" <Shift-3> "Demarcation h  $K %x %y"
    $K bind "Coeur" <Control-1> ""
    $K bind "Coeur" <Control-2> ""
    $K bind "Ligne" <Control-3> "Demarcation d $K %x %y"

    $K bind "Etiquette" <1>               "GereLesZoneEtiquettee $K %x %y text Point"
    $K bind "Etiquette" <B1-Motion>       "GereLesZoneEtiquettee $K %x %y text Motion"
    $K bind "Etiquette" <ButtonRelease-1> "GereLesZoneEtiquettee $K %x %y text Relache"
    $K bind "Etiquette" <2>               "GereLesZoneEtiquettee $K %x %y text Erase ; Demarcation d $K %x %y"
    $K bind "Etiquette" <3>               "GereLesZoneEtiquettee $K %x %y text ModifCouleur"
    $K bind "Etiquette" <Shift-3>         "GereLesZoneEtiquettee $K %x %y text ModifTaille"
    $K bind "Etiquette" <Control-3>       "GereLesZoneEtiquettee $K %x %y text ModifTexte"

#   $Bind $K <1>            "PointeDotPlot $K %x %y"
    $Bind $K <2>            "$K scan mark %x %y"
    $Bind $K <B2-Motion>    "$K scan dragto %x %y"

    lappend LesDotPlotCourants $K

    set FacteurX [expr (1.0*$LargeurVoulue)/$LargeurMaxi]  
    set FacteurY [expr (1.0*$HauteurVoulue)/$HauteurMaxi]
    if {! $PourGif} {
	Gonfle $w all $FacteurX $FacteurY
    }

    if {$PourGif} { return $LesOrdresPourGif }
    if { 0 && [PourWscope]} {
	return $w
    } else {
	return $K
    }
}

proc TourneLaListeAutour {Liste CentreX CentreY AngleDelta} {
    Wup "Returns the rotated list"
    set PI 3.14159

    foreach {X Y} $Liste {
	set Angle [AngleDansRosace "CoordonneesVraies" $X $Y $CentreX $CentreY]
	set Rayon [RayonDansRosace "CoordonneesVraies" $X $Y $CentreX $CentreY]

	set NouvelAngle [Entre0Et2PI [expr $Angle+$AngleDelta]]

	lappend Sortie [expr $CentreX+$Rayon*cos($NouvelAngle)]
	lappend Sortie [expr $CentreY+$Rayon*sin($NouvelAngle)]
    }
    return $Sortie
}

proc SwitchEnX {Liste PivotX} {
    Wup "Returns the X-symetrical list"
    foreach {X Y} $Liste {
	lappend Sortie [expr $PivotX+$PivotX-$X]
	lappend Sortie $Y
    }
    return $Sortie
}

proc ManipuleLaRosace {Action R Tag x y} {
    Wup "Manages the point-and-motion for rotating the arcs"
    global ParametresDuBoard
    global AnglePoint

    JeMeSignale 

    set CentreX [set ParametresDuBoard($R,CentreX)]
    set CentreY [set ParametresDuBoard($R,CentreY)]

    set X [$R canvasx $x]
    set Y [$R canvasx $y]

    if {$Action == "Point"} {
	set AnglePoint [AngleDansRosace "CoordonneesVraies" $X $Y $CentreX $CentreY]
	return 
    }
    if {$Action == "Release"} {
	if { ! [info exists AnglePoint]} { return }
	set AngleRelease [AngleDansRosace "CoordonneesVraies" $X $Y $CentreX $CentreY]
	set AngleDelta [Entre0Et2PI [expr $AngleRelease-$AnglePoint]]
    }
    foreach Id [$R find withtag $Tag] {
	set Coordonnees [$R coords $Id]
	if {$Action == "Switch"} {
	    set NouvellesCoordonnees [SwitchEnX $Coordonnees $CentreX]
	}
	if {$Action == "Release"} {
	    set NouvellesCoordonnees [TourneLaListeAutour $Coordonnees $CentreX $CentreY $AngleDelta]
	}
	eval $R coords $Id [split $NouvellesCoordonnees " "]
    }
}

proc LongueurMoyenne {} {
    Wup "Average length of the orfs."
    global ListeDeBoites

    if { ! [info exists ListeDeBoites]} { ChargeListeDeBoites }

    set Mi  9999999
    set Ma -999999
    set CumulLong 0
    set n 0
    foreach Boite $ListeDeBoites {
	set Nom    [Box $Boite nom]
	if { ! [EstUnPAB $Nom] } { continue }
	set Debut  [Box $Boite debut]
	set Fin    [Box $Boite fin]
	set Orient [Box $Boite orient]

	set Long [expr $Fin-$Debut+1]
	set Mi [Mini $Long $Mi]
	set Ma [Maxi $Long $Ma]
	incr CumulLong $Long
	incr n
    }
    set PourcentageCodant [format "%5.2f" [expr 100.*$CumulLong/[LongueurADN]]]

    puts "$n ORFs mini [expr $Mi/3] maxi [expr $Ma/3] moyenne [expr $CumulLong/(3*$n)] $PourcentageCodant"
}

proc LongueurADN {{Orga ""}} {
    Wup "Returns the length in bases of orga's genome" 
    global LongueurADNDesOrganismes
    global ADN TDN RAC

    if {$Orga==""} {
	if {[info exists LongueurADNDesOrganismes("NotreOS")]} {
	    return [set LongueurADNDesOrganismes("NotreOS")]
	}
	if { ! [info exists ADN]} { ChargeADNetTDNetRAC	}
	set LongueurADNDesOrganismes("NotreOS") [expr [string length $ADN]-1]
	return [set LongueurADNDesOrganismes("NotreOS")]
    }
    
    if {[info exists LongueurADNDesOrganismes($Orga)]} {
	return [set LongueurADNDesOrganismes($Orga)]
    }
    if {[info exists LongueurADNDesOrganismes("SontCharges")]} {
	return -1
    }
    ChargeLesPositionsDesOrthologues
    return [LongueurADN $Orga]
}

proc HeureDePosADN {PosADN {Orga ""}} {
    Wup "Returns the clock-wize angle in radian starting at 12:00"
    set PI 3.14159
    if {$Orga==""} {
	return [expr $PosADN*2*$PI/[LongueurADN]]
    }
    return [expr $PosADN*2*$PI/[LongueurADN $Orga]]
}

proc RosaceDeLaRosaceCourante {Type {K ""} {Interieur ""} {Exterieur ""}} {
    global RosaceCourante
    global CurrentGenome
    global TypeCouleur

    if {$K==""} {
	if { ! [info exists RosaceCourante]} {
	    RscopeBoard $CurrentGenome
	}
	set K $RosaceCourante
    }

    set TypeDeCouleur [set TypeCouleur($K)]

    if {$Interieur==""} { set Interieur 0.75 ; set Exterieur 0.80 }

    foreach Nom [ListeDesPABs] {
	set Couleur [CouleurParTypeEtNom $TypeDeCouleur $Nom $K]	
	lappend LesPointes $Nom
	lappend LesPointes $Couleur
    }
    AiguilleLaListe $LesPointes $K "UneListeEnPlus" "milieu" $Interieur $Exterieur 
    return $K
}

proc RosaceDesArcEnCiel {Type {Orga ""} {R ""} } {
    Wup "Creates the wheel of orga's orthologs colored like CurrentGenome" 
    global RepertoireDuGenome
    global ListeDeBoites
    global ListeDesPABs
    global RosaceCourante
    global CurrentGenome
    global LesAutresTagsPourAiguilles

    set PI 3.14159

    if {$R==""} {
	if { ! [info exists RosaceCourante]} {
	    RscopeBoard $CurrentGenome
	}
	set R $RosaceCourante
    }

    if { ! [info exists ListeDeBoites]} { ChargeListeDeBoites }

    if { ! [info exists ListeCompleteDesOrganismesAyantPosOrth]} {
	set ListeCompleteDesOrganismesAyantPosOrth [PositionsDesOrthologues "LaListeDesOrgas" "genomes"]
    }

    set LesOrgas [CocheDansLaListe [concat $ListeCompleteDesOrganismesAyantPosOrth "AllTogether"]]

    if {$LesOrgas==""} { return }

    if {[lsearch $LesOrgas "AllTogether"] > -1} {
	set LesOrgas $ListeCompleteDesOrganismesAyantPosOrth
    }

    set MaxExterieur 0.77
    set MinInterieur 0.55
    set MaxExterieur 1.35
    set MinInterieur 1.15

    set Delta [expr ($MaxExterieur-$MinInterieur)/[llength $LesOrgas]]

    set Exterieur $MaxExterieur
    foreach Orga $LesOrgas {
	set Interieur [expr $Exterieur + $Delta*0.6]
	set LesPointes {}
	foreach Nom $ListeDesPABs {
	    set LesPosOrth [PositionsDesOrthologues $Nom "genomes" $Orga]
	    if {[llength $LesPosOrth]==0} { continue }
	    set PosOrth [lindex $LesPosOrth 0]
	    if {$PosOrth == -1 } { continue }
	    set HeureOrth [HeureDePosADN $PosOrth $Orga]
	    set Couleur [Nuance [expr $HeureOrth/(2*$PI)] 0.0 0.987] 
	    lappend LesPointes $Nom
	    lappend LesPointes $Couleur
	}
	set LesAutresTagsPourAiguilles [list "RosaceArcEnCiel" "AEC_$Orga"]
	AiguilleLaListe $LesPointes $R "UneListeEnPlus" "milieu" $Interieur $Exterieur 
	unset LesAutresTagsPourAiguilles
	set Exterieur [expr $Exterieur - $Delta]
    }
}

proc CouleurDeLaZone Nom {
    Wup "Returns the color of Nom's zone in the dotplot"
    global LesCouleursDesZones

    set Milieu [expr ([Box $Nom debut]+[Box $Nom fin])/2]

    foreach DebutFinCouleur $LesCouleursDesZones {
	scan $DebutFinCouleur "%s %s %s" OldPosADN PosADN Couleur
	if {$OldPosADN <= $Milieu && $Milieu <= $PosADN} { return $Couleur }
    }
    return "white"    
}

proc RosaceDuDotPlot {K {R ""}} {
    Wup "Creates the wheel of the dotplot"
    global CurrentGenome
    global RosaceCourante
    global ParametresDuBoard
    global ParametresDuDotPlot
    global NePasDessinerLesZonesDansLaRosace

    set PI 3.14159

    if {$R==""} {
	if { ! [info exists RosaceCourante]} {
	    RscopeBoard $CurrentGenome
	}
	set R $RosaceCourante
    }

    set xFin    [set ParametresDuBoard($R,xFin)]
    set CentreX [set ParametresDuBoard($R,CentreX)]
    set CentreY [set ParametresDuBoard($R,CentreY)]
    set RayonMoyen     [set ParametresDuBoard($R,RayonMoyen)]
    set OffsetRayonMin [set ParametresDuBoard($R,OffsetRayonMin)]
    set OffsetRayonMax [set ParametresDuBoard($R,OffsetRayonMax)]

    incr ParametresDuBoard($R,IemeCouche)
    set IemeCouche     [set ParametresDuBoard($R,IemeCouche)]

    set MinX [set ParametresDuDotPlot($K,MinX)]
    set MaxX [set ParametresDuDotPlot($K,MaxX)]
    set MinY [set ParametresDuDotPlot($K,MinY)]
    set MaxY [set ParametresDuDotPlot($K,MaxY)]
    set LargeurMaxi [set ParametresDuDotPlot($K,LargeurMaxi)]
    set HauteurMaxi [set ParametresDuDotPlot($K,HauteurMaxi)]

    set LesDots [$K find withtag "Coeur"]
    set LesTagsDePivotPossibles {"ABY0254" "ABY0247" "ABY0248"}
    foreach TagDuPivot $LesTagsDePivotPossibles {
	set IdDuPivot [$K find withtag $TagDuPivot]
	if {$IdDuPivot > 0} { break }
    }
    scan [$K gettags $IdDuPivot] "%s %d" NomDuPivot PivotY
    set PositionEquivalenteDuPivot [expr ([Box $NomDuPivot debut]+[Box $NomDuPivot fin])/2]
    set CouleurDuPivot [CouleurDeLaZone $NomDuPivot]
    set OldPos 0
    foreach Dot $LesDots {
	scan [$K gettags $Dot] "%s %d" Nom Pos
	if {[info exists DejaVu($Pos)]} { continue }
	set CouleurFouR [$K itemcget $Dot -fill]
	if {$CouleurFouR=="red"} { 
	    set FouR "R"
	}
	if {$CouleurFouR=="blue"} { 
	    set FouR "F"
	}
	if {$CouleurFouR=="grey"} { 
	    set FouR "Z"
	}
	set Couleur [CouleurDeLaZone $Nom]
	if {$Couleur==$CouleurDuPivot} { set Couleur "black" }
	set HeureF  [Entre0Et2PI [expr ($Pos-$MinY)*2*$PI/($MaxY-$MinY)]]
	set HeureCF [Entre0Et2PI [expr $PivotY*2*$PI/($MaxY-$MinY)]]
	set HeureCA [Entre0Et2PI [expr $PositionEquivalenteDuPivot*2*$PI/($MaxX-$MinX)]]
	set HeureA  [Entre0Et2PI [expr $HeureCA+$HeureCF-$HeureF]]
	set Angle   [Entre0Et2PI [expr $PI/2-$HeureA]]
	lappend LesAngles $Angle
	set CouleurDe($Angle) $Couleur
	set OrientationDe($Angle) [expr $Pos < $OldPos]
	set DejaVu($Pos) 1
	set OldPos $Pos
    }
    set LesAnglesTries [lsort -real $LesAngles]
    set LesAngles2x [concat $LesAnglesTries $LesAnglesTries]
    set OuvertureFenetre 50
    set ScoreBascule 8
    set CombienDeDejaVus 0
    set LesCouleursLocales {}
    foreach Angle $LesAngles2x {
	set Couleur [set CouleurDe($Angle)]
	set FouR [set OrientationDe($Angle)]
	if { [llength $LesCouleursLocales] > $OuvertureFenetre } {
	    set OldCouleur [lindex $LesCouleursLocales 0]
	    set LesCouleursLocales [lreplace $LesCouleursLocales 0 0]
	}
	lappend LesCouleursLocales $Couleur

	if {[info exists Histo($Couleur)]} {
	    incr Histo($Couleur) 1
	} else {
	    set  Histo($Couleur) 1
	}
	if {[info exists OldCouleur] && [incr Histo($OldCouleur) -1] == 0} { unset Histo($OldCouleur) }
	set MeilleurScore -1
	set CumulFouR 0
	foreach {C ValHisto} [array get Histo] {
	    if {$FouR > 0} { incr CumulFouR } else { incr CumulFouR -1 }
	    set N $ValHisto
	    if {$N>$MeilleurScore} {
		set MeilleurScore $N
		set MeilleureCouleur $C
	    }
	}

	if {[info exists DejaVu($Angle)]} {
	    Espionne "DejaVu $Angle"
	    if {[incr CombienDeDejaVus] > 10} { break }
	    continue
	}
	set DejaVu($Angle) 1
	
	if {$MeilleurScore > $ScoreBascule} {
	    if {$CumulFouR < 0} {		
		lappend LesPointes "Reverse_$Angle"
	    } else {
		lappend LesPointes $Angle
	    }
	    lappend LesPointes $MeilleureCouleur
	}
    } 
    set Rayon [expr $RayonMoyen + $OffsetRayonMax + $IemeCouche*$OffsetRayonMax*0.5]

    ArcLaListe $LesPointes $R "UneListeEnPlus" "angle" $Rayon $Rayon
    return $R
}

proc DetruireLaRosace w {
    Wup "Kills and erase the rosace from the currentlist"
    global RosaceCourante
    global ParametresDuBoard
    global LesKanvasOuverts
    global KanvaCourant

    set K $w.canvas

    destroy $w

    set LesRosacesEnCours [set ParametresDuBoard(RosacesEnCours)]

    set i [lsearch $LesRosacesEnCours $K]
    if {$i >= 0} {
	set LesRoacesEnCours [lreplace LesRosacesEnCours $i $i]
	set ParametresDuBoard(RosacesEnCours) $LesRosacesEnCours
	if {[info exists RosaceCourante] && $RosaceCourante==$K} {
	    if {[llength $LesRosacesEnCours] > 0} {
		set RosaceCourante [lindex $LesRosacesEnCours end]
	    }
	}
    }
    set i [lsearch $LesKanvasOuverts $K]
    if {$i >= 0} {
	set LesKanvasOuverts [lreplace LesKanvasOuverts $i $i]
	if {[info exists KanvaCourant] && $KanvaCourant==$K} {
	    if {[llength $LesKanvasOuverts] > 0} {
		set KanvaCourant [lindex $LesKanvasOuverts end]
	    }
	}
    }
    return
}

proc TextePourRosace {Action K {ListeOuFichier {}}} {
    global ParametresDuBoard

    set CentreX [set ParametresDuBoard($K,CentreX)]
    set CentreY [set ParametresDuBoard($K,CentreY)]

    if {$Action == "Add"} {
	set Liste $ListeOuFichier
	if {$Liste == {}} {
	    set Texte [Entre]
	    if {$Texte == ""} { return }
	    $K create text $CentreX $CentreY -text "$Texte" -font {Courier 10} \
		    -tags [list "Etiquette" $Texte]
	    return $Texte
	} 
	if {$Liste != {}} {
	    set DefautX $CentreX
	    set DefautY $CentreY
	    foreach Ligne $Liste {
		set X [incr DefautX 10]
		set Y [incr DefautY 10]	    
		scan $Ligne "%s %s %s" Texte X Y
		$K create text $X $Y -text "$Texte"  -font {Courier 10} \
			-tags [list "Etiquette" $Texte]
	    }
	}
    }
    if {$Action == "AddFromList"} {
	if {$ListeOuFichier == ""} {
	    set Fichier [ButineArborescence]
	    if {$Fichier == ""} { return "" }
	    foreach Ligne [LesLignesDuFichier $Fichier] {
		set Texte "Bidon"
		scan $Ligne "%s" Texte
		lappend Liste $Texte
	    }
	} else {
	    set Liste $ListeOuFichier
	}
	return [TextePourRosace "Add" $K $Liste]
    }
}

proc LaFigureAutomatique2002 {} {
    global RepertoireDuGenome
    global NePasDessinerLesZonesDansLaRosace
    global ParametresDuBoard
    
    set R [RosaceDesPIOs            "EnPlus" "" {phor pfur tmar bsub}]
    set R [RosaceDesTwoGenesCluster "EnPlus" "" {phor pfur tmar bsub}]
    RecoloreLesBoites ClassesFonctionnelles $R
}

proc LaFigureAutomatiqueMsFinal {} {
    global RepertoireDuGenome
    global NePasDessinerLesZonesDansLaRosace
    global ParametresDuBoard
    
    DecalageAngulaireRosace

#   set R [RosaceDesPIOs            "EnPlus" "" {mtub mlep}]
    set R [RosaceDesTwoGenesCluster "EnPlus" "" {mtub mlep}]
    set R [RosaceDesGCSkew          "EnPlus" "" 0.75 0.80]
    RecoloreLesBoites "NombreDeCopainsDansBlast" $R
}

proc LaFigureAutomatique {} {
    global RepertoireDuGenome
    global NePasDessinerLesZonesDansLaRosace
    global ParametresDuBoard
    
    Wup "Draws a rosace with org1 and org2 ... the dotplots have to be made before."

    NousAllonsAuBoulot "$RepertoireDuGenome/figure" 

    set K [DotPlot genomes phor Proches]
#    RestaureUneDemarcation $K "org1.dp"

#    set NePasDessinerLesZonesDansLaRosace 1
    set R [DemarqueLaRosace $K]
#    catch {unset NePasDessinerLesZonesDansLaRosace}

#perdu    set ParametresDuBoard($R,IemeCouche) 1
#    set R [RosaceDuDotPlot $K]

    set K [DotPlot genomes pfur Proches]
#    RestaureUneDemarcation $K "org2.dp"

    set ParametresDuBoard($R,IemeCouche) 0
#perdu    set R [DemarqueLaRosace $K]

    set ParametresDuBoard($R,IemeCouche) 2
#    set R [RosaceDuDotPlot $K]

    RosaceDesPIOs "EnPlus" "" {phor pfur tmar bsub} 
    RosaceDesTwoGenesCluster "EnPlus" "" {phor pfur tmar bsub}
    
    OnRevientDuBoulot
}

proc GereLesZoneEtiquettee {K x y ItemType Action} {
    global DernierXDeZoneEtiquettee DernierYDeZoneEtiquettee
    global DernierStartDeZoneEtiquettee
    global ZoneEtiquetteeTouchee
    global LesCouleursDeZoneEtiquettee
    global LesTaillesDeZoneEtiquettee
    global CouleurDuFond
    global ParametresDuBoard

    set PI 3.14159

    set X [$K canvasx $x]
    set Y [$K canvasy $y]

    set xFin    [set ParametresDuBoard($K,xFin)]
    set CentreX [set ParametresDuBoard($K,CentreX)]
    set CentreY [set ParametresDuBoard($K,CentreY)]


    if { ! [info exists LesCouleursDeZoneEtiquettee] } {
	set LesCouleursDeZoneEtiquettee {}
	lappend LesCouleursDeZoneEtiquettee "black"
	lappend LesCouleursDeZoneEtiquettee "grey"
	lappend LesCouleursDeZoneEtiquettee "white"
	lappend LesCouleursDeZoneEtiquettee "blue"
	lappend LesCouleursDeZoneEtiquettee "lightblue"
	lappend LesCouleursDeZoneEtiquettee "yellow"
	lappend LesCouleursDeZoneEtiquettee "green"
	lappend LesCouleursDeZoneEtiquettee "orange"
	lappend LesCouleursDeZoneEtiquettee "red"
	lappend LesCouleursDeZoneEtiquettee "purple"
	lappend LesCouleursDeZoneEtiquettee $CouleurDuFond

	set LesTaillesDeZoneEtiquettee {"Raise" "Lower" "Extent" "Copy" "Other" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20}
    }

    if {$Action == "Motion"} {
	if { $ItemType=="arc" } {
	    set DeltaX [expr $x-$DernierXDeZoneEtiquettee]
	    set DeltaY [expr $y-$DernierYDeZoneEtiquettee]
	    set DernierStartDeZoneEtiquettee [expr $DernierStartDeZoneEtiquettee + $DeltaX]
	    $K itemconfigure $ZoneEtiquetteeTouchee -start $DernierStartDeZoneEtiquettee
	} else {
	    $K move $ZoneEtiquetteeTouchee [expr $x-$DernierXDeZoneEtiquettee] [expr $y-$DernierYDeZoneEtiquettee]
	}
	set DernierXDeZoneEtiquettee $x
	set DernierYDeZoneEtiquettee $y
	return
    }

    set ZoneEtiquetteeTouchee [$K find withtag current]
    if {$Action == "Point"} {
	set ZoneEtiquetteeTouchee [$K find withtag current]
	set DernierXDeZoneEtiquettee $x
	set DernierYDeZoneEtiquettee $y
	if { $ItemType=="arc"} {
	    set DernierStartDeZoneEtiquettee [$K itemcget $ZoneEtiquetteeTouchee -start]
	}
	return
    }
    if {$Action == "Erase"} {
	if { ! [OuiOuNon "Do you really want to erase this $ItemType"]} {
	    return 0
	}
	$K delete $ZoneEtiquetteeTouchee
	return 1
    }
    if {$Action == "ModifCouleur"} {
	set Couleur [ChoixParmi \
		[concat $LesCouleursDeZoneEtiquettee "NewColor"] \
		[concat $LesCouleursDeZoneEtiquettee "white"]]
	if {$Couleur == ""} { return "" }
	if {$Couleur == "NewColor"} {
	    set Couleur [PaletteDeCouleurs]
	    if {$Couleur == ""} { return "" }
	    lappend LesCouleursDeZoneEtiquettee $Couleur
	}
	if { $ItemType=="polygone"} {
	    $K itemconfigure $ZoneEtiquetteeTouchee -fill $Couleur
	    $K itemconfigure $ZoneEtiquetteeTouchee -outline $Couleur
	    return $Couleur
	}
	if { $ItemType=="arc"} {
	    $K itemconfigure $ZoneEtiquetteeTouchee -outline $Couleur
	    return $Couleur
	}
	if { $ItemType=="text" || $ItemType=="line"} {
	    $K itemconfigure $ZoneEtiquetteeTouchee -fill $Couleur
	    return $Couleur
	}
    }
    if {$Action == "ModifTaille"} {
	set Taille [ChoixParmi $LesTaillesDeZoneEtiquettee]
	if {$Taille == ""} { return "" }
	if {$ItemType == "arc" && $Taille == "Copy"} {
	    set Extent [$K itemcget $ZoneEtiquetteeTouchee -extent]
	    $K itemconfigure $ZoneEtiquetteeTouchee -extent [expr $Extent*[Entre 0.9]]
	    return
	}
	if {$ItemType == "arc" && $Taille == "Extent"} {
	    set Extent [$K itemcget $ZoneEtiquetteeTouchee -extent]
	    $K itemconfigure $ZoneEtiquetteeTouchee -extent [expr $Extent*[Entre 0.9]]
	    return
	}
	if {$Taille == "Raise"} {
	    $K raise $ZoneEtiquetteeTouchee
	    return "Raise"
	}
	if {$Taille == "Lower"} {
	    $K raise $ZoneEtiquetteeTouchee
	    return "Lower"
	}
	if {$ItemType == "line" && $Taille == "Arrow"} {
	    set AvAr [$K itemcget $ZoneEtiquetteeTouchee -arrow]
	    if {$AvAr=="first"} { set AvAr "last" } else { set AvAr "first" }
	    $K itemconfigure $ZoneEtiquetteeTouchee -arrow $AvAr
	    return 
	}
	if {$Taille == "Other"} {
	    set Taille [Entre 21]
	    if {$Taille == ""} { return "" }
	    lappend LesTaillesDeZoneEtiquettee $Taille
	}
	if { $ItemType=="arc" || $ItemType=="line" } {
	    $K itemconfigure $ZoneEtiquetteeTouchee -width $Taille
	    return $Taille
	}
	if { $ItemType=="text"} {
	    $K itemconfigure $ZoneEtiquetteeTouchee -font [list Courier $Taille]
	    return $Taille
	}
    }
    if {$Action == "ModifTexte"} {
	set Texte [Entre]
	if {$Texte == ""} { return "" }
	if { $ItemType=="text"} {
	    $K itemconfigure $ZoneEtiquetteeTouchee -text $Texte
	    return $Texte
	}
    }
}

proc DetruireLeDotPlot w {
    global LesDotPlotCourants 

    set K "$w.grid.canva"

    if { ! [OuiOuNon "Do you really want to dismiss this Dotplot ?"]} { return }

    set i [lsearch $LesDotPlotCourants $K]
    set LesDotPlotCourants [lreplace $LesDotPlotCourants $i $i]
    destroy $w
    return 1
}

proc DemarcationEnPositionDansFichier {K VouH {Fichier ""}} {
    if {$Fichier == ""} {
	set Fichier [ButineArborescence]
	if {$Fichier == ""} { return }
    }
    foreach Ligne [LesLignesDuFichier $Fichier] {
	if {[regexp {"#Don't remove this line it marks the end."} $Ligne]} { break }
	if {[regexp {^\#} $Ligne]} { continue }
	if { ! [regexp -nocase {[a-z0-9]} $Ligne]} { continue }
	set Y 100
	set Etiq "NoValue"
	set n [scan $Ligne "%s %s %s" NomOuPosition Y Etiq]
	if {$n<1} {
	    FaireLire "$Ligne\nis not correct. I'll skip it."
	}
	DemarcationEnPosition $K $VouH $NomOuPosition $Y $Etiq 
    }
}

proc DemarcationEnPosition {K VouH {NomOuPosition ""} {Y ""} {Etiquette ""}} {
    global ParametresDuDotPlot
    global ListeDeBoites
    global xFinLocal

    if { ! [info exists ListeDeBoites]} { ChargeLesBoites }

    if { ! [info exists xFinLocal]} {
	scan [BoundingBox $ListeDeBoites] "%d %d" xDebut xFinLocal
    }
    set xFin $xFinLocal

    set MinX [set ParametresDuDotPlot($K,MinX)]
    set MaxX [set ParametresDuDotPlot($K,MaxX)]
    set MinY [set ParametresDuDotPlot($K,MinY)]
    set MaxY [set ParametresDuDotPlot($K,MaxY)]
    set LargeurMaxi [set ParametresDuDotPlot($K,LargeurMaxi)]
    set HauteurMaxi [set ParametresDuDotPlot($K,HauteurMaxi)]

    if {$NomOuPosition == ""} {
	set NomOuPosition [Entre ""]
    }
    if {$NomOuPosition == ""} { return "" }

    set Nom "Manual"
    if {[YaPABouTROUouTRNAouARNenDebutDe $NomOuPosition]} {
	regsub {\-\+} $NomOuPosition "" Nom
	if {[Box $Nom nom]!=$Nom} {
	    FaireLire "$NomOuPosition not known"
	    return
	}
	if {[regexp {\-} $NomOuPosition]} {
	    set Position [Box $Nom debut]
	} elseif {[regexp {\+} $NomOuPosition]} {
	    set Position [Box $Nom fin]
	} else {
	    set Position [expr ([Box $Nom debut]+[Box $Nom fin])/2]
	}
	if {$Etiquette == ""} {
	    set Etiquette $Nom
	}
	set X "SurADN_$Position"
    } else {
	set X $NomOuPosition
    }
    Demarcation $VouH $K $X $Y $Etiquette
}

proc CleanRosace {K Quoi} {
    global ParametresDuBoard

    if {$Quoi=="Textes"}    { set LesTags [list "Txt"] }
    if {$Quoi=="Aiguilles"} { set LesTags [list "Aiguille"] }
    if {$Quoi=="Zones"}     {
	set LesTags [list "Zone" "Etiquette"]
    }
    catch {unset ParametresDuBoard($K,IemeCouche)} 
    
    foreach Tag $LesTags {
	foreach Id [$K find withtag $Tag] {
	    $K delete $Id
	}
    }
}

proc EntreMinEtMax {Angle m M} {
    set D [expr $M-$m]
    while {$Angle < $m} { set Angle [expr $Angle + $D] }
    while {$Angle >= $M} { set Angle [expr $Angle - $D] }
    return $Angle
}

proc Entre0Et360 Angle {
    while {$Angle < 0} { set Angle [expr $Angle + 360] }
    while {$Angle >= 360} { set Angle [expr $Angle - 360] }
    return $Angle
}

proc Entre0Et2PI Angle {
    set PI 3.14159
    while {$Angle < 0} { set Angle [expr $Angle + 2*$PI] }
    while {$Angle >= 2*$PI} { set Angle [expr $Angle - 2*$PI] }
    return $Angle
}

proc SauveLaDemarcation {K {NomDuFichier ""}} {
    set LesNoms [Demarcation "lv" $K]
    set LesXs   [Demarcation "av" $K]
    set LesEtiq [Demarcation "ev" $K]

    if {$NomDuFichier == ""} {
	set NomDuFichier [FichierPourSaveAs]
    }
    if {$NomDuFichier == ""} { return "" }

    foreach Nom $LesNoms X $LesXs Etiq $LesEtiq {
	lappend Sortie "$Nom $X $Etiq"
    }
    lappend $Sortie "#Don't remove this line it marks the end."
    return [SauveLesLignes $Sortie dans $NomDuFichier]
}

proc RestaureUneDemarcation {K {NomDuFichier ""}} {
    Demarcation "dallv" $K
    return [AppendUneDemarcation $K $NomDuFichier]
}
    
proc AppendUneDemarcation {K {NomDuFichier ""}} {

    if {$NomDuFichier == ""} {
	set NomDuFichier [ButineArborescence]
    }
    if {$NomDuFichier == ""} { return "" }

    set Y 100
    set Etiquette "NoValue"
    foreach Ligne [LesLignesDuFichier $NomDuFichier] {
	if {[regexp {"#Don't remove this line it marks the end."} $Ligne]} { break }
	if {[regexp {^\#} $Ligne]} { continue }
	if { ! [regexp -nocase {[a-z0-9]} $Ligne]} { continue }
	set n [scan $Ligne "%s %s %s" Nom Y Etiq]
	DemarcationEnPosition $K "v" $Nom $Y $Etiq
    }
    return $NomDuFichier
}

proc MiseAJourDesEtiquettes K {
    global LesDemarcationsVerticales
    global LesDemarcationsHorizontales
    global LesAbscissesVerticales
    global LesAbscissesHorizontales
    global LesEtiquettesVerticales
    global LesEtiquettesHorizontales

    foreach Id [$K find withtag "Etiquette"] {
	set SesTags [$K gettags $Id]
	set Position [lindex $SesTags 1]
	set i [lsearch [set LesAbscissesVerticales($K)] $Position]
	set Etiquette [lindex [set LesEtiquettesVerticales($K)] $i]
	set SesTags [lreplace $SesTags 5 5 $Etiquette]
	$K itemconfigure $Id -text $Etiquette -tags $SesTags
    }
}

proc NouveauNomDeZoneDeDemarcation K {
    global NomDeZoneDeDemarcation NumeroDeZoneDeDemarcation

    if { ! [info exists NomDeZoneDeDemarcation($K)]} {
	set NomDeZoneDeDemarcation($K) "Zone"
	set NumeroDeZoneDeDemarcation($K) "0"
    }
    return [set NomDeZoneDeDemarcation($K)][incr NumeroDeZoneDeDemarcation($K)]
}

proc TrieLesListesDeDemarcation {K VouH} {
    global LesDemarcationsVerticales
    global LesDemarcationsHorizontales
    global LesAbscissesVerticales
    global LesAbscissesHorizontales
    global LesEtiquettesVerticales
    global LesEtiquettesHorizontales

    if {$VouH=="v"} {
	set ListeA [set LesAbscissesVerticales($K)]
	set ListeB [set LesDemarcationsVerticales($K)]
	set ListeC [set LesEtiquettesVerticales($K)]
    }
    if {$VouH=="h"} {
	set ListeA [set LesAbscissesHorizontales($K)]
	set ListeB [set LesDemarcationsHorizontales($K)]
	set ListeC [set LesEtiquettesHorizontales($K)]
    }

    foreach A $ListeA B $ListeB C $ListeC {
	set Bdu($A) $B
	set Cdu($A) $C
    }
    set ListeATriee [lsort -integer $ListeA]

    foreach A $ListeATriee {
	lappend ListeBTriee [set Bdu($A)]
	lappend ListeCTriee [set Cdu($A)]
    }

    if {$VouH=="v"} {
	set LesAbscissesVerticales($K)    $ListeATriee
	set LesDemarcationsVerticales($K) $ListeBTriee
	set LesEtiquettesVerticales($K)   $ListeCTriee
	return
    } 
    if {$VouH=="h"} {
	set LesAbscissesHorizontales($K)    $ListeATriee
	set LesDemarcationsHorizontales($K) $ListeBTriee
	set LesEtiquettesHorizontales($K)   $ListeCTriee
	return
    } 
}

proc RayonDansRosace {R X Y {CentreX ""} {CentreY ""}} {
    global ParametresDuBoard

    if {$CentreX == ""} {
	set CentreX [set ParametresDuBoard($R,CentreX)]
	set CentreY [set ParametresDuBoard($R,CentreY)]
    }
    if {$R == "CoordonneesVraies"} {
	set xVrai $X
	set yVrai $Y
    } else {
	set xVrai [$R canvasx $X]
	set yVrai [$R canvasy $Y]
    }

    set x [expr $xVrai-$CentreX] 
    set y [expr $yVrai-$CentreY]

    set Rayon [expr sqrt($x*$x+$y*$y)]

    return $Rayon
}

proc HeureDansRosace {R X {Y ""} {CentreX ""} {CentreY ""}} {
    set PI 3.14159
    return [Entre0Et2PI [expr $PI/2+[AngleDansRosace $R $X $Y $CentreX $CentreY] ]]
} 

proc AngleDansRosace {R X {Y ""} {CentreX ""} {CentreY ""}} {
    global ParametresDuBoard

    set PI 3.14159

    if {[regexp -nocase {[a-z]} $X]} {
	set Nom $X
	set PosADN [Milieu $Nom]
	
	set Heure [expr $PosADN*2*$PI/[LongueurADN]]
	set Angle [expr  -$PI/2 - $Heure]]
	set Angle [expr $Angle + [DecalageAngulaireRosace]]
	set Angle [Entre0Et2PI [expr  -$PI/2 - $Heure]]
	return $Angle
    }

    if {$CentreX == ""} {
	set CentreX [set ParametresDuBoard($R,CentreX)]
	set CentreY [set ParametresDuBoard($R,CentreY)]
    }
    if {$R == "CoordonneesVraies"} {
	set xVrai $X
	set yVrai $Y
    } else {
	set xVrai [$R canvasx $X]
	set yVrai [$R canvasy $Y]
    }

    set x [expr $xVrai-$CentreX]
    set y [expr $yVrai-$CentreY]

    if {[expr abs($x) < 1] && [expr abs($y) < 1]} { return 0.0 }
    if {[expr abs($x) < 1] && [expr $y > 0]} {
	set Angle [expr $PI/2]
    } elseif {[expr abs($x) < 1] && [expr $y < 0]} {
	set Angle [expr 3*$PI/2]
    } else {
	set Angle [expr atan($y*1.0/$x)]
	if {$x<0} { set Angle [expr $Angle + $PI] }
	set Angle [expr $Angle + [DecalageAngulaireRosace]]
	set Angle [Entre0Et2PI $Angle]
    }
    return $Angle
}

proc DuPlotteCourant {K X Y Qui} {
    set LesIds [$K find withtag current]
    foreach Id $LesIds {
	set Moi [lindex [$K gettags $Id] 0]
	set Toi [lindex [$K gettags $Id] 1]
	if {[regexp -nocase {[a-z]} $Toi]} { continue }
	if {$Qui == "PAB"} {
	    return $Moi
	} else {
	    return $Toi
	}
    }
}

proc DemarqueLeDotPlot {K {D ""}} {
    global RosaceCourante
    global NePasEffacerLesRepereBox
    global CurrentGenome
    global LesDotPlotCourants 

    if {$D==""} {
	if {[llength $LesDotPlotCourants]==1} {
	    FaireLire "Please, open an other DotPlot."
	    return 
	}
	set i [lsearch $LesDotPlotCourants $K]
	set LesAutres [lreplace $LesDotPlotCourants $i $i]
	set D [ChoixParmi $LesAutres]
	if {$D==""} { return }
    }

    set LesNoms [Demarcation "lv" $K]
    set LesXs   [Demarcation "av" $K]
    set LesEtiq [Demarcation "ev" $K]

    foreach Nom $LesNoms X $LesXs Etiq $LesEtiq {
	Demarcation v $D $X $Nom $Etiq
    }
}

proc DemarqueLaRosace {K {R ""}} {
    global RosaceCourante
    global NePasEffacerLesRepereBox
    global CurrentGenome
    global ParametresDuBoard
    global ParametresDuDotPlot
    global CouleurArcDeZone
    global LesCouleursDesZones
    global NePasDessinerLesZonesDansLaRosace

    set MinX [set ParametresDuDotPlot($K,MinX)]
    set MaxX [set ParametresDuDotPlot($K,MaxX)]
    set MinY [set ParametresDuDotPlot($K,MinY)]
    set MaxY [set ParametresDuDotPlot($K,MaxY)]
    set LargeurMaxi [set ParametresDuDotPlot($K,LargeurMaxi)]
    set HauteurMaxi [set ParametresDuDotPlot($K,HauteurMaxi)]


    if {$R==""} {
	if { ! [info exists RosaceCourante]} {
	    RscopeBoard $CurrentGenome
	}
	set R $RosaceCourante
    }

    if { ! [info exists ParametresDuBoard($R,IemeCouche)]} {
	set ParametresDuBoard($R,IemeCouche) 0
    }
    incr ParametresDuBoard($R,IemeCouche)
    set PI 3.14159

    set xFin           [set ParametresDuBoard($R,xFin)]
    set CentreX        [set ParametresDuBoard($R,CentreX)]
    set CentreY        [set ParametresDuBoard($R,CentreY)]
    set RayonMoyen     [set ParametresDuBoard($R,RayonMoyen)]
    set OffsetRayonMin [set ParametresDuBoard($R,OffsetRayonMin)]
    set OffsetRayonMax [set ParametresDuBoard($R,OffsetRayonMax)]
    set IemeCouche     [set ParametresDuBoard($R,IemeCouche)]

    set RayonInt [expr $RayonMoyen + $OffsetRayonMax + $IemeCouche*$OffsetRayonMax*0.5]
    set RayonExt $RayonInt

    set LesNoms [Demarcation "lv" $K]
    set LesXs   [Demarcation "av" $K]
    set LesEtiq [Demarcation "ev" $K]

    set RayonCourant $RayonExt
    set NePasEffacerLesRepereBox 1
    set LesCouleursDesZones {}
    foreach Nom $LesNoms X $LesXs Etiq $LesEtiq {
	set MaPos $X
	set Angle [Entre0Et2PI [expr $PI/2-$MaPos*2*$PI/$xFin]]
	Espionne "$Nom $X $Etiq $MaPos $Angle"
	if {[regexp -nocase "vide" $Etiq]} { set NonVide 0 } else { set NonVide 1 }
	if { 0 && $RayonCourant == $RayonInt } {
	    set RayonCourant $RayonExt
	} else {
	    set RayonCourant $RayonInt
	}
	set PosX [PositionCanvaActuelleX $R [expr $CentreX+$RayonCourant*cos($Angle)]]
	set PosY [PositionCanvaActuelleY $R [expr $CentreY-$RayonCourant*sin($Angle)]]
	
#	RepereBox "Nom: $Nom" $R "SansInforme"
	if {[info exists OldPosX]} {
	    set OldHeure [Entre0Et2PI [expr $PI/2-$OldAngle]]
	    set    Heure [Entre0Et2PI [expr $PI/2-$Angle]]
	    set HeureTexte   [Entre0Et2PI [expr ($OldHeure+$Heure)/2]]
	    set AngleCouleur [Entre0Et2PI [expr $HeureTexte+2*$PI/12]]
	    set AngleTexte   [Entre0Et2PI [expr $PI/2-$HeureTexte]]
	    set TextePosX [expr $CentreX+$RayonCourant*0.97*cos($AngleTexte)]
	    set TextePosY [expr $CentreY-$RayonCourant*0.97*sin($AngleTexte)]
	    if {$NonVide} {
#		set CouleurArcDeZone [Nuance $AngleCouleur/(2*$PI) 0.0 0.987]
		set CouleurArcDeZone  [CouleurExquiseDeLaZone $Etiq "VraieCouleur"]
		set CouleurEtiquettee [CouleurExquiseDeLaZone $Etiq ""]
	    } else {
		set CouleurArcDeZone "VIDE"
		set CouleurEtiquettee "VIDE"
	    }
	    set OldPosADN [expr $OldHeure*$xFin/(2*$PI)]
	    set PosADN [expr $Heure*$xFin/(2*$PI)]
	    lappend LesCouleursDesZones "$OldPosADN $PosADN $CouleurEtiquettee"
	    if {$NonVide} {
		set MemoCouleurArcDeZone $CouleurArcDeZone
		set CouleurArcDeZone "black"
		set Delta [expr [LongueurADN]/977]
		if { ! [info exists NePasDessinerLesZonesDansLaRosace]} {
#		    set IdP [ShowNucRosace $R $OldPosX $OldPosY "Point"  $OldMaPos]
#		    set IdM [ShowNucRosace $R    $PosX    $PosY "Motion" [expr $MaPos]]
		    set CouleurArcDeZone $MemoCouleurArcDeZone
		    set IdP [ShowNucRosace $R $OldPosX $OldPosY "Point"  [expr $OldMaPos+$Delta]]
		    set IdM [ShowNucRosace $R    $PosX    $PosY "Motion" [expr $MaPos-$Delta]]
		    $R addtag "Zone" withtag $IdM
		    FlecheSurArc $R $IdM "F"
		    $R create text $TextePosX $TextePosY \
			    -text "$Etiq" \
			    -anchor "c" \
			    -font {Courier 10} \
			    -tags [list "$Etiq" "Etiquette"]
		}
	    }
	    unset CouleurArcDeZone
	}

	BindLaRosace $R

	set OldMaPos $MaPos
	set OldPosX $PosX
	set OldPosY $PosY
	set OldAngle $Angle
    }
    catch {unset NePasEffacerLesRepereBox}
    return $R
}

proc Demarcation {Action K {X ""} {Y ""} {E ""}} {
    Wup "X peut etre un x de clic, une position ADN ou un Nom"
    global LesDemarcationsVerticales
    global LesDemarcationsHorizontales
    global LesAbscissesVerticales
    global LesAbscissesHorizontales
    global LesEtiquettesVerticales
    global LesEtiquettesHorizontales
    global ScrollRectangleOriginal IdScrollRectangle
    global NePasDessinerLesZonesDansLaRosace
    JeMeSignale

    scan "[$K coords [set IdScrollRectangle($K)]]" "%f %f %f %f" Gauche Haut Droite Bas

    if {$X!=""} {
	if {[regexp "SurADN_" $X]} {
	    set Nom $X
	    regsub "SurADN_" $X ""  XPositionADN
	    set XActuel [PositionCanvaActuelleX $K $XPositionADN]	    
	} else {
	    scan [$K gettags [$K find withtag current]] "%s %s %s" Nom Toi Coeur 
	    set XPositionADN [Milieu $Nom]
	    set XActuel [$K canvasx $X]
	}
	set XduTexte $XActuel
    }


    if {$Y!=""} {
	if {[regexp "SurADN_" $Y] || [regexp "SurADN_" $X]} {
	    regsub "SurADN_" $Y ""  YPositionADN
	    set YActuel [PositionCanvaActuelleY $K $YPositionADN]
	} else {
	    scan [$K gettags [$K find withtag current]] "%s %s %s" Nom Toi Coeur 
	    set YPositionADN $Toi
	    set YActuel [$K canvasy $Y]
	}
	set YduTexte $YActuel
    }

    if {[regexp "_ifyes" $Action]} {
	if { ! [OuiOuNon "Do you really want to erase the lines ?"]} { return }
    }
    regsub  "_ifyes" $Action "" Action

    if {$Action == "dall"} {
	set LesIds [$K find withtag "Ligne"]
	foreach Id $LesIds {
	    $K delete $Id
	}
	set LesIds [$K find withtag "Etiquette"]
	foreach Id $LesIds {
	    $K delete $Id
	}
	set LesDemarcationsVerticales($K)   {}
	set LesAbscissesVerticales($K)      {}
	set LesEtiquettesVerticales($K)     {}
	set LesDemarcationsHorizontales($K) {}
	set LesAbscissesHorizontales($K)    {}
	set LesEtiquettesHorizontales($K)   {}
	return
    }
    if {$Action == "dallv"} {
	set LesIds [$K find withtag "verticale"]
	foreach Id $LesIds {
	    $K delete $Id
	}
	set LesDemarcationsVerticales($K) {}
	set LesAbscissesVerticales($K) {}
	set LesEtiquettesVerticales($K)     {}
	return
    }
    if {$Action == "dallh"} {
	set LesIds [$K find withtag "horizontale"]
	foreach Id $LesIds {
	    $K delete $Id
	}
	set LesDemarcationsHorizontales($K) {}
	set LesAbscissesHorizontales($K) {}
	set LesEtiquettesHorizontales($K)   {}
	return
    }

    if {$Action == "d"} {
	set LesIds [$K find withtag current]
	foreach Id $LesIds {
	    set VouH [lindex [$K gettags $Id] 3]
	    set NomOuNum [lindex [$K gettags $Id] 0]
	    if {$VouH == "verticale"} {
		set i [lsearch [set LesDemarcationsVerticales($K)] $NomOuNum]
		if { $i < 0 } { continue }
		set LesDemarcationsVerticales($K) [lreplace [set LesDemarcationsVerticales($K)] $i $i]
		set LesAbscissesVerticales($K)    [lreplace [set LesAbscissesVerticales($K)]    $i $i]
		set LesEtiquettesVerticales($K)   [lreplace [set LesEtiquettesVerticales($K)]   $i $i]
	    }
	    if {$VouH == "horizontale"} {
		set i [lsearch $LesDemarcationsHorizontales($K) $NomOuNum]
		if { $i < 0 } { continue }
		set LesDemarcationsHorizontales($K) [lreplace [set LesDemarcationsHorizontales($K)] $i $i]
		set LesAbscissesHorizontales($K)    [lreplace [set LesAbscissesHorizontales($K)]   $i $i]
		set LesEtiquettesHorizontales($K)   [lreplace [set LesEtiquettesHorizontales($K)]  $i $i]
	    }
	    $K delete $Id
	}
	return
    }
    if {$Action == "rev"} {
	set Texte [EntreTexte [join [set LesEtiquettesVerticales($K)] "\n"]]
	if {$Texte == ""} { return }
	regsub "\n$" $Texte "" Texte
	set LesNouvellesEtiquettes [split $Texte "\n"]
	if {[llength $LesNouvellesEtiquettes] != [llength [set LesEtiquettesVerticales($K)]]} {
	    FaireLire "Sorry, you lose or add a label. I can't accept your modification"
	}
	set LesEtiquettesVerticales($K) $LesNouvellesEtiquettes
	MiseAJourDesEtiquettes $K
	return $LesNouvellesEtiquettes
    }
    if {$Action == "e"} {
	set LesIds [$K find withtag current]
	foreach Id $LesIds {
	    set VouH [lindex [$K gettags $Id] 3]
	    set NomOuNum [lindex [$K gettags $Id] 0]
	    if {$VouH == "verticale"} {
		set i [lsearch [set LesDemarcationsVerticales($K)] $NomOuNum]
		if { $i < 0 } { continue }
		set EtiquetteVerticale [lindex LesEtiquettesVerticales($K) $i]
		set NouvelleEtiquette [Entre $EtiquetteVerticale]
		if {$NouvelleEtiquette==""} { return }
		set LesEtiquettesVerticales($K) [lreplace $LesEtiquettesVerticales($K) $i $i $NouvelleEtiquette]
	    }
	    if {$VouH == "horizontale"} {
		set i [lsearch $LesDemarcationsHorizontales($K) $NomOuNum]
		if { $i < 0 } { continue }
		set EtiquetteHorizontale [lindex LesEtiquettesHorizontales($K) $i]
		set NouvelleEtiquette [Entre $EtiquetteHorizontale]
		if {$NouvelleEtiquette==""} { return }
		set LesEtiquettesHorizontales($K) [lreplace $LesEtiquettesHorizontales($K) $i $i $NouvelleEtiquette]
	    }
	}
	return
    }
    
    if {$Action == "lv"} {
	if {[info exists LesDemarcationsVerticales($K)]} {
	    return [set LesDemarcationsVerticales($K)]
	} else {
	    return {} 
	}
    }
    if {$Action == "lh"} {
	if {[info exists LesDemarcationsHorizontales($K)]} {
	    return [set LesDemarcationsHorizontales($K)]
	} else {
	    return {} 
	}
    }
    if {$Action == "av"} {
	if {[info exists LesDemarcationsVerticales($K)]} {
	    return [set LesAbscissesVerticales($K)]
	} else {
	    return {} 
	}
    }
    if {$Action == "ah"} {
	if {[info exists LesDemarcationsHorizontales($K)]} {
	    return [set LesAbscissesHorizontales($K)]
	} else {
	    return {} 
	}
    }
    if {$Action == "ev"} {
	if {[info exists LesDemarcationsVerticales($K)]} {
	    return [set LesEtiquettesVerticales($K)]
	} else {
	    return {} 
	}
    }
    if {$Action == "eh"} {
	if {[info exists LesDemarcationsHorizontales($K)]} {
	    return [set LesEtiquettesHorizontales($K)]
	} else {
	    return {} 
	}
    }

    if {$Action == "v" || $Action == "vh"} {
	if {$Action=="vh"} {
	    set Haut [expr $YActuel-5]
	    set Bas  [expr $YActuel+5]
	}
	lappend LesDemarcationsVerticales($K) $Nom
	lappend LesAbscissesVerticales($K)    $XPositionADN
	if {$E == ""} {
	    set Etiquette [NouveauNomDeZoneDeDemarcation $K]
	} else {
	    set Etiquette $E
	}
	lappend LesEtiquettesVerticales($K) $Etiquette
	TrieLesListesDeDemarcation $K "v"
	$K create line $XActuel $Haut $XActuel $Bas -tags [list $Nom $X "Ligne" "verticale"]
	$K create text $XduTexte $YduTexte \
		-text "$Etiquette" \
		-anchor "e" \
		-tags [list $Nom $X "Etiquette" "verticale" $Y $Etiquette]
    }
    if {$Action == "h" || $Action == "vh"} {
	if {$Action=="vh"} {
	    set Gauche [expr $XActuel-5]
	    set Droite [expr $XActuel+5]
	}
	$K create line $Gauche $YActuel $Droite $YActuel -tags [list $Nom $YPositionADN "Ligne" "horizontale"]
	lappend LesDemarcationsHorizontales($K) $YPositionADN
	lappend LesAbscissesHorizontales($K)    $YPositionADN
	lappend LesEtiquettesHorizontales($K)   [NomDe Etiquette]
	TrieLesListesDeDemarcation $K "h"
    }
    return 
}

proc TPIO {} {
    foreach Nom [ListeDesPABs] {
	Espionne [time {set PIO [PourcentageIdentiteOrga $Nom taci]}]
	Espionne $PIO
    }
	
    exit
}

proc PourcentageIdentiteOrga {Nom Orga {FichierPIC ""}} {
    global RepertoireDuGenome
    global PourcentageIdentiteOrga
    global LesOrgasDePIO
    global NotreOS
    global NotreOrga


    Wup "If FichierPIC is empty we work normally on current genome" 

    set FiPIC $FichierPIC
    set NOF "$Nom,$Orga,$FiPIC"
    if { [info exists PourcentageIdentiteOrga($NOF)]} {
	return [set   PourcentageIdentiteOrga($NOF)]
    } else {
	if {0 && [info exists PourcentageIdentiteOrga("EstCharge",$FiPIC)]} {
	    return -1
	}
    }
    if {$FichierPIC==""} {
	set Extension ".$NotreOrga"
	set FichierPIC "$RepertoireDuGenome/fiches/piclustalw$Extension"
    }

    if  {$Nom == "LaListe"} { set RendreLaListe 1 } else { set RendreLaListe 0 }

    

    if { ! [info exists PourcentageIdentiteOrga("EstCharge",$FiPIC)]} {
	set PourcentageIdentiteOrga("EstCharge",$FiPIC) "EstCharge"
	if { ! [file exists $FichierPIC]} { return "PourcentageIdentiteOrgaNonValide" } 
	Espionne "Je charge $FichierPIC"
	foreach Ligne [LesLignesDuFichier $FichierPIC] {
	    set Liste [split $Ligne " "]
	    set NomLu [lindex $Liste 0]
	    set ListeOrgaPIC [lrange $Liste 1 end]
	    foreach {OrgaLu PI} $ListeOrgaPIC {
		if {[info exists PourcentageIdentiteOrga($NomLu,$OrgaLu,$FiPIC)]} { continue }
		if { ! [info exists DejaVu($OrgaLu)]} {
		    lappend LesOrgasDePIO $OrgaLu
		    set DejaVu($OrgaLu) 1
		}
		set NOFlu "$NomLu,$OrgaLu,$FiPIC"
		set PourcentageIdentiteOrga($NOFlu) $PI
	    }
	}
    }

    if {$RendreLaListe} { return $LesOrgasDePIO } 

    if {[info exists PourcentageIdentiteOrga($NOF)]} { 
	return [set  PourcentageIdentiteOrga($NOF)]
    } else {
	return -1
    }
}

proc InteRosace {Type {K ""}} {
    global RosaceCourante
    global LesInteRosacesPossibles
    global LesInteRosaces

    if {$K==""} {
	if { ! [info exists RosaceCourante]} {
	    RscopeBoard $CurrentGenome
	}
	set K $RosaceCourante
    }

    if {$Type=="Which"} {
	if { ! [info exists $LesInteRosaces($K)] || [llength $LesInteRosaces($K)]==0} {
	    FaireLire "No Interior Wheel"
	} else {
	    FaireLire "[join $LesInteRosaces($K) "\n"]"
	}
	return ""
    }

    if {$Type=="New"} { AiguilleLaListe {} $K "UneListe" } 

    if { ! [info exists LesInteRosacesPossibles]} {
	foreach Procedure [info procs] {
	    if {[regexp "^RosaceDe" $Procedure]} {
		lappend LesInteRosacesPossibles $Procedure
	    }
	}
    }

    set InteRo [ChoixParmi [concat $LesInteRosacesPossibles "Erase_all"]]
    if {$InteRo==""} { return "" }

    if {$InteRo=="Erase_all"} { AiguilleLaListe {} $K "UneListe" ;  return "" }

    lappend LesInteRosaces($K) $InteRo
    $InteRo $K
}

proc RosaceDesPIOs {Type {K ""} {LesOrgas ""}} {
    global RepertoireDuGenome
    global ListeDeBoites
    global ListeDesPABs
    global RosaceCourante
    global CurrentGenome
    global ListeCompleteDesOrganismesAyantMemeOperon

    if {$K==""} {
	if { ! [info exists RosaceCourante]} {
	    RscopeBoard $CurrentGenome
	}
	set K $RosaceCourante
    }

    if { ! [info exists ListeDeBoites]} { ChargeListeDeBoites }

    if {$LesOrgas == ""} {
	if { ! [info exists ListeCompleteDesOrganismesAyantPIO]} {
	    set ListeCompleteDesOrganismesAyantPIO [PourcentageIdentiteOrga "LaListe" "Merci"]
	}
	
	set LesOrgas [CocheDansLaListe [concat $ListeCompleteDesOrganismesAyantPIO "AllTogether"]]
	
	if {$LesOrgas==""} { return $K }
	
	if {[lsearch $LesOrgas "AllTogether"] > -1} {
	    set LesOrgas $ListeCompleteDesOrganismesAyantMemeOperon
	}
    }

    set MaxExterieur 0.45
    set MinInterieur 0.30

    set Delta [expr ($MaxExterieur-$MinInterieur)/[llength $LesOrgas]]

    set Exterieur $MaxExterieur
    foreach Orga $LesOrgas {
	set Interieur [expr $Exterieur + $Delta*0.6]
	set LesPointes {}
	foreach Nom $ListeDesPABs {
	    set PIO [PourcentageIdentiteOrga $Nom $Orga]
	    if {$PIO == -1 } { continue }
	    if {$PIO > 80} {
		set Couleur "red"
	    } elseif {$PIO > 50} {
		set Couleur "orange"
	    } elseif {$PIO > 30} {
		set Couleur "green"
	    } else { continue }
	    lappend LesPointes $Nom
	    lappend LesPointes $Couleur
	}
	AiguilleLaListe $LesPointes $K "UneListeEnPlus" "milieu" $Interieur $Exterieur 
	set Exterieur [expr $Exterieur - $Delta]
    }
    return $K
}

proc RosaceDesTwoGenesCluster {Type {K ""} {LesOrgas ""}} {
    global RepertoireDuGenome
    global ListeDeBoites
    global ListeDesPABs
    global RosaceCourante
    global CurrentGenome
    global ListeCompleteDesOrganismesAyantMemeOperon
    
    Gs "Rien"
    
    if {$K==""} {
	if { ! [info exists RosaceCourante]} {
	    RscopeBoard $CurrentGenome
	}
	set K $RosaceCourante
    }

    if { ! [info exists ListeDeBoites]} { ChargeListeDeBoites }

    if {$LesOrgas==""} {
	if { ! [info exists ListeCompleteDesOrganismesAyantMemeOperon]} {
	    ChargeLesOrganismesAyantMemeOperon
	}
	
	set LesOrgas [CocheDansLaListe [concat $ListeCompleteDesOrganismesAyantMemeOperon "AllTogether"]]
	
	if {$LesOrgas==""} { return $K }
	
	if {[lsearch $LesOrgas "AllTogether"] > -1} {
	    set LesOrgas $ListeCompleteDesOrganismesAyantMemeOperon
	}
    }

    set MaxExterieur 0.50
    set MinInterieur 0.30
    if {[regexp "MsFinal" [RepertoireDuGenome]]} {
	set MaxExterieur 0.65
	set MinInterieur 0.40
    }

    set Delta [expr ($MaxExterieur-$MinInterieur)/[llength $LesOrgas]]

    set Exterieur $MaxExterieur
    foreach Orga $LesOrgas {
	set Interieur [expr $Exterieur + $Delta*0.6]
	set LesPointes {}
	foreach Nom $ListeDesPABs {
	    set ListeOMO [ListeDesOrganismesAyantMemeOperon $Nom]
	    if {[lsearch $ListeOMO $Orga] == -1} { continue }
	    lappend LesPointes $Nom
	    lappend LesPointes "black"
	}
	AiguilleLaListe $LesPointes $K "UneListeEnPlus" "milieu" $Interieur $Exterieur 
	set Exterieur [expr $Exterieur - $Delta]
    }
    return $K
}

proc RosaceDesCas {Type {K ""} {Interieur ""} {Exterieur ""}} {
    global RepertoireDuGenome
    global ListeDeBoites
    global ListeDesPABs
    global RosaceCourante
    global CurrentGenome

    if {$K==""} {
	if { ! [info exists RosaceCourante]} {
	    RscopeBoard $CurrentGenome
	}
	set K $RosaceCourante
    }

    if {$Interieur==""} { set Interieur 0.75 ; set Exterieur 0.80 }

    if { ! [info exists ListeDeBoites]} { ChargeListeDeBoites }

    set Black 0
    set Red 0
    set Orange 0
    foreach Nom $ListeDesPABs {
	if {[Fantome $Nom]} {
	    set Couleur $CouleurDuFond
	} elseif {[regexp "CasNonConnu" [Cas $Nom]]} {
	    set Couleur "white"
	} elseif {[regexp {^1} [Cas $Nom]]} {
	    set Couleur "black"
	    incr Black
	} elseif {[regexp {1$} [Cas $Nom]]} {
	    set Couleur "red"
	    incr Red
	} elseif {[regexp {1,0$} [Cas $Nom]]} {
	    set Couleur "orange"
	    incr Orange
	} elseif {[regexp {1,0,0$} [Cas $Nom]]} {
	    set Couleur "yellow"
	} else {
	    set Couleur "green"
	}
	if {$Couleur=="black" || $Couleur=="red" } { 
	    lappend LesPointes $Nom
	    lappend LesPointes $Couleur
	}
    }
    AiguilleLaListe $LesPointes $K "UneListeEnPlus" "milieu" $Interieur $Exterieur 
    return $K
}

proc RosaceDesPhylosFolles {Type {K ""} {Interieur ""} {Exterieur ""}} {
    global RepertoireDuGenome
    global ListeDeBoites
    global ListeDesPABs
    global RosaceCourante
    global CurrentGenome

    if {$K==""} {
	if { ! [info exists RosaceCourante]} {
	    RscopeBoard $CurrentGenome
	}
	set K $RosaceCourante
    }

    if {$Interieur==""} { set Interieur 0.75 ; set Exterieur 0.80 }


    if { ! [info exists ListeDeBoites]} { ChargeListeDeBoites }

    foreach Nom $ListeDesPABs {
	if {[PhyloFolle $Nom]} { 
	    lappend LesPointes $Nom
	    lappend LesPointes "red"
	}
    }
    AiguilleLaListe $LesPointes $K "UneListeEnPlus" "milieu" $Interieur $Exterieur 
    return $K
}

proc RosaceDesTables {Type {K ""} {Interieur ""} {Exterieur ""}} {
    global RepertoireDuGenome
    global ListeDeBoites
    global ListeDesPABs
    global RosaceCourante
    global CurrentGenome
    global OuEstIlRetenu

    if {$K==""} {
	if { ! [info exists RosaceCourante]} {
	    RscopeBoard $CurrentGenome
	}
	set K $RosaceCourante
    }

    if {$Interieur==""} { set Interieur 0.75 ; set Exterieur 0.80 }


    if { ! [info exists ListeDeBoites]} { ChargeListeDeBoites }

    if { ! [info exists LesNomDesTables]} {
	set LesNomsDesTables     {"no_ark" "manque_euryarks" "toutes_euryarks"}
	set LesCouleursDesTables {"red"    "orange"          "green"          }
	foreach Table $LesNomsDesTables {
	    foreach Ligne [LesLignesDuFichier "$RepertoireDuGenome/fiches/pabretenus.$Table"] {
		scan $Ligne "%s" Nom
		set ${Table}($Nom) 1
	    }
	}
    }

    foreach Nom $ListeDesPABs {
	foreach Table $LesNomsDesTables Couleur $LesCouleursDesTables {
	    if {[info exists ${Table}($Nom)]} { 
		if {$Couleur != "green"} {
		    lappend LesPointes $Nom
		    lappend LesPointes $Couleur
		}
		break
	    }
	}
    }
    AiguilleLaListe $LesPointes $K "UneListeEnPlus" "milieu" $Interieur $Exterieur 
    return $K
}

proc RosaceDesGCSkew {Type {K ""} {Interieur ""} {Exterieur ""}} {
    global RepertoireDuGenome
    global ListeDeBoites
    global ListeDesPABs
    global RosaceCourante
    global CurrentGenome

    if {$K==""} {
	if { ! [info exists RosaceCourante]} {
	    RscopeBoard $CurrentGenome
	}
	set K $RosaceCourante
    }

    if {$Interieur==""} {
	set Interieur 0.70
	set Exterieur 0.74
    }

    if { ! [info exists ListeDeBoites]} { ChargeListeDeBoites }

    foreach Boite $ListeDeBoites {
	set Nom [Box $Boite nom]
	if {[regexp "GLIMMER" $Nom]} { continue }
	set GC [CompositionEn GC $Nom]
	if { $GC == "" } {
	    set Couleur "white"
	} else {
	    set Couleur [QuelInterval $GC [LesSeuilsGC] [CouleursDuRougeAuBleu 5]]
	}
	lappend LesPointes $Nom
	lappend LesPointes $Couleur	
    }
    AiguilleLaListe $LesPointes $K "UneListeEnPlus" "milieu" $Interieur $Exterieur 
    return $K
}

proc ShowNucRosace {K X Y Action {PositionNucleique 0}} {
    global ADN TDN RAC
    global OldX OldADN OldTDN OldPosD OldPosG OldLigne
    global       RectangleDeSelectionNucleique
    global xDebutRectangleDeSelectionNucleique
    global yDebutRectangleDeSelectionNucleique
    global   xFinRectangleDeSelectionNucleique
    global   yFinRectangleDeSelectionNucleique
    global xMinCercleDeSelectionNucleique
    global yMinCercleDeSelectionNucleique
    global xMaxCercleDeSelectionNucleique
    global yMaxCercleDeSelectionNucleique
    global DebutAngleDeSelectionNucleique
    global   FinAngleDeSelectionNucleique
    global ParametresDuBoard
    global PremiereMotion
    global JeChargeADNduCalme
    global CouleurArcDeZone
    global OldRayonJaune

    if { [info exists JeChargeADNduCalme] } { return }
    if { ! [info exists ADN]} {
	set JeChargeADNduCalme 1
	ChargeADNetTDNetRAC
	unset JeChargeADNduCalme
    }

    set PI 3.14159

    set x [$K canvasx $X]
    set y [$K canvasy $Y]

    set xFin    [set ParametresDuBoard($K,xFin)]
    set CentreX [set ParametresDuBoard($K,CentreX)]
    set CentreY [set ParametresDuBoard($K,CentreY)]

    if {$PositionNucleique > 0} {
	set Angle [expr $PositionNucleique*(2*$PI)/$xFin]
	set PositionSurADN $PositionNucleique
    } else {
	set Angle [HeureDansRosace $K $X $Y]
	set PositionSurADN [expr round($xFin*$Angle/(2*$PI))]   
    }

    if { $Action == "Point" } {
	set PremiereMotion($K) 1
	set xDebutRectangleDeSelectionNucleique($K) $PositionSurADN
	set DebutAngleDeSelectionNucleique($K) [expr ([DecalageAngulaireRosace] + $PI/2 - $Angle)*180./$PI]
	set RayonJaune [RayonDansRosace $K $X $Y]
	if {[info exists OldRayonJaune] && [expr abs($RayonJaune-$OldRayonJaune)/$RayonJaune < 0.05]} {
	    set RayonJaune $OldRayonJaune
	}
	set OldRayonJaune $RayonJaune
	set xMinCercleDeSelectionNucleique($K) [expr $CentreX-$RayonJaune]
	set yMinCercleDeSelectionNucleique($K) [expr $CentreY-$RayonJaune]
	set xMaxCercleDeSelectionNucleique($K) [expr $CentreX+$RayonJaune]
	set yMaxCercleDeSelectionNucleique($K) [expr $CentreY+$RayonJaune]
    }

    if {[info exists OldLigne($K)]} {
	catch {$K delete [set OldADN($K)]}
	catch {$K delete [set OldTDN($K)]}
	catch {$K delete [set OldPosD($K)]}
	catch {$K delete [set OldPosG($K)]}
	catch {$K delete [set OldLigne($K)]}
	unset OldLigne($K)
	if { $PositionNucleique == 0 && $X == [set OldX($K)] } { return }
    }

    set i $PositionSurADN

    set Orient "Inconnue"
    set BoiteTouchee [BoiteDuCourant $K $X $Y]
    if { $BoiteTouchee != "" } {
	if { [expr $i < ([Box $BoiteTouchee debut]+[Box $BoiteTouchee fin])/2]} {
	    set i [Box $BoiteTouchee debut]
	} else {
	    set i [expr [Box $BoiteTouchee fin]+1]
	}
	set x [PositionCanvaActuelleX $K $i]
	set y [expr $y-30]
	set Orient [Box $BoiteTouchee orient]
    }

    set ZoneADN [string range $ADN [expr $i-20] [expr $i+19]]
    set ZoneTDN [string range $TDN [expr $i-20] [expr $i+19]]
    set PositionD [format " %4.4d" $i]
    set PositionG [format "%4.4d " [expr $i-1]]

    set Fonte {Courier 8}
    set OldX($K) $X
    if { $Orient != "R" } {
	set OldADN($K)   [$K create text [expr $x] [expr $y-10] \
		-text $ZoneADN  -font $Fonte -anchor center]
    }
    if { $Orient != "F" } {
	set OldTDN($K)   [$K create text [expr $x] [expr $y+10] \
		-text $ZoneTDN  -font $Fonte -anchor center]
    }
    set OldPosD($K)  [$K create text $x [expr $y] -text $PositionD -font $Fonte -anchor w]
    set OldPosG($K)  [$K create text $x [expr $y] -text $PositionG -font $Fonte -anchor e]
    set OldLigne($K) [$K create line $CentreX $CentreY $x $y]


    if { $Action == "Motion" } {
	if { ! [set PremiereMotion($K)]} {
	    if {[info exists RectangleDeSelectionNucleique($K)]} {
		$K delete [set RectangleDeSelectionNucleique($K)]
	    }
	}
	set PremiereMotion($K) 0
	set xFinRectangleDeSelectionNucleique($K) $PositionSurADN
	set FinAngleDeSelectionNucleique($K) [expr ([DecalageAngulaireRosace] + $PI/2 - $Angle)*180./$PI]
	set Start  [set DebutAngleDeSelectionNucleique($K)]
	set Extent [expr [set FinAngleDeSelectionNucleique($K)] - $Start]
	if {[info exists CouleurArcDeZone]} {
	    set CouleurArc $CouleurArcDeZone
	    set Epaisseur 7
	    set LesTags {}
	} else {
	    set CouleurArc "yellow"
	    set Epaisseur 3
	    set LesTags [list "SelectionNucleique"]
	}
	set RectangleDeSelectionNucleique($K) [$K create arc \
		[set xMinCercleDeSelectionNucleique($K)] \
		[set yMinCercleDeSelectionNucleique($K)] \
		[set xMaxCercleDeSelectionNucleique($K)] \
		[set yMaxCercleDeSelectionNucleique($K)] \
		-start  $Start  \
		-extent $Extent \
		-style "arc" \
		-outline $CouleurArc \
		-width $Epaisseur \
		-tags $LesTags]
	return [set RectangleDeSelectionNucleique($K)]
    }
}    

proc CreeLesTables {Source Orga Extension} {
    set LesTables {"tout_le_monde" "toutes_euryarks" "manque_euryarks" "no_ark" "pyro_specif"}
    set LesTables {"tout_le_monde"}
    foreach Table $LesTables {
	CreeLaTable $Table $Source $Orga $Extension
    }
}

proc CreeLaTableDuTamis {{Tam ""} {Source ""} {Orga ""} {Extension ""}} {
    if {$Tam==""} { set Tam [ChoisisUnTamis "ChampNom" "AvecNewTamis"] }
    set Tam [CreeLeTasTamis $Tam]
    if {$Tam==""} { return "" } 
    CreeLaTable "TasTamis_$Tam" $Source $Orga $Extension
} 

proc CreeLaTable {CommeCa {Source ""} {Orga ""} {Extension ""}} {
    global RepertoireDuGenome
    global NotreOS
    global NotreOrga
    global TasTamis
    
    Wup "On peut avoir comme source distancesphylo ou psclustalw"

    if {$Source==""} { set Source "distancesphylo" }
    if {$Orga==""} { set Orga $NotreOrga }
    if {$Extension==""} { set Extension ".$Orga" }

    Wup "Devrait etre le meme que dans LesSpecifiquesDansDistancePhylo"
    set SeuilDistance 82
    set SeuilPIC 20

    Wup "On en repeche car il existent dans TBlastN mais pas dans le proteome de phor"
    set ARepecher "ABY0341 ABY7428 ABY3419 ABY7435 ABY3433"

    regsub {\$}        $CommeCa "" Titre
    regsub {\^}        $Titre   "" Titre
    regsub " "         $Titre   "" Titre
    regsub "TasTamis_" $Titre   "" Titre

    foreach Ligne [LesOrganismesImportantsPourDBClustal] {
	scan $Ligne "%s %s" Genre Espece
	set Complet "$Genre $Espece"
	set Organisme [Glossaire $Complet Court]
	set OrgaInteressant($Organisme) 1
    }

    catch {unset OrgaInteressant([Glossaire $Orga Court])}
    catch {unset OrgaInteressant(nmen)}
    
    set FichierPIClustalw "$RepertoireDuGenome/fiches/piclustalw$Extension"
    while { ! [file exists $FichierPIClustalw]} {
	if {[OuiOuNon "$FichierPIClustalw doesn't exist\Do I create it now ? (it will take a while)."]} {
	    CreeLesFichiersPIClustalwEtPSClustalw $Orga $Extension
	}
    }
    foreach Ligne [LesLignesDuFichier $FichierPIClustalw] {
	set Liste [split $Ligne " "]
	set Nom [lindex $Liste 0]
	set ListeOrgaPIC [lrange $Liste 1 end]
	if {[regexp $Nom $ARepecher]} {
	    set ListeOrgaPIC [linsert $ListeOrgaPIC 0 100]
	    set ListeOrgaPIC [linsert $ListeOrgaPIC 0 phor]
	}
	foreach {Orga PI} $ListeOrgaPIC {
	    if {[info exists PIC($Nom,$Orga)]} { continue }
	    set PIC($Nom,$Orga) $PI
	}
    }

    if {$Source=="distancesphylo"} {
	set FichierDistancesPhylo "$RepertoireDuGenome/fiches/distancesphylo$Extension"
	if { ! [file exists $FichierDistancesPhylo]} {
	    FaireLire "$FichierDistancesPhylo\nNous y voila"
	    set FichierDistancesPhylo [CreeDistancesPhyloAvecLesMSFs [Glossaire $NotreOS Court] [PreFixe]]
	}
    }

    if {$Source=="psclustalw"} {
	set FichierDistancesPhylo "$RepertoireDuGenome/fiches/psclustalw$Extension"
	set MaxiPS -9999.
	foreach Ligne [LesLignesDuFichier $FichierDistancesPhylo] {
	    scan $Ligne "%s %s %f" Nom Orga PS
	    set MaxiPS [Maxi $PS $MaxiPS]
	}
	set CoeffPSversDistance  [expr 100./$MaxiPS]
	set OffsetPSversDistance 0
    }

    set NombreDeLignesRejetees 0
    foreach Ligne [LesLignesDuFichier $FichierDistancesPhylo] {
	set Liste [split $Ligne " "]
	set Nom [lindex $Liste 0]
	set ListeOrgaDistance [lrange $Liste 1 end]
#	if {[regexp $Nom $ARepecher]} {
#	    set ListeOrgaDistance [linsert $ListeOrgaDistance 0 $MaxiPS]
#	    set ListeOrgaDistance [linsert $ListeOrgaDistance 0 phor]
#	}
	set NouvelleListeOrgaDistance {}
	set LesHonnetes {}
	catch { unset DejaVuCetOrga }
	foreach {Orga Distance Access} $ListeOrgaDistance {
	    if {$Source=="psclustalw"} {
		set Distance [expr $CoeffPSversDistance*$Distance + $OffsetPSversDistance]
	    }
	    if {[info exists DejaVuCetOrga($Nom,$Orga)]} { continue }
	    if {[info exists PIC($Nom,$Orga)]} {
		if {[set PIC($Nom,$Orga)] < $SeuilPIC } { continue }
	    } else {
		if {$Distance > $SeuilDistance} { continue }
	    }
	    set DejaVuCetOrga($Nom,$Orga) 1
	    lappend LesHonnetes $Orga
	    lappend LesHonnetes $Distance
	    if { ! [info exists OrgaInteressant($Orga)] } { continue }
	    lappend NouvelleListeOrgaDistance $Orga
	    lappend NouvelleListeOrgaDistance $Distance
	    lappend NouvelleListeOrgaDistance $Access
	}
	set YaUneBactos 0
	foreach {Orga Distance Access} $NouvelleListeOrgaDistance {
	    if { ! [PyroLike $Orga]} {
		set YaUneBactos 1
		break
	    } 
	}
	
	if { $NouvelleListeOrgaDistance == {} || $CommeCa == "no_ark" && ! $YaUneBactos } {
	    lappend LesRejetes $Ligne
	    incr NombreDeLignesRejetees
	    continue
	}
	set AncienneLigne($Nom) "$Nom [join $LesHonnetes " "]"
	lappend NouvellesLignes "$Nom [join $NouvelleListeOrgaDistance " "]"
    }

    SauveLesLignes $NouvellesLignes dans "$FichierDistancesPhylo.$Titre"
    
    set NombreDePhylosRetenus 0
    set MaxPlace 0
    set ListeDesOrgas {}
    set LesRetenus {}
    foreach Ligne $NouvellesLignes {
	set Liste [split $Ligne " "]
	set Nom [lindex $Liste 0]
	set ToutesLesEuryArks \
		[expr  [regexp "phor" $Ligne] \
		    && [regexp "pfur" $Ligne] \
		    && ( ! [info exists AutreOrganismeDeReference] || [regexp "paby" $Ligne]) \
		    && [regexp "mjan" $Ligne] \
		    && [regexp "mthe" $Ligne] \
		    && [regexp "aful" $Ligne] \
		    ]
	if { $CommeCa == "toutes_euryarks" && ! $ToutesLesEuryArks } { continue } 
	if { $CommeCa == "manque_euryarks" &&   $ToutesLesEuryArks } { continue } 
	set NoEuryArk \
		[expr  ! [regexp "mjan" $Ligne] \
		    && ! [regexp "mthe" $Ligne] \
		    && ! [regexp "aful" $Ligne] \
		    ]
	if { $CommeCa == "no_euryark" && ! $NoEuryArk } { continue } 
	set NoArk \
		[expr  ! [regexp "mjan" $Ligne] \
		    && ! [regexp "mthe" $Ligne] \
		    && ! [regexp "aful" $Ligne] \
		    && ! [regexp "aper" $Ligne] \
		    && ! [regexp "ssol" [set AncienneLigne($Nom)]] \
		    && ! [regexp "hsal" [set AncienneLigne($Nom)]] \
		    ]
	if { $CommeCa == "no_ark" && ! $NoArk } { continue } 

	if { [regexp "TasTamis" $CommeCa] && ! [info exists TasTamis($Nom)] } { continue }

	incr NombreDePhylosRetenus
	lappend LesRetenus $Ligne
	set SC [SuperClasse [ClasseFonctionnelle $Nom]]
	if {[info exists Cumul($SC)]} {
	    incr Cumul($SC)
	} else {
	    set Cumul($SC) 1
	}

	set ListeOrgaDistance [lrange $Liste 1 end]

	set Place 0
	catch {unset DejaVuDansCetteListe}
	set NomOrgasDuPAB $Nom

	foreach {Orga Distance Access} $ListeOrgaDistance {
	    if { ! [info exists DejaVu($Orga)] } {
		set DejaVu($Orga) 1
		if {[info exists CumulDesDistances($Orga)]} {
		    incr CumulDesDistances($Orga) $Distance
		    incr NombreDeDistancesCumulees($Orga)
		} else {
		    set CumulDesDistances($Orga) $Distance
		    set NombreDeDistancesCumulees($Orga) 1
		}
		lappend ListeDesOrgas $Orga
	    }
	    if {[info exists DejaVuDansCetteListe($Orga)]} { continue }
	    lappend ListeNomOrgaDistanceDesPABs "$Nom $Orga $Distance"
	    append NomOrgasDuPAB " $Orga"
	    set DejaVuDansCetteListe($Orga) 1
	    incr Place
	    set MaxPlace [Maxi $MaxPlace $Place]
	    if {0 && $Place > 15} { continue } 
	    set Place [Mini $Place 15]
	    if { ! [info exists CumulOrgaPlace($Orga,$Place)]} {
		set CumulOrgaPlace($Orga,$Place) 0
	    }
	    incr CumulOrgaPlace($Orga,$Place)
	}
	set GrosseDefinition "[Definition $Nom]"
#	Espionne "[string range $GrosseDefinition 0 60] $NomOrgasDuPAB"
	lappend ListeNomOrgas $NomOrgasDuPAB
   }
   Espionne "$NombreDeLignesRejetees PAB rejetes"
   Espionne "$NombreDePhylosRetenus PAB retenus"

   Wup "Mettre 10 pour ne garder que les 10 premieres par ex."
   set nColonnes 12
   set MaxPlace [Mini $MaxPlace $nColonnes]

   set ListeOrgaEtSesPlaces {}
   foreach Orga $ListeDesOrgas {
       set LesPlaces {}
       set SesPlaces ""
       set CumulDM 0
       set CumulMM 0
       set CumulM 0
       for {set Place 1} {$Place<=$MaxPlace} {incr Place} {
	   if {[info exists CumulOrgaPlace($Orga,$Place)]} {
	       set COP [set CumulOrgaPlace($Orga,$Place)]
	       lappend LesPlaces $COP
	       incr CumulDM [expr $Place*$COP*$COP]
	       incr CumulMM [expr        $COP*$COP]
	       incr CumulM  $COP
	   } else {
	       lappend LesPlaces -1
	   }
       }
       Wup "On affiche le % si 1   ou le # de fois si 0 "
       set OnVeutPourcentage 0
       set Tab " "

       Wup "Nombre de fois mini ou orga doit apparaitre pour etre significatif"
       set MiniCumulM 1
       if { $CumulM < $MiniCumulM } { continue }

       foreach Place $LesPlaces {
	   set PP [Maxi [expr ($Place*100)/$CumulM] 0]
	   if { $Place > 0 } {
	       if {$OnVeutPourcentage} {
		   append SesPlaces [format "$Tab%4d" $PP]
	       } else {
		   append SesPlaces [format "$Tab%4d" $Place]
	       }
	   } else {
	       append SesPlaces "$Tab    "
	   }
       }
#      set SesPlaces [string trimright $SesPlaces]
       set MoyenneDesDistances [expr [set CumulDesDistances($Orga)]/[set NombreDeDistancesCumulees($Orga)]]
       set SesPlaces "$SesPlaces $MoyenneDesDistances" 
       set PlacePreferee [expr (1.0*$CumulDM)/$CumulMM]
       set BellePlacePreferee [format "%5.1f" $PlacePreferee]
       set BelOrga [format "%-16s" [string range [Glossaire $Orga Pointe] 0 15]]
       set OrgaCentreEtSesPlaces "$BellePlacePreferee $BelOrga $SesPlaces"  
       lappend ListeOrgaEtSesPlaces $OrgaCentreEtSesPlaces
   }
   set ListeTriee [lsort -command CompareLesFloatsEnDebut $ListeOrgaEtSesPlaces]
   set BonneListeTriee {}
   foreach Ligne $ListeTriee {
       lappend BonneListeTriee [string range $Ligne 6 end]
   }
   Espionne [join $BonneListeTriee "\n"]

   set Resume "Ordre  "
   foreach Ligne $BonneListeTriee {
       scan $Ligne "%s" OrgaPointe
       set Orga [Glossaire $OrgaPointe Court]
       if {[regexp "M.thermoauto" $OrgaPointe]} { set Orga "mthe" }
       if {[regexp "nmen" $Orga]} { continue }
       append Resume " $Orga"
   }
   Espionne [string range $Resume 0 100]
#   foreach SC [LesSuperClassesDansLOrdre] {
#       if { ! [info exists Cumul($SC)]} { continue }
#       if {[regexp "RR|tR" $SC]} { continue }
#       set HistoDuSC [format "%4d %4.1f%% %s" [set Cumul($SC)] [expr [set Cumul($SC)]*100./$NombreDePhylosRetenus] $SC]
#       Espionne $HistoDuSC
#       lappend HistoDesSC $HistoDuSC
#   }

    set FichierOrgaEtSesPlaces "$RepertoireDuGenome/fiches/orgaetsesplaces.$Titre"
    if {[file exists $FichierOrgaEtSesPlaces]} {
	if { ! [OuiOuNon "$FichierOrgaEtSesPlaces\nalready exists. Do I replace it ?"]} {
	    set FichierOrgaEtSesPlaces [FichierPourSaveAs "$FichierOrgaEtSesPlaces"]
	}
    }
    if {$FichierOrgaEtSesPlaces!=""} {
	Espionne [SauveLesLignes $BonneListeTriee dans $FichierOrgaEtSesPlaces]
    }

    set FichierPABRetenus "$RepertoireDuGenome/fiches/pabretenus.$Titre"
    if {[file exists $FichierPABRetenus]} {
	if { ! [OuiOuNon "$FichierPABRetenus\nalready exists. Do I replace it ?"]} {
	    set FichierPABRetenus [FichierPourSaveAs "$FichierPABRetenus"]
	}
    }
    if {$FichierPABRetenus!=""} {
	Espionne [SauveLesLignes $LesRetenus dans $FichierPABRetenus]
    }
#   Espionne [SauveLesLignes $HistoDesSC dans "$RepertoireDuGenome/fiches/superclasses.$Titre"]
#   Espionne [SauveLesLignes $LesRejetes dans "$RepertoireDuGenome/fiches/pabrejetes.$Titre"]
}

proc CocheDansLaListe {Liste {CocheParDefaut {}}} {
    global retourCoche
    global VariableAssociee

    set w [NomDe coche]
    catch {destroy $w}
    toplevel $w
    wm title $w "Merci de cocher ..."
    wm iconname $w "Coche"
    
    frame  $w.buttons
    pack   $w.buttons -side bottom -fill x -pady 2m
    button $w.buttons.dismiss -text "Dismiss" -background red    -foreground white \
	    -command "set retourCoche($w) Dismiss"
    pack   $w.buttons.dismiss -side left -expand 1
    button $w.buttons.defaut -text "Default"  -background yellow -foreground black \
	    -command "set retourCoche($w) Defaut"
    pack   $w.buttons.defaut -side left -expand 1
    button $w.buttons.accept -text "Accept"   -background green  -foreground black \
	    -command "set retourCoche($w) Accept"
    pack   $w.buttons.accept -side left -expand 1

    set d 0
    set i 0
    foreach a $Liste d $CocheParDefaut {
	if {$d==""} { set d 0 }
	set VariableAssociee($a) $d
	set b $w.b[incr i]
	checkbutton $b -text "$a" -variable VariableAssociee($a) -relief flat
	pack $b -side top -pady 2 -anchor w
    }

    tkwait variable retourCoche($w)

    if { [set retourCoche($w)] == "Defaut" } {
	foreach a $Liste d $CocheParDefaut {
	    if {$d==""} { set d 0 }
	    set VariableAssociee($a) $d 
	}
	while { [set retourCoche($w)] == "Defaut" } {
	    unset retourCoche($w)
	    tkwait variable retourCoche($w)
	}
    }
    if { [set retourCoche($w)] != "Dismiss" } {
	set LesChoisis {}
	foreach a $Liste {
	    if {[set VariableAssociee($a)]} {
		lappend LesChoisis $a
	    }
	}
    }
    unset retourCoche($w)
    destroy $w
    return $LesChoisis
}

proc TousLesMiniBootstrap {} {
    global RepertoireDuGenome

    foreach FichierPhylo [glob "$RepertoireDuGenome/bootstrap/*"] {
	MiniBootstrap $FichierPhylo
    }
}

proc MiniBootstrap FichierPhylo {
    global ListeDistanceDeChaqueFeuille
    global Cible
    global MiniOuSomme

    set Cible [file tail $FichierPhylo]
    set MiniOuSomme "Mini"

    set Arbre [ArbreBootstrapEnListe [ContenuDuFichier $FichierPhylo]]
    set ListeDistanceDeChaqueFeuille {}
    AppendEtRetourneDistance $Arbre "Inconnue"

    puts "\n$Cible"
    puts [join $ListeDistanceDeChaqueFeuille "\n"] 

}

proc AiguilleLaListe {ListeNomCouleur K Type {Po ""} {Min ""} {Max ""}} {
    if { ! [regexp "EnPlus$" $Type]} {
        foreach Id [$K find withtag $Type] {
            $K delete $Id
        }
    } else {
        regsub "EnPlus$" $Type "" Type
    }
    foreach {Nom Couleur} $ListeNomCouleur {
        Aiguille $Nom $Couleur $K $Type $Po $Min $Max
    }
}

proc Aiguille {Nom Couleur K Type {MilieuOuAngle "milieu"} {RapportAuRayonMin 0.1} {RapportAuRayonMax 0.7}} {
    global ParametresDuBoard
    global LesAutresTagsPourAiguilles

    set PI 3.14159

    set xFin           [set ParametresDuBoard($K,xFin)]
    set CentreX        [set ParametresDuBoard($K,CentreX)]
    set CentreY        [set ParametresDuBoard($K,CentreY)]
    set RayonMoyen     [set ParametresDuBoard($K,RayonMoyen)]
    set OffsetRayonMin [set ParametresDuBoard($K,OffsetRayonMin)]
    set OffsetRayonMax [set ParametresDuBoard($K,OffsetRayonMax)]

    set RayonMin [expr $RayonMoyen*$RapportAuRayonMin]
    set RayonMax [expr $RayonMoyen*$RapportAuRayonMax]


    if {$Type == "Zero" } {
	set Angle [expr $PI/2]
	set RayonMax $RayonMoyen
    } else {
	if { $MilieuOuAngle == "angle" } {
	    set Angle $Nom
	} elseif { $MilieuOuAngle == "milieu"} {
	    set Debut  [Box $Nom debut]
	    set Fin    [Box $Nom fin]
	    set Milieu [expr ($Debut+$Fin)/2]
	    if {$Type=="RepereBox"} {
		set Orient [Box $Nom orient]
		if {$Orient == "F"} { set Sens 1 } else { set Sens -1 }
		set RayonMax [expr $RayonMoyen+$Sens*($OffsetRayonMin+$OffsetRayonMax)/2]
	    }
	    set Angle [expr [DecalageAngulaireRosace] + 3.14159/2 - $Milieu*2*3.14159/$xFin]
	} else { 
	    FaireLire "Illegal\nJeMeSignale"
	    return 
	}
    }
    set PosMinX [PositionCanvaActuelleX $K [expr $CentreX+$RayonMin*cos($Angle)]]
    set PosMinY [PositionCanvaActuelleY $K [expr $CentreY-$RayonMin*sin($Angle)]]
    set PosMaxX [PositionCanvaActuelleX $K [expr $CentreX+$RayonMax*cos($Angle)]]
    set PosMaxY [PositionCanvaActuelleY $K [expr $CentreY-$RayonMax*sin($Angle)]]

    if {$Type == "RepereBox"} {
	set Couleur "black"
	$K create text $PosMinX $PosMinY -text $Nom -anchor c -tag "Txt $Type"
    }

    set BindBouton3 0
    set LesTags [list "Aiguille" "$Type"]
    if {[info exists LesAutresTagsPourAiguilles]} {
	set LesTags [concat $LesTags $LesAutresTagsPourAiguilles]
	if {[set i [lsearch $LesAutresTagsPourAiguilles "RosaceArcEnCiel"]] >= 0} {
	    set Tag [lindex $LesAutresTagsPourAiguilles 1]
	    set BindBouton3 1
	}
    }
    $K create line $PosMinX $PosMinY $PosMaxX $PosMaxY -fill $Couleur -tag $LesTags
    if {$BindBouton3} {
	$K bind "$Tag" <3>               "ManipuleLaRosace Point   $K $Tag %x %y"  
	$K bind "$Tag" <ButtonRelease-3> "ManipuleLaRosace Release $K $Tag %x %y"  
	$K bind "$Tag" <Control-3>       "ManipuleLaRosace Switch  $K $Tag %x %y"  
    }
}

proc CreeLesFichiersDesShineDalgarnoDesPABs {{Motif ""} {Liste ""} {Rendre ""}} {
    global RepertoireDuGenome
    global ListeDesPABs
    global NotreOC
    global MotifShineDalgarno


    if {$Liste==""} { set Liste [ListeDesPABs] }

    set RendreLeMotif 0
    if {$Motif=="LeMotifMerci"} {
	set RendreLeMotif 1
	set Motif ""
    }

    if {$Motif=="" && [info exists MotifShineDalgarno]} {
	set Motif $MotifShineDalgarno
    }

    if {$Motif==""} {
	if {[regexp -nocase "Archaea" $NotreOC]} {
	    set Motif "GGT"
	}
	if {[regexp -nocase "Bacteria" $NotreOC]} {
	    set Motif "GGA"
	}
	while {$Motif==""} {
	    if {[OuiOuNon "Do you known the main motif (GGT or GGA or ??? ) for the ShineDalgarno sequence ?"]} {
		set Motif [string toupper [Entre]]
		if {[regexp -nocase {[^ATGC]} $Motif]} {
		    FaireLire "$Motif seems to be wrong (use A,T,G, and C)"
		    set Motif ""
		    continue 
		} 
	    } else {
		if {[OuiOuNon "I'll stop this procedure ?"]} { return "" }
	    }
	}
    }

    if { ! [info exists MotifShineDalgarno]} { set MotifShineDalgarno $Motif }

    if {$RendreLeMotif} { return $Motif }

    if { ! [info exists ListeDesPABs]} { ChargeLesPABs }

    set Avant 18
    set TropLoin $Avant
    set TropPres  6

    set LesSansSD {}
    set LesLoinSD {}
    set LesMetsSD {}
    set LesBonsSD {}
    foreach Boite $Liste {
	set Nom    [Box $Boite nom]
	set Debut  [Box $Boite debut]
	set Fin    [Box $Boite fin]
	set Orient [Box $Boite orient]

	if {$Orient == "F"} {
	    set Seq    [BoutADN [expr $Debut-$Avant] [expr $Debut+2]  $Orient]
	    set SeqMet [BoutADN [expr $Debut-$Avant] [expr $Debut+11] $Orient]
	    set iOldMet $Avant
	} else {
	    set Seq    [BoutADN [expr $Fin-2]  [expr $Fin+$Avant]   $Orient]
	    set SeqMet [BoutADN [expr $Fin-11] [expr $Fin+$Avant] $Orient]
	    set iOldMet $Avant
	}
	set lSeq [string length $Seq]
	set iGGT [string last $Motif $Seq]
	set PosGGT [expr $iGGT-$lSeq]
	if {$iGGT < 0} {
	    lappend LesSansSD "$Nom"
	    continue
	} 
	if {[expr $lSeq-$iGGT] > $TropLoin} {
	    lappend LesLoinSD "$Nom [string range $SeqMet $iGGT end]"
	    continue
	}
	while {$iGGT >= 0 && [expr $lSeq-$iGGT] < $TropPres} {
	    set iGGT [string last $Motif [incr iGGT -1]]
	}
	if {$iGGT>=0} {
	    lappend LesBonsSD "$Nom"
	    continue 
	}

	Wup "Beginning again at farest iGGT, we try to find a better start codon"
	set iGGT [string last $Motif $Seq]
	set iNewMet $iOldMet
	for {set i [expr $iOldMet+3]} {$i < [string length $SeqMet]} {incr i 3} {
	    if {[CodonStartPossible [string range $SeqMet $i [expr $i+2]]]} {
		set iNewMet $i
	    }
	}
	set iGGT [string first $Motif $Seq]
	set AfficheSeq [string range $SeqMet $iGGT end]
	if {$iNewMet != $iOldMet} {
	    set    AfficheSeq                 [string range $SeqMet $iGGT             [expr $iOldMet-1]]
	    append AfficheSeq [string tolower [string range $SeqMet $iOldMet          [expr $iOldMet+2]]]
	    append AfficheSeq                 [string range $SeqMet [expr $iOldMet+3] [expr $iNewMet-1]]
	    append AfficheSeq [string tolower [string range $SeqMet [expr $iNewMet]   [expr $iNewMet+2]]]
	    append AfficheSeq                 [string range $SeqMet [expr $iNewMet+3] end              ]
	    lappend LesMetsSD "$Nom $AfficheSeq"
	} else {
	    set    AfficheSeq                 [string range $SeqMet $iGGT             [expr $iOldMet-1]]
	    append AfficheSeq [string tolower [string range $SeqMet $iOldMet          [expr $iOldMet+2]]]
	    append AfficheSeq                 [string range $SeqMet [expr $iOldMet+3] end              ]
	    lappend LesBonsSD "$Nom $AfficheSeq"
	}
    }
    if {$Rendre=="RendreLesListes"} {
	return [list $LesBonsSD $LesSansSD $LesLoinSD $LesMetsSD]
    }
    if {$Rendre=="RendreEtat"} {
	set Pos [expr $]
	if {$LesBonsSD!={}} { return "ok $PosGGT" }
	if {$LesSansSD!={}} { return "no $PosGGT" }
	if {$LesLoinSD!={}} { return "far $PosGGT" }
	if {$LesMetsSD!={}} { return "met $PosGGT" }
	return ""
    }
    Espionne [SauveLesLignes $LesSansSD dans "$RepertoireDuGenome/fiches/sd_sans"]
    Espionne [SauveLesLignes $LesLoinSD dans "$RepertoireDuGenome/fiches/sd_loin"]
    Espionne [SauveLesLignes $LesMetsSD dans "$RepertoireDuGenome/fiches/sd_mets"]
    Espionne [SauveLesLignes $LesBonsSD dans "$RepertoireDuGenome/fiches/sd_bons"]
}

proc MontreLesSD {} {
    global RepertoireDuGenome
    global ListeDesPABs

    if { ! [info exists ListeDesPABs]} { ChargeLesPABs }

    foreach Nom $ListeDesPABs {
	puts [ShineDalgarno $Nom]
    }
}

proc ShineDalgarno {Nom {Format "raw"}} {
    global RepertoireDuGenome
    global ShineDalgarno

    set Nice(sans) "ShineDalgarno : not found"
    set Nice(bons) "ShineDalgarno : ok"
    set Nice(mets) "ShineDalgarno : too close ... better with next start codon"
    set Nice(loin) "ShineDalgarno : too far"
    set Nice(invalide) ""

    if {[info exists ShineDalgarno]} {
	set SD "invalide"
	if {[info exists ShineDalgarno($Nom)]} {
	    set SD [set ShineDalgarno($Nom)]
	}
	if {$Format=="Nice"} {
	    set Sequence ""
	    scan $SD "%s %s" Etat Sequence
	    set SD [string trim "[set Nice($Etat)] $Sequence"]	    
	}
	return $SD
    }

    foreach NomDuFichier {"sd_bons" "sd_loin" "sd_mets" "sd_sans"} {
	set Fichier "$RepertoireDuGenome/fiches/$NomDuFichier"
	if { ! [file exists $Fichier]} { continue }
	foreach Ligne [LesLignesDuFichier $Fichier] {
	    scan $Ligne "%s" NomLu
	    set Etat [lindex [split $NomDuFichier "_"] 1]
	    set Seq [StringSuivant " " dans $Ligne]
	    set ShineDalgarno($NomLu) "$Etat $Seq"
	}
    }
    set ShineDalgarno(Bidon) "EstCharge"
    return [ShineDalgarno $Nom $Format]
}

proc InformeLesClasses {} {
    global RepertoireDuGenome
    global ListeDesPABs
    global InformeSansDemander

    set InformeSansDemander 1

    if { ! [info exists ListeDesPABs]}  { ChargeLesPABs }

    foreach Ligne [LesLignesDuFichier "$RepertoireDuGenome/fiches/classes"] {
	scan $Ligne "%s %s %s" Nom AA Classe
	set Classes($Nom) $Classe
    }

    foreach Nom $ListeDesPABs {
	Informe $Nom "Class: [set Classes($Nom)]" 
    }
}

proc AfficheLesConcernesDeCeRang {K X Y Fichier} {
    global RepertoireDuGenome
    global NotreOS
    global PABRetenus

    Wup "if K is an Organism then return LesAtteints (for PourGif)"
    if {[regexp {^\.} $K]} {
	set PourGif 0
    } else {
	set PourGif 1
    }

    regsub "orgaetsesplaces" $Fichier "distancesphylo.[Glossaire $NotreOS Court]" FichierDPh
    regsub "orgaetsesplaces" $Fichier "pabretenus"     FichierDesRetenus

    set TailFDR [file tail $FichierDesRetenus]

    if { ! [info exists PABRetenus($TailFDR)] && [file exists $FichierDesRetenus]} {
	set  PABRetenus($TailFDR) 1
	foreach Ligne [LesLignesDuFichier $FichierDesRetenus] {
	    scan $Ligne "%s" Nom
	    set PABRetenus($TailFDR,$Nom) 1
	}
    }

    if { ! [file exists $FichierDPh]} {
	FaireLire "I can't find $FichierDPh"
	return ""
    }
    if {$PourGif} {
	set Orga  [Glossaire $K Court]
	set Score $X
	set Rang  $Y
	set Rep ""
    } else {
	set Id [$K find withtag current]
	set Orga [Glossaire [lindex [$K gettags $Id] 0] Court]
	set Score [lindex [$K gettags $Id] 1]
	set Rang  [lindex [$K gettags $Id] 2]
	set Rep "$RepertoireDuGenome/"
    }

    set LesAtteints {}
    foreach Ligne [LesLignesDuFichier $FichierDPh] {
	set LesMots [split $Ligne " "]
	set Nom [lindex $LesMots 0]
	set Ieme [lsearch -exact $LesMots $Orga]
	if { [expr ($Ieme-1)/3] == [expr $Rang-1] } {
	    if { ! [info exists PABRetenus($TailFDR)] || \
		    [info exists PABRetenus($TailFDR)] && [info exists PABRetenus($TailFDR,$Nom)]} {
		lappend LesAtteints "${Rep}msf/$Nom $Ligne"
	    }
	}
    }

    if {$PourGif} { return $LesAtteints }

    if {[llength $LesAtteints]>0} {
	AfficheVariable [join $LesAtteints "\n"] "AvecShowSansFetch"
    } else {
	FaireLire "Sorry I can't find the associated alignments ... I'm so messy ..."
    }
}

proc DemandeEtDessineOrgaEtSesPlaces {} {
    global RepertoireDuGenome
    
    Gs "Canvas"
    
    set Generique "orgaetsesplaces."
    set iGenerique [string length $Generique]
    set LesOrgasPossibles {}
    foreach Fichier [glob -nocomplain "$RepertoireDuGenome/fiches/$Generique*"] {
	set Orga [string range [file tail $Fichier] $iGenerique end]
	lappend LesOrgasPossibles $Orga
    }
    set Orga [ChoixParmi $LesOrgasPossibles]
    set Fichier "$RepertoireDuGenome/fiches/$Generique$Orga"
    if { ! [file exists $Fichier]} { return }
    DessineOrgaEtSesPlaces $Fichier
}

proc CopieLesBonsDisphy {} {
    global RepertoireDuGenome

    foreach Nom [ListeDesPABs] {
	set PhyFaux "$RepertoireDuGenome/phylos.faux/$Nom"
	set PhyBon  "$RepertoireDuGenome/phylos/$Nom"
	set DisFaux "$RepertoireDuGenome/disphy.faux/$Nom"
	set DisBon  "$RepertoireDuGenome/disphy/$Nom"

	if { ! [file exists $PhyFaux]} { continue }

	if {[ContenuDuFichier $PhyFaux]==[ContenuDuFichier $PhyBon]} {
	    if { ! [file exists $DisFaux]} { continue }
	    File copy $DisFaux $DisBon
	    continue
	}
    }
}

proc CreeDistancesPhyloAvecLesMSFs {{ReferenceVoulue ""} {Extension ""}} {
    global RepertoireDuGenome
    global ListeDesPABs
    global NotreOS

    if {$ReferenceVoulue == ""} { set ReferenceVoulue [Glossaire $NotreOS Court] } 
    if {$Extension == ""} { set Extension ".$ReferenceVoulue" } 

    set ReferenceVoulue [string toupper $ReferenceVoulue]

    if { ! [info exists ListeDesPABs]}  { ChargeLesPABs }

    set KeepDisphy 1
    set SauveDansDisphy 1
    set NotreOsEstLaReference 0
    if {[string toupper $ReferenceVoulue] == [string toupper [Glossaire $NotreOS Court]]} {
	set NotreOsEstLaReference 1
	set DisphyDir "$RepertoireDuGenome/disphy"
	if { ! [file exists $DisphyDir]} { File mkdir $DisphyDir }
	set SauveDansDisphy 1 
	if {[llength [glob -nocomplain "$DisphyDir/*"]] > 0} {
	    set KeepDisphy [OuiOuNon "Some files already exist in $DisphyDir\nDo I keep them ? "]
	}
    }

    set FichierDistancesPhylo "$RepertoireDuGenome/fiches/distancesphylo$Extension"
    while {[file exists $FichierDistancesPhylo]} {
	if {[OuiOuNon "$FichierDistancesPhylo\n  already exists. Do I replace it ? " 0]} {
	    File delete $FichierDistancesPhylo
	} else {
	    if {[OuiOuNon "Do I append to it ? "]} {
		foreach Ligne [LesLignesDuFichier $FichierDistancesPhylo] {
		    scan $Ligne "%s" Nom
		    set DejaVu($Nom) 1
		}
		break
	    } else {
		if {[OuiOuNon "Do I cancel ? "]} { return "" }
	    }
	}
    }
    
    foreach Nom $ListeDesPABs {
	Espionne $Nom
	if {[info exists DejaVu($Nom)]} { continue }
	set FichierPhylo  "$RepertoireDuGenome/phylos/$Nom"
	set FichierDisphy "$RepertoireDuGenome/disphy/$Nom"
	Wup "On peut ne pas avoir cree les fichiers phylos, alors on le fait ici."
	if { ! [file exists $FichierPhylo]} {
	    Espionne "Creation de phylo pour $Nom"
	    Wup "J'en cree qu'un, pas plusieurs ..."
	    CreeLesFichiersPhylos $Nom
	}
	if { ! [file exists $FichierPhylo]} {
	    Warne "$FichierPhylo couldn't be created"
	    continue
	}
	
	if {$NotreOsEstLaReference} {
	    set Reference $Nom
	} else {
	    set Reference [TrouveLaReferenceVoulue $ReferenceVoulue $FichierPhylo]
	}


	if {$KeepDisphy && $NotreOsEstLaReference && [file exists $FichierDisphy]} {
	    set ListeTriee [LesLignesDuFichier $FichierDisphy]
	} else {
	    set ListeTriee [ListeTrieeDesDistancesPhylos $Nom $Reference]
	    if {$SauveDansDisphy} {
		if { ! [file exists $FichierDisphy] || ! $KeepDisphy } {
		    Espionne "Creation de disphy pour $Nom"
		    SauveLesLignes $ListeTriee dans "$RepertoireDuGenome/disphy/$Nom"
		}
	    }
	}
#	lappend Sortie "$Nom [join $ListeTriee " "]"
	AppendAuFichier $FichierDistancesPhylo "$Nom [join $ListeTriee " "]"
    }
    return $FichierDistancesPhylo
}

proc ListeTrieeDesDistancesPhylos {Nom Reference {Arbre ""}} {
    global RepertoireDuGenome
    global ListeDistanceDeChaqueFeuille
    global NotreOS

    set FichierPhylo "$RepertoireDuGenome/phylos/$Nom"
    Wup "On peut ne pas avoir cree les fichiers phylos"
    if { ! [file exists $FichierPhylo]} {
	Wup "J'en cree qu'un, pas plusieurs ..."
	CreeLesFichiersPhylos $Nom
    }
    if { ! [file exists $FichierPhylo]} {
	Warne "$FichierPhylo couldn't be created"
	return {}
    }

    set ListeDistanceDeChaqueFeuille {}

    catch {unset SortieSeqDist}
    catch {set SortieSeqDist [split [exec seqdist $FichierPhylo $Reference] "\n"]}

    if { ! [info exists SortieSeqDist]} {
	Warne "seqdist did'nt success with $FichierPhylo $Reference"
	return {}
    }

    if {[llength $SortieSeqDist] == 0} { return {} }

    foreach Ligne $SortieSeqDist {
	if {[scan $Ligne "%s %s %s %f" Cible to Feuille Distance]!=4 } { continue }
	lappend ListeSeqDistDeChaqueFeuille "$Feuille $Distance"
    }

    set ListeTrieeSD [lsort  -command "CompareLesFloats" $ListeSeqDistDeChaqueFeuille]

    Wup "On demande tous les Orgas en une seule fois"
    set LesAccess {}
    foreach FeuilleDistance $ListeTrieeSD {
	scan $FeuilleDistance "%s %f" Feuille DistanceFloat
	lappend LesAccess $Feuille
    }
    foreach AccessOrga [LesOrgasDesAccess $LesAccess Court] {
	Espionne $AccessOrga
	set Orga "iinc"
	scan $AccessOrga "%s %s" Access Orga
	set OrgaDuAccess($Access) $Orga
    }

    set ListeOrgaDistance {}
    foreach FeuilleDistance $ListeTrieeSD {
	Wup "Je stocke les distances en INTEGER de 0 a 100"
	scan $FeuilleDistance "%s %f" Feuille DistanceFloat
	set Access $Feuille
	if {[llength $ListeTrieeSD] == 1} { set DistanceFloat [expr $DistanceFloat/2] }
	set Distance [expr round(100*$DistanceFloat)]
	if {[info exists OrgaDuAccess($Access)]} {
	    set Orga [set OrgaDuAccess($Access)]
	} else {
	    set Orga [Glossaire "Inconnu inconnu" Court]
	}
	foreach O [SplitOrgas $Orga] {
	    lappend ListeOrgaDistance "$O $Distance $Access"
	}
    }
    
    return $ListeOrgaDistance
}

proc CopieLesPH {} {
    global RepertoireDuGenome
    foreach Fichier [LesLignesDuFichier "$RepertoireDuGenome/listedesph.fof"] {
	if { ! [regexp -nocase {[a-z0-9]} $Fichier]} { continue }
	set AA [string range [file tail $Fichier] 0 2]
	set Destin "$RepertoireDuGenome/phylos/[AutreCode $AA]"
	if {[file exists $Destin]} { continue }
	Espionne " copy -force $Fichier $Destin"
	File copy -force $Fichier $Destin
    }
}

proc AutreCode X {
    global RepertoireDuGenome
    global AutreCode

    if { ! [info exists AutreCode]} {
	foreach Ligne [LesLignesDuFichier "$RepertoireDuGenome/fiches/lookup"] {
	    scan $Ligne "%s %s" Nom AA
	    set AutreCode($Nom) $AA
	    set AutreCode($AA)  $Nom
	}
    }
    return [set AutreCode($X)]
}

proc Scrunch Sequence {
    regsub -all {\.|\~} $Sequence "" Sequence
    return $Sequence
}

proc OrgApprochant {Genre Espece} {

    if {[regexp -nocase "^sacc" $Genre]} { set Genre "Schizosacc" }

    set LesOrgApprochants {}

    set LaCommandeOrgApprochantExiste 1
    if {$LaCommandeOrgApprochantExiste} {
	catch {set LesOrgApprochants [split [eval exec orgapprochant $Genre $Espece] "\n"]}
    } else {
	foreach Texte [Glossaire "ListOf" "Complet"] {
	    scan $Texte "%s %s" Genre Espece
	    if {[regexp -nocase "^$Gen" $Genre] && [regexp -nocase "^$Esp" $Espece]} {
		set Organisme "$Genre $Espece"
		lappend LesOrgApprochants $Organisme
	    }
	}
    }

    if {[llength $LesOrgApprochants] == 1} { return [lindex $LesOrgApprochants 0]}

    if {0 && [llength $LesOrgApprochants] > 1} {
	foreach Organisme $LesOrgApprochants {
	    scan $Organisme "%s %s" G E
	    if {[regexp -nocase "^$Genre" $G] && [regexp -nocase "^$Espece" $E]} {
		return $Organisme
	    }
	}
    }

    while {[llength $LesOrgApprochants] != 1} {
#	set Organisme "$Genre $Espece"
	set Organisme [ChoixParmi [concat [list "$Genre $Espece" "... other" "Unknown unknown"] $LesOrgApprochants]]
	if {$Organisme=="... other"} { set Organisme [Entre "$Genre $Espece"] }
	if {$Organisme==""} { set Organisme "Unknown unknown" }
	set LesOrgApprochants [list $Organisme]
    }
    return [lindex $LesOrgApprochants 0]
}

proc CreeUnFichierEMBL {AA3 Organisme AA1 Sequence {Extension ""}} {

    set Sortie {}
    scan $Organisme "%s %s" Genre Espece
    set Gen_esp ""
    append Gen_esp [string toupper [string range $Genre 0 0]]
    append Gen_esp [string tolower [string range $Genre 1 2]]
    append Gen_esp "_[string tolower [string range $Espece 0 2]]"
 
    set Access "${AA1}_${Gen_esp}$Extension"

    lappend Sortie "ID   $Access; cree par rR d'apres un MSF egare."
    lappend Sortie "AC   $Access"
    lappend Sortie "DE   ${AA3}rs"
    lappend Sortie "OS   $Organisme"
    lappend Sortie "OC   [OCduOS $Organisme]"
    lappend Sortie [QueSequenceFormatEMBL $Sequence "AvecSQ"] 
    return $Sortie
}

proc UT X {
    global UT

    if {[string length $X]==1} {
	set X [string toupper $X] 
    } else { 
	set X [string tolower $X]
    } 

    if {$X=="ace"} { return "" }

    if { ! [info exists UT]} {
	set UT(ala) A
	set UT(glu) E
	set UT(gln) Q
	set UT(trp) W
	set UT(phe) F
	set UT(pha) F
	set UT(phb) f
	set UT(tyr) Y
	set UT(cys) C
	set UT(met) M
	set UT(ser) S
	set UT(lys) K
	set UT(ly1) k
	set UT(leu) L
	set UT(val) V
	set UT(ile) I
	set UT(asp) D
	set UT(thr) T
	set UT(his) H
	set UT(arg) R
	set UT(pro) P
	set UT(gly) G
	set UT(gla) J
	set UT(glb) j
	set UT(asn) N

	foreach {Y ValUT} [array get UT] {
	    set UT($ValUT) $Y 
	}
	set UT(csy) C
	set UT(asi) [set UT(asn)]
	set UT(aya) [set UT(ala)]
	set UT(cea) [set UT(cys)]
	set UT(cme) [set UT(cys)]
	set UT(cro) [set UT(ser)]
	set UT(csd) [set UT(cys)]
	set UT(css) [set UT(cys)]
	set UT(csw) [set UT(cys)]
	set UT(cxm) [set UT(met)]
	set UT(glh) [set UT(glu)]
	set UT(hic) [set UT(his)]
	set UT(hph) [set UT(phe)]
	set UT(kcx) [set UT(lys)]
	set UT(mho) [set UT(met)]
	set UT(mse) [set UT(met)]
	set UT(mso) [set UT(met)]
	set UT(nep) [set UT(his)]
	set UT(oas) [set UT(ser)]
	set UT(omt) [set UT(met)]
	set UT(pca) [set UT(gln)]
	set UT(sac) [set UT(ser)]
	set UT(tpo) [set UT(thr)]
    }
    if {[info exists UT($X)]} { return [set UT($X)] }
    if {[string length $X]==1} { return XXX }
    if {[string length $X]==3} { return x }
    return $X
}

proc AADuNomDuFichier {NomDuFichier {AvecAlias "AvecAlias"}} {
    global AAAlias

    if { ! [info exists AAAlias] } {
	set AAAlias(ly1) lys
	set AAAlias(ly2) lys
	set AAAlias(pha) phe
	set AAAlias(phb) phe
	set AAAlias(gla) gly
	set AAAlias(glb) gly
    }
    set AA3 [string range $NomDuFichier 0 2]
    if { $AvecAlias != "AvecAlias" && [info exists AAAlias($AA3)]} {
	return [set AAAlias($AA3)]
    } else {
	return $AA3
    }
}

proc ClasseCanonique OC {
    set OrigOC $OC
    regsub -all "ARCHAEBACTERIA;" $OC "ARCHAEA;" OC
    regsub -all "BACILLACEAE;" $OC "BACILLUS/STAPHYLOCOCCUS GROUP;" OC
    regsub "; PTERYGOTA; LEPIDOPTERA;" $OC "; PTERYGOTA; NEOPTERA; ENDOPTERYGOTA; LEPIDOPTERA;" OC
    regsub "; PTERYGOTA; DIPTERA;" $OC "; PTERYGOTA; NEOPTERA; ENDOPTERYGOTA; DIPTERA;" OC
    regsub "; PTERYGOTA; COLEOPTERA;" $OC "; PTERYGOTA; NEOPTERA; ENDOPTERYGOTA; COLEOPTERA;" OC
    return "$OC"
}

proc QueryDuFichierBlast Fichier {
    set LesLignes [LesLignesDuFichier $Fichier]
    foreach Ligne [lrange $LesLignes 0 20] {
	if {[regexp "Query=" $Ligne]} {
	    scan $Ligne "%s %s" Bidon Query 
	    return $Query
	}
    }
    return ""
}

proc AfficheLesCouleursEtSignifications K {
    global TypeCouleur

    set LesNomSignif [LesSignificationsAssocieesAuxORFs $K]

    set OldSignif "trululuyoupiii"
    set LaSortie {}
    foreach Ligne $LesNomSignif {
	scan $Ligne "%s" Nom
	set Signif [StringSuivant " " dans $Ligne]
	if {$Signif!=$OldSignif} { set N 0 }
	lappend LaSortie "$Nom [incr N] $Signif"
	set OldSignif $Signif
    }
    return [AfficheVariable [join $LaSortie "\n"] "AvecShow"] 
}

proc CreeLeFichierAssocieAuxCouleurs {K {Fichier ""}} {
    global TypeCouleur

    set LesNomSignif [LesSignificationsAssocieesAuxORFs $K]

    if {$Fichier==""} {
	set Fichier [FichierPourSaveAs "[RepertoireDeTravail]/[set TypeCouleur($K)].lst"]
	if {$Fichier==""} { return "" }
    }
    return [SauveLesLignes $LesNomSignif dans "$Fichier"]
}

proc LesSignificationsAssocieesAuxORFs K {
    global TypeCouleur

    set TypeDeCouleur [set TypeCouleur($K)]
    
    foreach Nom [ListeDesPABs] {
	set Couleur [CouleurParTypeEtNom $TypeDeCouleur $Nom $K]	
	lappend LesNomSignif "$Nom [GetSignification $Couleur $K]"
    }
    set LesNomSignif [lsort -command CompareSansPremierChamp $LesNomSignif]

    return $LesNomSignif
}

proc TestDecortiqueBlast {{Nom ""}} {
    global RepertoireDuGenome
    global ListeDesPABs


    if { $Nom == "" } {
	ChargeListeDeBoites
	set Liste $ListeDesPABs
    } else {
	set Liste [list $Nom]
    }

    foreach Nom $Liste {
	set FichierBlastP "$RepertoireDuGenome/blastp/$Nom"
	set lPartieSegAli {}
#	DecortiqueBlast $FichierBlastP "SansSeuilExpect" "SansLimiteDeNombre" Query lBanqueId lAccess lDE lProfil lPN lPartieSegAli
	DecortiqueBlast $FichierBlastP "SansSeuilExpect" "SansLimiteDeNombre" Query lBanqueId lAccess lDE lProfil lPN
	foreach BanqueId $lBanqueId Access $lAccess DE $lDE Profil $lProfil PN $lPN SegAli $lPartieSegAli {
#	    puts "$BanqueId $Access $DE $Profil $PN \n$SegAli"
	    puts "$BanqueId $Access $DE"
	}
	continue
	set FichierBlast "$RepertoireDuGenome/blastngenembl/$Nom"
	if { ! [file exists $FichierBlast]} { continue }
	DecortiqueBlast $FichierBlast \
		0.001 5 Query lBanqueId lAccess lDE lProfil lPN
	foreach BanqueId $lBanqueId Access $lAccess DE $lDE Profil $lProfil PN $lPN {
	    Espionne "$Nom $BanqueId $Access $DE $Profil $PN"
	    set LeEMBL [LaSequenceDesBanques $BanqueId $Access a "OnVeutNucEMBL"]
	    if {$LeEMBL=={}} {
	    } else {
		EspionneL $LeEMBL
		break
	    }
	}
	Espionne ""
	continue

	set FichierBallast "$RepertoireDuGenome/ballast/$Nom"
	if { ! [file exists $FichierBallast]} { continue }
	set FichierBlastP "$RepertoireDuGenome/blastp/$Nom"
	DecortiqueBlast $FichierBallast \
		"SansSeuilExpect" "SansLimiteDeNombre" Query lBanqueId lAccess lDE lProfil lPN
	foreach BanqueId $lBanqueId Access $lAccess DE $lDE Profil $lProfil PN $lPN {
	    puts "$BanqueId $Access $DE $Profil $PN"
	}
	DecortiqueBlast $FichierBlastP \
		"SansSeuilExpect" "SansLimiteDeNombre" Query lBanqueId lAccess lDE lProfil lPN
	foreach BanqueId $lBanqueId Access $lAccess DE $lDE Profil $lProfil PN $lPN {
	    puts "$BanqueId $Access $DE $Profil $PN"
	}
    }
    exit
}

proc LaLigneAPnOsOc {Nom Candidat} {
    global RepertoireDuGenome
    global LesLignesAPnOsOc NomDuAPnOsOcCourant

    scan $Candidat "%s %s %f" BanqueId Access PN

    if { ! [info exists NomDuAPnOsOcCourant] || $NomDuAPnOsOcCourant != $Nom } {
	set FichierAPnOsOc "$RepertoireDuGenome/apnosoc/$Nom"
	if { ! [file exists $FichierAPnOsOc]} {
	    set LesLignesAPnOsOc {}
	}
	set LesLignesAPnOsOc [LesLignesDuFichier $FichierAPnOsOc]
	set NomDuAPnOsOcCourant $Nom
    }
    set Ieme [lsearch -regexp $LesLignesAPnOsOc "$BanqueId $Access"]
    if { $Ieme < 0 } { return "" }
    return [lindex $LesLignesAPnOsOc $Ieme]
}

proc OnGardeCommeNouvelOrganisme {OS {Controle "SansDemander"}} {
    global RepertoireDuGenome
    global NouvelOrganisme

    set FichierNouveauxOrganismes "$RepertoireDuGenome/fiches/nouveauxorganismes"

    if { ! [info exists NouvelOrganisme]} {
	set NouvelOrganisme(RIPPUS_RAYMONDII) 1
	if {[file exists "$FichierNouveauxOrganismes"]} {
	    foreach Ligne [LesLignesDuFichier "$FichierNouveauxOrganismes"] {
		set NouvelOrganisme($Ligne) "lu"
	    }
	}
    }

    set OS [string toupper $OS]
    if {[info exists NouvelOrganisme($OS)]} { return $OS }

    if { $Controle == "EnDemandant"} {
	if {! [OuiOuNon "Can I keep \n$OS \n as organism name ?" 0]} {
	    return ""
	}
	while { ! [regexp {^[A-Z]+ [A-Z]+} $OS] } {
	    if {[OuiOuNon "$OS \n contains wrong characters, I forget it ?"]} { return "" }
	    set OS [Entre $OS]
	} 
    } 
    set GloOS [Glossaire $OS Complet]
    if {$GloOS != "" } { Espionne "$GloOS existe, je suis content." ; return $GloOS }
    AppendAuFichier "$FichierNouveauxOrganismes" $OS
    set NouvelOrganisme($OS) "cree"
    return $OS
}

proc OrganismeCanonique {OS {Controle "Stricte"}} {
    global DejaTraite

    set OriginalOS $OS

    set NePasDemanderPourRaccourcir [expr [string equal $Controle "NonStricte"]]
    set NePasDemanderPourRallonger  [expr [string equal $Controle "NonStricte"]]

    regsub -all {\,} $OS " " OS
    regsub -all {\.} $OS " " OS
    regsub -all {\;} $OS " " OS
    while {[regexp "  " $OS]} { regsub -all "  " $OS " " OS }
    set OS [string trim $OS]

    set iParenthese [string first "(" $OS]
    if {$iParenthese!=-1} {
	set OS [string trim [string range $OS 0 [expr $iParenthese - 1]]] 
    }

    set LesMots [split [string trim $OS] " "]

    Wup " ............................................ cas connus et nouveaux acceptes."

    set PremierMot [lindex $LesMots 0]
    if {[llength $LesMots] == 1 && [regexp -nocase "VIRUS" $PremierMot]} {
	set LesMots [list VIRUS $PremierMot]
    }
    if {[llength $LesMots] == 1 && $Controle=="Sommaire"} {
	if {[regexp -nocase "^Xenopus$" $PremierMot]} { return "Xenopus laevis" }
	return "$PremierMot $PremierMot"
    }


    if {[llength $LesMots] == 2} {
	if {$Controle=="Sommaire"} { return [join $LesMots " "] }
	set Orga [Glossaire $OS Complet]
	if {$Orga != ""} { return $Orga }
	if {$Controle == "Stricte"} {
	    return [OnGardeCommeNouvelOrganisme $OS "EnDemandant"]
	}
	Wup "Attention on accepte tel quel."
	if {$Controle == "NonStricte"} {
	    OnGardeCommeNouvelOrganisme $OS "SansDemander"
	    return $OS
	}
    }

    Wup "Homo sapiens sapiens"
    if {[llength $LesMots] == 3 && [lindex $LesMots 1] == [lindex $LesMots 2]} {
	set OS [join [lrange $LesMots 0 1] " "]
	if {$Controle=="Sommaire"} { return $OS }
	set Orga [Glossaire $OS Complet]
	if {$Orga != ""} { return $Orga }
	if {$Controle == "Stricte"} {
	    return [OnGardeCommeNouvelOrganisme $OS "EnDemandant"]
	}
	Wup "Attention on accepte tel quel."
	if {$Controle == "NonStricte"} {
	    OnGardeCommeNouvelOrganisme $OS "SansDemander"
	    return $OS
	}
    }

    if {[llength $LesMots] > 2} {
	if {$Controle == "NonStricte" && [info exists DejaTraite($OriginalOS)]} {
	    return [set DejaTraite($OriginalOS)]
	}

	if {[regexp -nocase "VIRUS" $OS]} {
	    set LesMots [linsert $LesMots 0 "VIRUS"]
	}

	if {[regexp -nocase "ENDOSYMBIONT" $OS]} {
	    set LesMots [linsert $LesMots 0 "ENDOSYMBIONT"]
	}

	if {[regexp -nocase "ENDOBACTERIUM" $OS]} {
	    set LesMots [linsert $LesMots 0 "ENDOSYMBIONT"]
	}

	set UnEtDeux [join [lrange $LesMots 0 1] " "]
	if {$Controle=="Sommaire"} { return $UnEtDeux }
	if {$NePasDemanderPourRaccourcir || [OuiOuNon "Can I take $UnEtDeux\nfrom $OriginalOS ?"]} {
	    set Orga $UnEtDeux
	    set DejaTraite($OriginalOS) $Orga
	} else {
	    set Orga [string trim [Entre "$OriginalOS"]]
	}
    } else {
	if {$NePasDemanderPourRallonger} {
	    set Orga "Unknown $OS"
	} else {
	    set Orga [string trim [Entre "$OriginalOS"]]
	}
    }
    if {$Controle == "Stricte"} {
	return [OnGardeCommeNouvelOrganisme $Orga "EnDemandant"]
    }
    if {$Controle == "NonStricte"} {
	OnGardeCommeNouvelOrganisme $Orga "SansDemander"
	return $Orga
    }
    return [string trim $OriginalOS]
}

proc FindPatternDansADNetRAC Pattern {
    global ADN TDN RAC

    if { ! [info exists ADN]} { ChargeADNetTDNetRAC }

    set PatternPourRegexp $Pattern
    regsub -all {[oO]} $PatternPourRegexp "\[GC\]" PatternPourRegexp
    regsub -all {[iI]} $PatternPourRegexp "\[AT\]" PatternPourRegexp
    regsub -all {[nN]} $PatternPourRegexp "\[ATGCX\]" PatternPourRegexp

    set Courant 0
    while {[regexp -nocase -indices $PatternPourRegexp [string range $ADN $Courant end] Indices]} {
	foreach {Debut Fin} $Indices {
	    incr Debut $Courant
	    incr Fin   $Courant
	    puts "F [string range $ADN [expr $Debut-6] [expr $Debut -1]] \
		    [string range $ADN [expr $Debut]   [expr $Fin]] \
		    [string range $ADN [expr $Fin+1]   [expr $Fin+6]] $Debut $Fin"
	}
	set Courant [incr Debut 1]
    }

    set lRAC [string length $RAC]

    set Courant 0
    while {[regexp -nocase -indices $PatternPourRegexp [string range $RAC $Courant end] Indices]} {
	foreach {Debut Fin} $Indices {
	    incr Debut $Courant
	    incr Fin   $Courant
	    puts "R [string range $RAC [expr $Debut-6] [expr $Debut - 1]] \
		    [string range $RAC [expr $Debut]   [expr $Fin]] \
		    [string range $RAC [expr $Fin+1]   [expr $Fin+6]] \
		    [expr $lRAC - $Debut] [expr $lRAC - $Fin]"
	}
	set Courant [incr Debut 1]
    }

}

proc MiseAJourDesFichiersApns {{NomVoulu ""}} {
    global RepertoireDuGenome

    Wup "Updates the lines where no organism was found"
    Wup "Updates if < SeuilExpect and 250 first one only"
    
    set SeuilExpect 0.001
    scan [TailleSortiePourDBClustal] "%d %d" MinObliges MaxVoulus
    set MaxListe {Maxi 250 [expr 3*$MaxVoulus]}


    if { ! [file exists "$RepertoireDuGenome/apns_maj"]} { File mkdir "$RepertoireDuGenome/apns_maj" }

    if {$NomVoulu==""} {
	set Liste [ListeDesPABs]
    } else {
	set Liste [list $NomVoulu]
    }

    foreach Nom $Liste {
	Espionne "Je mets a jour les cops de $Nom"

	set FichierAPNs    "$RepertoireDuGenome/apns/$Nom"
	if { ! [file exists $FichierAPNs]} { continue }

	set FichierNouveau "$RepertoireDuGenome/apns_maj/$Nom"
	if {[file exists $FichierNouveau]} { continue }

	set nLu 0
	set LesAccess {}
	foreach Ligne [LesLignesDuFichier $FichierAPNs] {
	    scan $Ligne "%s %s %s" BanqueId Access Expect
	    incr nLu
	    lappend LesAccess $Access
	    set GEs ""
	    regsub " *$BanqueId +$Access +$Expect *" $Ligne "" GEs
	    if { ! [regexp -nocase {[a-z]} $GEs]} { continue }
	    set OrgaTrouve([string toupper $Access]) $GEs
	}
	foreach AGEs [LesOrgasDesAccess $LesAccess] {
	    scan $AGEs "%s" A
	    regsub "$A " $AGEs "" GEs
	    regsub {(^|\:)Inconnu inconnu($|\:)} $GEs "" GEs
	    if {$GEs==""} { continue }
	    set OrgaTrouve([string toupper $A]) $GEs
	}
	set MesOrgas {}
	set nLu 0
	foreach Ligne [LesLignesDuFichier $FichierAPNs] {
	    scan $Ligne "%s %s %f" BanqueId Access Expect
	    if {[EstUnAccessPDB $BanqueId]} { continue }
	    set ACCESS [string toupper $Access]
	    set Orgas ""
	    if {[info exists OrgaTrouve($ACCESS)]} {
		set Orgas [set OrgaTrouve($ACCESS)]
	    } else {
		if {$Expect <= $SeuilExpect && $nLu <= $MaxListe && ! [EstUnAccessPDB $Access]} {
		    set Orgas [OrgaDuAccess $Access Complet $BanqueId]
		    if {$Orgas!=""} {
			Espionne "          J'ai trouve pour $Nom $Orgas"
		    }
		}
	    }
	    AppendAuFichier $FichierNouveau "$BanqueId $Access $Expect $Orgas"	
	}
    }
    return
}

proc CreeLesFichiersApns {{RepertoireDesBlasts "blastp"} {RepertoireDesAPns ""}} {
    global RepertoireDuGenome

    if { ! [file exists "$RepertoireDuGenome/$RepertoireDesBlasts"] || $RepertoireDesAPns=="" } {
	switch -regexp $RepertoireDesBlasts {
	    "blastp" {
		set DirDesBlasts "$RepertoireDuGenome/blastp"
		set DirDesApns "$RepertoireDuGenome/apns"
	    }
	    "blastn" {
		set DirDesBlasts "$RepertoireDuGenome/blastn"
		set DirDesApns "$RepertoireDuGenome/apns"
	    }
	    "trouxs" {
		set DirDesBlasts "$RepertoireDuGenome/trousblastx"
		set DirDesApns "$RepertoireDuGenome/trouxsapns"
	    }
	    "trouns" {
		set DirDesBlasts "$RepertoireDuGenome/troustblastxgenembl"
		set DirDesApns "$RepertoireDuGenome/trounsapns"
	    }
	    "trous"  {
		set DirDesBlasts "$RepertoireDuGenome/trousblastp"
		set DirDesApns "$RepertoireDuGenome/trousapns"
	    }
	    default  {
		set DirDesBlasts "$RepertoireDesBlasts"
		if {[file isdirectory "$RepertoireDesAPns"]} {
		    set DirDesApns   "$RepertoireDesAPns"
		} elseif {[file isdirectory "$RepertoireDuGenome/$RepertoireDesAPns"]} {
		    set DirDesApns   "$RepertoireDuGenome/$RepertoireDesAPns"
		} elseif {[OuiOuNon "Should I create $RepertoireDuGenome/$RepertoireDesAPns"]} {
		    set DirDesApns   "$RepertoireDuGenome/$RepertoireDesAPns"
		} else {
		    FaireLire "Please create the correct directory $RepertoireDesAPns"
		    return "RepertoireDesAPns inexistant"
		}
	    }
	}
    } else {
	if {[file exists "$RepertoireDesBlasts"] && [file exists "$RepertoireDesAPns"]} {
	    set DirDesBlasts "$RepertoireDesBlasts"
	    set DirDesApns   "$RepertoireDesAPns"
	} else {
	    FaireLire "Please create the correct directory $RepertoireDesAPns"
	    return "RepertoireDesAPns inexistant"
	}
    }

    File mkdir "$DirDesApns"

    set Conserve 0
    if {[llength [glob -nocomplain "$DirDesApns/*"]] > 0} {
	set Conserve [OuiOuNon "Should I keep the existing files in $DirDesApns ?"]
    }

    foreach FichierBlast [lsort [glob -nocomplain "$DirDesBlasts/*"]] {

	set Nom [file tail $FichierBlast]

	if { ! [YaPABouTROUouTRNAouARNenDebutDe $Nom] || [regexp ".encours" $Nom]} { continue }

	set FichierACreer "$DirDesApns/$Nom"

	if {$Conserve && [file exists $FichierACreer]} { continue }

	set lBanqueId {}
	DecortiqueBlast $FichierBlast \
		"SansSeuilExpect" "SansLimiteDeNombre" Query lBanqueId lAccess lDE lProfil lPN
	set ListeAPN {}
	
	if {[file tail $RepertoireDesBlasts]=="blastp"} {
	    foreach AGEs [LesOrgasDesAccess $lAccess] {
		scan $AGEs "%s" A
		regsub "$A " $AGEs "" GEs
		regsub {(^|\:)Inconnu inconnu($|\:)} $GEs "" GEs
		if {$GEs==""} { continue }
		set OrgaTrouve([string toupper $A]) $GEs
	    }
	}
	foreach BanqueId $lBanqueId Access $lAccess PN $lPN {
	    if {[file tail $RepertoireDesBlasts]=="blastn"} {		
		set Ligne "$BanqueId $BanqueId $PN"
	    } else {
		set Ligne "$BanqueId $Access $PN"
		if {[info exists OrgaTrouve([string toupper $Access])]} {
		    append Ligne " [set OrgaTrouve([string toupper $Access])]"
		}
	    }
	    lappend ListeAPN $Ligne
	}
	Espionne [SauveLesLignes $ListeAPN dans $FichierACreer]
    }
}

proc CorrigeUneExpressionDansLesInfos {Old New {Confirmation "SansConfirmation"}} {
    global RepertoireDuGenome

    set SansConfirmation [string compare $Confirmation "AvecConfirmation"]

    foreach Fichier [glob "$RepertoireDuGenome/infos/*"] {
	set Nom [file tail $Fichier]
	set LesNouvellesLignes {}
	set YaModif 0
	foreach Ligne [LesLignesDuFichier $Fichier] {
	    if {[regexp $Old $Ligne]} {
		if {$SansConfirmation || [OuiOuNon "Je corrige $Nom\n$Ligne\n  ?"]} {
		    set YaModif 1
		    regsub $Old $Ligne $New Ligne
		}
	    }
	    lappend LesNouvellesLignes $Ligne
	}
	if {$YaModif} {
	    Espionne [SauveLesLignes $LesNouvellesLignes dans $Fichier]
	}
    }
}

proc LesOrganismesTresProches {{Organisms ""}} {
    global RepertoireDuGenome
    global LesOrganismesTresProches
    global DemandeDejaFaite
    global Org1 Org2
    
    #rR a rajoute Organisms pour pouvoir le faire taire (pour SM2PH surtout)
    if {$Organisms!=""} { set LesOrganismesTresProches $Organisms } 

    if {[info exists LesOrganismesTresProches]} {  return $LesOrganismesTresProches }

    if {[PourWscope]} { return {} }

    if {[info exists Org1] && [info exists Org2]} {
	if { ! [info exists LesOrganismesTresProches]} {
	    set LesOrganismesTresProches [list $Org1 $Org2]
	}
	return $LesOrganismesTresProches
    }
    
    set Org1 "    "
    set Org2 "    "

    if {[OnTraiteUneCollection]} { return {}}

    set RepertoireFiches "$RepertoireDuGenome/fiches"
    if { ! [file exists $RepertoireFiches]} {
	File mkdir $RepertoireFiches
    }
    
    if { ! [info exists LesOrganismesTresProches]} {
	set Fichier "$RepertoireDuGenome/fiches/lesorganismestresproches"
	if { [info exists DemandeDejaFaite] && ! [file exists $Fichier]} {
	    return {}
	}
	while { ! [file exists $Fichier]} {
	    if { ! [OuiOuNon "Do You want to give the two nearest organisms ?" 0]} {
		set DemandeDejaFaite 1
		if {[OuiOuNon "Do I ask later ?"]} { return {} }
		Sauve "Aaaa\nBbbb" dans $Fichier
	    } else {
		FaireLire "You have to select 2 organisms.\nThe first one ..."
		scan [MontreOrganismes "AvecRetour"] "%s %s %s" Orga Genre Espece
		set Orga [Glossaire "$Genre $Espece" Court]
		lappend LesOrganismesTresProches $Orga
		FaireLire "The second one ..."
		scan [MontreOrganismes "AvecRetour"] "%s %s %s" Orga Genre Espece
		set Orga [Glossaire "$Genre $Espece" Court]
		lappend LesOrganismesTresProches $Orga
		SauveLesLignes $LesOrganismesTresProches dans $Fichier
	    }
	}
	set LesOrganismesTresProches [LesLignesDuFichier $Fichier]
    }
    
    set Org1 [lindex $LesOrganismesTresProches 0]
    set Org2 [lindex $LesOrganismesTresProches 1]

    return $LesOrganismesTresProches
}

proc LesEntetesChevronneesDuBlast {Page {GetWhat ""} {Titre ""}} {

    if { ! [regexp "\n" $Page]} {
	set Fichier $Page
	if {[EstUnPAB $Fichier]} {
	    if {[FileAbsent $Fichier]} { set Fichier [GscopeFile $Fichier "blastp"] }
	    if {[FileAbsent $Fichier]} { set Fichier [GscopeFile $Fichier "blastn"] }
	}
	if {[FileAbsent $Fichier]} { return "" }
	set Page [ContenuDuFichier $Fichier]
    }

    if {$GetWhat==""} { set GetWhat "GetHeaders" }
    set OnAttendChevron 1
    set OnAttendFinEntete 0
    set OnAFiniLePremier 0
    foreach Ligne [split $Page "\n"] {
	if {$OnAttendChevron && [regexp {^>} $Ligne]} {
	    set Entete $Ligne
	    set OnAttendChevron 0
	    set OnAttendFinEntete 1
	    continue
	}
	if {$OnAttendFinEntete} {
	    if {[regexp {^ {10}Length =} $Ligne]} {
		set OnAttendFinEntete 0
		set OnAttendChevron 1
		regsub -all { +} $Entete " " Entete
		set OnAFiniLePremier 0
	    } else {
		append Entete " $Ligne"
	    }
	    continue
	}
	if { ! $OnAFiniLePremier && [regexp {^ Score = } $Ligne]} {
	    set Expect [PNApres "Expect = " dans $Ligne]
	    lappend LesScoreExpect $Ligne
	}
	if { ! $OnAFiniLePremier && [regexp {^ Identities = } $Ligne]} {
	    lappend LesIdentities $Ligne
	    lappend LesEntetes "[string trim $Entete] Expect=$Expect"
	    set OnAFiniLePremier 1
	}
    }
    if {$GetWhat=="GetHeaders"}     { return $LesEntetes }
    if {$GetWhat=="GetScoreExpect"} { return $LesScoreExpect }
    if {$GetWhat=="GetIdentities"}  { return $LesIdentities }
    if {$GetWhat=="GetAll"}         { return [list $LesEntetes $LesScoreExpect $LesIdentities]}
    if {$Titre==""} { set Titre "Headers" } 
    return [AfficheVariable [join $LesEntetes "\n"] "AvecFetch" $Titre]
}

proc AfficheAliEnPage {Page LigneAccess Fichier} {

    return [AfficheVariable [PartieSegAli $Page $LigneAccess] " " $Fichier]
}

proc AfficheFetch {Selection {NomDuFichierOrigine ""}} {
    global RepertoireDuGenome
    global AccessDejaVus

    LogWscope "AfficheFetch $Selection"
    Wup "On cherche la sequence et on l'affiche"
    
    Gs "Frame"

    if {[regexp " " $NomDuFichierOrigine]} {
	foreach Mot [split $NomDuFichierOrigine " "] {
	    if {[regexp "/" $Mot]} { set NomDuFichierOrigine $Mot ; break }
	}
    }
    if {[regexp " " $NomDuFichierOrigine]} { scan $NomDuFichierOrigine "%s" NomDuFichierOrigine }
	
    
    set FormatVoulu ""
    if {$NomDuFichierOrigine=="OnVeutNature"} {
	set FormatVoulu "OnVeutNature"
	set NomDuFichierOrigine ""
    }
    if {[regexp "^OnVeut" $NomDuFichierOrigine]} {
	set FormatVoulu $NomDuFichierOrigine
	set NomDuFichierOrigine ""
    }


    set Nom ""
    if {$NomDuFichierOrigine != "" } {
	set Nom [file tail $NomDuFichierOrigine]
	Wup "NomDuFichierOrigine peut finir par Nom (de PAB)"
	if { ! [YaPABdans $Nom]} {
	    Wup "Recherche du pab si c'est un copain"
	    set Nom [file tail [file dirname $NomDuFichierOrigine]]
	}
	if { ! [YaPABdans $Nom]} { set Nom "" }
    }
    Wup "Si Nom n'est pas vide c'est qu'on a affaire a un PAB"
    
    set LesFramesFetchees {}
    
    set Liste [split $Selection "\n"]
    foreach Ligne $Liste {
	if { ! [regexp -nocase {[a-z0-9_]} $Ligne]} { continue }
	set Ligne [OteSuperfluPourFetch $Ligne]
	scan $Ligne "%s" aPDB
	if {[EstUnAccessPDB $aPDB]} {
	    if {[info exists DejaVu($aPDB)]} { continue }
	    set  DejaVu($aPDB) 1
	    if {[set LaFramePDB [AffichePDB $aPDB]]!=""} { 
		lappend LesFramesFetchees $LaFramePDB
		continue
	    } 
	}

	set BanqueId ""
	set Access ""
	Wup "On cherche d'abord Access dans la ligne"
	if { [regexp "^Query=" $Ligne] } {
	    Wup "C'est une ligne Query"
	    set Access [QueryDeLaLigne $Ligne]
	} elseif  { [regexp "^Name:" $Ligne] } {
	    Wup "C'est une ligne d'un MSF"
	    set Access [lindex [split $Ligne " "] 1]
	} elseif  { [regexp {^(AC|ID) } $Ligne] } {
	    Wup "C'est une ligne d'un EMBL"
	    scan $Ligne "%s %s" AC Access
	} elseif {[regexp -nocase {^[a-z0-9_]+=[a-z0-9_]+ } $Ligne]} {
	    Wup "Ligne descriptif"
	    regsub "=" $Ligne " " Access_BanqueId
	    scan $Access_BanqueId "%s %s" Access BanqueId
	} elseif {[regexp {^[a-zA-Z0-9_]+:[a-zA-Z0-9_]+[ !]* [a-zA-Z0-9_]+} $Ligne]} {
	    Wup "Ligne blast"
	    regsub "!" $Ligne " " BanqueId_Access
	    scan $BanqueId_Access "%s %s" BanqueId Access
	} elseif { [regexp {^[a-zA-Z0-9_]+: +[a-zA-Z0-9_]+} $Ligne]} {
	    Wup "Ligne du type 'Clef: access'"
	    scan $Ligne "%s %s" Bidon Access
	} else {
	    scan $Ligne "%s" Access
	}
	if {$BanqueId==""} { set BanqueId $Access }

	if {$Nom!="" && [OnTraiteUneCollection]} {
	    set FichierCopain "$RepertoireDuGenome/coembl/$Nom/$Access"
	    if {[file exists $FichierCopain]} {
		if {[info exists DejaVu($FichierCopain)]} { continue }
		set  DejaVu($FichierCopain) 1
		lappend LesFramesFetchees [AfficheVariable [ContenuDuFichier $FichierCopain] "AvecBlasteAvecFormate" "$FichierCopain"]
		continue
	    }
	}
	if {[info exists DejaVu($BanqueId,$Access)]} { continue }
	set AccessOk ""
	set LaSeqDesBan [LaSequenceDesBanques $BanqueId $Access AccessOk $FormatVoulu]
	set Sequence [join $LaSeqDesBan "\n"]
	if {$Sequence!=""} {
	    set  DejaVu($BanqueId,$Access) 1
	    lappend LesFramesFetchees [AfficheVariable $Sequence "AvecBlasteAvecFormate" $AccessOk]
	    continue
	}
	Wup "Ici on n'a toujours rien trouve ... "
	set FichierMSF "$RepertoireDuGenome/msf/$Nom"
	if {[info exists DejaVu($FichierMSF)]} { continue }
	if {[YaPABdans $Nom] && [file exists $FichierMSF]} {
	    set Sequence [UneSequenceDuMSF $FichierMSF $Access]
	    set TFA [SequenceFormatTFA $Sequence $Access "protbrut"]
	    if {$TFA!=""} { 
		set  DejaVu($FichierMSF) 1
		lappend LesFramesFetchees [AfficheVariable $TFA "AvecBlasteAvecFormate"]
		continue
	    }
	}
    }
    
    if {[llength $LesFramesFetchees]>0} {
	return [lindex $LesFramesFetchees 0]
    }
}

proc AfficheLesAliEnPage {Page Selection Fichier} {
    set LesSel [split $Selection "\n"]
    if {[PourWscope]} {
	set s [lindex $LesSel 0]
	return [AfficheAliEnPage $Page $s $Fichier]
    }
    foreach s $LesSel {
	AfficheAliEnPage $Page $s $Fichier
    }
}

proc AfficheLogDesMSF Selection {
    foreach MSF [split $Selection "\n"] {
	AfficheLogDuMSF $MSF
    }
}

proc AfficheLogDuMSF MSF {
    global LogDuMSF
    if {[info exists LogDuMSF($MSF)]} {
	set Log [set LogDuMSF($MSF)]
    } else {
	regsub {.out} $MSF {.log} logmsf
	regsub {.msf$} $logmsf {} Log
    }
    if {[info exists Log]} {
	AfficheFichier $Log "AvecRien"
    }
}

proc MemoSelection {w {Action "Memorize"}} {
    global MemoSelection

    if {$Action=="Memorize"} {
	if {[info exists MemoSelection($w)]} { unset MemoSelection($w) }
	set MemoSelection($w) [$w.frame.list curselection]
	return [set MemoSelection($w)]
    }
    if {$Action=="Recall" && [info exists MemoSelection($w)]} {
	foreach i [set MemoSelection($w)] {
	   $w.frame.list selection set $i 
	}
	return [set MemoSelection($w)]
    }
    return ""
}

proc PackBo {Bouton {Action ""}} {
    global PackBo

    if {$Action=="NoWeb"} { set NoWeb 1 } else { set NoWeb 0 }
    if {$NoWeb && [PourWscope]} { destroy $Bouton ; return "" }

    set W [winfo parent [winfo parent $Bouton]]

    if { ! [info exists PackBo($W)]} {
	set PackBo($W) -1
    }
    set B [incr PackBo($W)]

    set BpR 5
    set DestFrame "[winfo parent $Bouton].rangee[expr $B/$BpR]"
    if {[expr $B%$BpR == 0]} {
	 pack $DestFrame -side "top" -fill x -pady 1m
    }
    incr B
    if {[expr $B%$BpR == 0]} {
	set ProchaineDestFrame "[winfo parent $Bouton].rangee[expr $B/$BpR]"
	if { ! [winfo exists $ProchaineDestFrame]} {frame $ProchaineDestFrame}
    }
    pack $Bouton -in $DestFrame -side left -expand 1 -padx 1m
    return $Bouton
}

proc LesOnListDeSeeAbyPossibles {} {
    set LesOnListPossibles {}
    foreach Ligne [split [info body SeeAby] "\n"] {
	if { ! [regexp {\# OnList} $Ligne]} { continue }
	scan $Ligne "%s" Possible
	regsub -all {\"} $Possible "" Possible
	Espionne $Possible
	lappend LesOnListPossibles $Possible
    }
    return $LesOnListPossibles
}

proc LesRepertoiresInteressantsPour {Nom {HtmlAussi ""} {Vite ""}} {
    
}

proc LesRepertoiresPossiblesPour {Nom {HtmlAussi ""} {Vite ""}} {
    global RepertoireDuGenome

    if {$Nom=="All"} {
	set Vite "TesteRepertoire"
	if {$HtmlAussi==""} { set HtmlAussi "HtmlAussi" }
    }

    if {$Vite==""} { set Vite "Vite" }
    if {$Vite=="TestePresence" || $Vite=="TesteRepertoire"} { set Vite 0 } else { set Vite 1 }

    if {$HtmlAussi=="HtmlAussi"} {set HtmlAussi 1 } else {set HtmlAussi 0 }   

    if {$Vite} {
	set LesRepNom [glob -nocomplain "[RepertoireDuGenome]/*/$Nom"]
	if {$HtmlAussi} {
	    set LesRepNomHtml [glob -nocomplain "[RepertoireDuGenome]/*/$Nom.html"]
	    LConcat LesRepNom $LesRepNomHtml
	}
	set LesPossibles {}
	foreach RepNom $LesRepNom {
	    lappend LesPossibles [file tail [file dirname $RepNom]]
	}
	return $LesPossibles
    }
    set LesPossibles {}
    set LesRepertoires [glob -nocomplain -type d $RepertoireDuGenome/*]
    set LesLiens [glob -nocomplain -type l $RepertoireDuGenome/*]
    foreach Lien $LesLiens {
	set But [file readlink $Lien]
	if {[file isdirectory $But]} { lappend LesRepertoires $But }
    }
    if {$Nom=="All"} {
	foreach Rep $LesRepertoires {
	    set LesRepNom [glob -nocomplain "$Rep/[PreFixe]*"]
	    if {$LesRepNom=={}} {continue}
	    lappend LesPossibles [file tail $Rep]
	}
	return $LesPossibles
    }
    foreach Rep $LesRepertoires {
	if {$Vite} { lappend LesPossibles [file tail $Rep] ; continue } 
	if {[file exists "$Rep/$Nom"]} {
	    lappend LesPossibles [file tail $Rep]
	    continue
	}
	if {$HtmlAussi && [file exists "$Rep/$Nom.html"]} {
	    lappend LesPossibles [file tail $Rep]
	    continue
	}
	if {[OnTraiteDesCDNAs]} { continue }
	foreach SousRep [lsort [glob -nocomplain -type d $Rep/*]] {
	    if {[file exists $Rep/$Nom]} {
		lappend LesPossibles "[file tail $Rep]/[file tail $SousRep]"
		continue
	    }
	}
    }
    return $LesPossibles
}

proc LesRepertoiresPourSeeAbyShow {{Action ""} {Reps ""}} {
    global LesRepertoiresPourSeeAbyShow

    if {$Action==""} { set Action "Get" }

    set FichierShowDirs "[RepertoireDuGenome]/fiches/showdirs"

    if {$Action=="Get"} {
	if {[info exists LesRepertoiresPourSeeAbyShow]} { return $LesRepertoiresPourSeeAbyShow }
	if {[file exists $FichierShowDirs]} {
	    set LesRepertoiresPourSeeAbyShow [LesLignesDuFichier $FichierShowDirs]
	} else {
	    set LesRepertoiresPourSeeAbyShow [list \
		    bilan \
		    notes \
		    msf \
		    infos \
		    blastp \
		    prottfa \
		    nuctfa \
		    ver \
		    ]
	}
	return $LesRepertoiresPourSeeAbyShow
    }

    if {$Action=="PutInFront"} {
	set LesRepertoiresPourSeeAbyShow [linsert $LesRepertoiresPourSeeAbyShow 0 {*}$Reps]
	set LesRepertoiresPourSeeAbyShow [ListeSansDoublon $LesRepertoiresPourSeeAbyShow]
	return $LesRepertoiresPourSeeAbyShow
    }

    set LesAnciens [LesRepertoiresPourSeeAbyShow]
    if {$Action=="Ask"} {
	set LesFichiersPossibles [glob -nocomplain "$FichierShowDirs*"]
	if {$LesFichiersPossibles!={}} {
	    while {[OuiOuNon "Do you want to load a file ?"]} {
		set FichierPossible [ButineArborescence "All" "[RepertoireDuGenome]/fiches/"]
		if {$FichierPossible==""} { continue }
		set LesAnciens [LesLignesDuFichier $FichierPossible]
		break
	    }
	}
	set LesReps [MorceauxChoisisAndMore $LesAnciens]
	if {$LesReps=={}} { set LesReps $LesAnciens }
	foreach Rep $LesReps {
	    lappend LesNouveaux [file tail $Rep]
	}
	set LesRepertoiresPourSeeAbyShow $LesNouveaux
	while {[OuiOuNon "Do You want to save this list in a file ?"]} {
	    set NewFichierShowDirs [FichierPourSaveAs $FichierShowDirs]
	    if {$NewFichierShowDirs==""} { continue }
	    SauveLesLignes $LesRepertoiresPourSeeAbyShow dans $NewFichierShowDirs
	    break
	}
	return $LesRepertoiresPourSeeAbyShow
    }
}

proc ShowNote Nom {
    return [SeeAby notes $Nom]
}

proc SeeAby {Quoi Fichier} {
    global SeeAby
    global RepertoireDuGenome
    global PABCourant
    global VariableToSetForWscope

    Gs "Frame"
    
    if {$Fichier==""} { return "" }

    scan $Fichier "%s" Fichier

    set Nom [file tail $Fichier]

    set PABCourant $Nom

    if {$Quoi=="OnList"} {
	set LesPossibles [LesOnListDeSeeAbyPossibles]
	lappend LesPossibles Loc
	set Quoi [ChoixParmi $LesPossibles]
	if {$Quoi==""} { return }
    }

    if {$Quoi=="Loc"} { return [AfficheChaqueSegmentDuBlastN $Nom] }

    global MemoAny
    if {$Quoi=="MemoAny"} {
	if {[info exists MemoAny]} {
	    return [SeeAby $MemoAny $Fichier]
	} else {
	    return [SeeAby "ChooseAny" $Fichier]
	}
    }

    if {$Quoi=="ChooseAny" || $Quoi=="AllAny"} {
	set LesAnyDisponibles {}
	foreach Rep [glob -nocomplain "$RepertoireDuGenome/*"] {
	    set Queue [file tail $Rep] 
	    if {$Quoi=="AllAny"} {
		if {[file exists "$Rep/$Nom"]} {
		    SeeAby "Any" $Fichier
		}
		continue
	    }
	    if {$Quoi=="ChooseAny"} {
		lappend LesAnyDisponibles $Queue
	    }
	}
	if {$Quoi=="AllAny"} { return $LesAnyDisponibles }
	if {$Quoi=="ChooseAny"} {
	    set VariableToSetForWscope "MemoAny"
	    set Choix [ChoixParmi $LesAnyDisponibles]
	    if {$Choix==""} { return "" }
	    set MemoAny "$Choix"
	    return [SeeAby "MemoAny" $Fichier]
	}
    }
    
    global MemoMsf
    if {$Quoi=="MemoMsf"} {
	if {[info exists MemoMsf]} {
	    return [SeeAby "$MemoMsf" $Fichier]
	} else {
	    if {[OnTraiteUnGenome]} { set MemoMsf "MSF_msf" }
	    if {[OnTraiteDesCDNAs]} { set MemoMsf "MSF_msf" }
	    if {[info exists MemoMsf]} {
		return [SeeAby "MemoMsf"   $Fichier]
	    } else {
		return [SeeAby "ChooseMsf" $Fichier]
	    }
	}
    }
    if {$Quoi=="ChooseMsf" || $Quoi=="AllMsf"} {
	set LesMsfDisponibles {}
	foreach Rep [glob -nocomplain "$RepertoireDuGenome/*msf*"] {
	    set Queue [file tail $Rep] 
	    if {$Quoi=="AllMsf"} {
		if {[file exists "$Rep/$Nom"]} {
		    SeeAby "Msf" $Fichier
		}
		continue
	    }
	    if {$Quoi=="ChooseMsf"} {
		lappend LesMsfDisponibles $Queue
	    }
	}
	if {$Quoi=="AllMsf"} { return $LesMsfDisponibles }
	if {$Quoi=="ChooseMsf"} {
	    set VariableToSetForWscope "MemoMsf"
	    set Choix [ChoixParmi $LesMsfDisponibles]
	    if {$Choix==""} { return "" }
	    set MemoMsf "MSF_$Choix"
	    return [SeeAby "MemoMsf" $Fichier]
	}
    }

    global MemoBlast
    if {$Quoi=="MemoBlast"} {
	if {[info exists MemoBlast]} {
	    if {$MemoBlast=="Blast"} { return [SeeAby "Banque$MemoBlast" $Fichier] }
	    return [SeeAby "Banque$MemoBlast" $Fichier]
	} else {
	    if {[OnTraiteUnGenome]} { set MemoBlast "blastp" }
	    if {[OnTraiteDesCDNAs]} { set MemoBlast "blastn" }
	    if {[info exists MemoBlast]} {
		return [SeeAby "MemoBlast"   $Fichier]
	    } else {
		return [SeeAby "ChooseBlast" $Fichier]
	    }
	}
    }
    if {$Quoi=="ChooseBlast" || $Quoi=="AllBlast"} {
	set LesBlastDisponibles {}
	foreach Rep [glob -nocomplain "$RepertoireDuGenome/*blast*"] {
	    set Banque [file tail $Rep]
#	    regsub -nocase {trou[sx]+} $Banque "" Banque 
	    if {$Quoi=="AllBlast"} {
		if {[file exists "$Rep/$Nom"]} {
		    SeeAby "Banque$Banque" $Fichier
		}
		continue
	    }
	    if {$Quoi=="ChooseBlast"} {
		lappend LesBlastDisponibles $Banque
	    }
	}
	if {$Quoi=="AllBlast"} { return $LesBlastDisponibles }
	if {$Quoi=="ChooseBlast"} {
	    set VariableToSetForWscope "MemoBlast"
	    set Ban [ChoixParmi $LesBlastDisponibles]
	    if {$Ban==""} { return "" }
	    set MemoBlast $Ban
	    return [SeeAby "MemoBlast" $Fichier]
	}
    }

    if {[regexp "LesTBlastN" $Quoi]} {
	foreach Rep [glob -nocomplain "$RepertoireDuGenome/tblastn*"] {
	    set Banque [file tail $Rep]
	    if {[file exists "$Rep/$Nom"]} {
		SeeAby "Banque$Banque" $Fichier
	    }
	}
    }
    if {[regexp "^all" $Quoi]} {
	set Quoi [string tolower $Quoi]
	regsub "all" $Quoi "" Quoi
	set Quoi "[string range $Quoi 0 end-1]last[string range $Quoi end end]"
	foreach Rep [glob -nocomplain "$RepertoireDuGenome/$Quoi*"] {
	    if {[file type $Rep]=="link"} {
		set Cible [file readlink $Rep]
		if {[regexp "^$Quoi" [file tail $Cible]]} { continue }
	    }
	    if {[file exists "$Rep/$Nom"]} {
		set Rep [file tail $Rep]
		SeeAby $Rep $Fichier
	    }
	}
	return
    }

    if {[regexp "^Banque" $Quoi]} {
	regsub "Banque" $Quoi "" Banque
	set Quoi "Banque"
    }

    if {[regexp "^MSF_" $Quoi]} {
	regsub "MSF_" $Quoi "" MsfDir
	set Quoi "MSF_"
    }

    set FichierExcuse "Sorry_I_cannot_find_the_file_associate_with_${Quoi}_${Fichier}"

    if {[OnTraiteUneCollection] && $Quoi=="Pep"} { set Quoi "PhEnNJPlot" }

    if {$Quoi=="Other"} {
	set LesPossibles [LesRepertoiresPossiblesPour $Nom]
	set Quoi [ChoixParmi [lsort $LesPossibles]]
	if {$Quoi==""} { return "" }
    }

    if {$Quoi=="Nicolas"} {
	set LesPossibles {Correlator Secator NuCA}
	set LesPossibles {Correlator}
	set Quoi [ChoixParmi $LesPossibles]
	if {$Quoi==""} { return "" }
    }

    if {$Quoi=="Blast" && [OnTraiteDesCDNAs]} {
	set Quoi "BlastN"
    } 
    if {$Quoi=="Seq" && [OnTraiteDesCDNAs]} {
	set Quoi "Nuc"
    } 
    if {$Quoi=="Taxobla"} {
	return [AfficheFichier "[RepertoireDuGenome]/taxobla/$Nom" "GrandeLargeur"]
    }
    switch $Quoi {
	"Show" { # OnList
	    foreach Rep [LesRepertoiresPourSeeAbyShow] {
		set FichierShow "$RepertoireDuGenome/$Rep/$Nom"
		if { ! [file exists $FichierShow]} { continue }
		if {$Rep=="msf" && [regexp "NoSequenceToAlign" $FichierShow]} { continue }
		break
	    }
	    if {[file exists $FichierShow] && [file size $FichierShow]>0} {
		if {$Rep=="msf"} { return [SeeAby "MSF" $FichierShow] } 
		return [AfficheFichier $FichierShow "AutoManiere"]
	    }
	    return [AfficheVariable "I found nothing to display for $Nom" "" $Nom]
	}
	"Correlator" { # OnList
	    switch -regexp $Nom \
		    "[PreFixe]"       { set FichierBlastP "$RepertoireDuGenome/blastp/$Nom" } \
		    default           { set FichierBlastP $FichierExcuse }
	    if {$FichierBlastP == $FichierExcuse || ! [file exists $FichierBlastP]} {
		FaireLire "No file to show"
		return ""
	    } else {
		return [Correlator $FichierBlastP [NomDe fenetre]]
	    }
	}
	"Secator" { # OnList
	    switch -regexp $Nom \
		    "[PreFixe]"       { set FichierBlastP "$RepertoireDuGenome/blastp/$Nom" } \
		    default           { set FichierBlastP $FichierExcuse }
	    if {$FichierBlastP == $FichierExcuse || ! [file exists $FichierBlastP]} {
		FaireLire "No file to show"
		return ""
	    } else {
		return [Correlator $FichierBlastP [NomDe fenetre]]
	    }
	}
	"Ordali" { # OnList
	    switch -regexp $Nom \
		    "[PreFixe]"       { return [Ordali $Nom $Fichier] } \
		    default           { return ""}
	}
	"PhEnNJPlot" {
	    switch -regexp $Nom \
		    "[PreFixe]"       { set FichierPh "$RepertoireDuGenome/phylos/$Nom" } \
		    default           { set FichierPh $FichierExcuse }
	    if {$FichierPh == $FichierExcuse} {
		FaireLire "No file to plot"
		return ""
	    } else {
		return [NJPlotPH $FichierPh]
	    }
	}
	"Nuc" { # OnList
	    switch -regexp $Nom \
		    "[PreFixe]"       { set FichierNuc "$RepertoireDuGenome/nuctfa/$Nom" } \
		    "ARN"             { set FichierNuc "$RepertoireDuGenome/nuctfa/$Nom" } \
		    "TRNA"            { set FichierNuc "$RepertoireDuGenome/nuctfa/$Nom" } \
		    {TROU[0-9]*N}     { set FichierNuc "$RepertoireDuGenome/nuctfa/$Nom" } \
		    {TROU[0-9]*[A-F]} { set FichierNuc "$RepertoireDuGenome/prottfa/$Nom" } \
		    default           { set FichierNuc $FichierExcuse }
	    if {$FichierNuc==$FichierExcuse} {
		set FichierNuc "$RepertoireDuGenome/nuctfa/$Nom"
		if {[FileAbsent $FichierNuc]} { set FichierNuc $FichierExcuse }
	    } 
	    return [AfficheFichier $FichierNuc "AvecBlasteAvecFormate"]
	}
	"Seq" { # OnList
	    switch -regexp $Nom \
		    "[PreFixe]"       { set FichierPep "$RepertoireDuGenome/prottfa/$Nom" } \
		    "ARN"             { set FichierPep "$RepertoireDuGenome/nuctfa/$Nom" } \
		    "TRNA"            { set FichierPep "$RepertoireDuGenome/nuctfa/$Nom" } \
		    {TROU[0-9]*N}     { set FichierPep "$RepertoireDuGenome/nuctfa/$Nom" } \
		    {TROU[0-9]*[A-F]} { set FichierPep "$RepertoireDuGenome/prottfa/$Nom" } \
		    default           { set FichierPep $FichierExcuse }
	    if {$FichierPep==$FichierExcuse} {
		set FichierPep "$RepertoireDuGenome/prottfa/$Nom"
		if {[FileAbsent $FichierPep]} { set FichierPep $FichierExcuse }
	    } 
	    return [AfficheFichier $FichierPep "AvecBlasteAvecFormate"]
	}
	"Embl" { # OnList
	    switch -regexp $Nom \
		    "[PreFixe]"       { set FichierPep "$RepertoireDuGenome/protembl/$Nom" } \
		    "ARN"             { set FichierPep "$RepertoireDuGenome/nucembl/$Nom" } \
		    "TRNA"            { set FichierPep "$RepertoireDuGenome/nucembl/$Nom" } \
		    {TROU[0-9]*N}     { set FichierPep "$RepertoireDuGenome/nucembl/$Nom" } \
		    {TROU[0-9]*[A-F]} { set FichierPep "$RepertoireDuGenome/protembl/$Nom" } \
		    default           { set FichierPep $FichierExcuse }
	    if {$FichierPep==$FichierExcuse} {
		set FichierPep "$RepertoireDuGenome/protembl/$Nom"
		if {[FileAbsent $FichierPep]} { set FichierPep $FichierExcuse }
	    } 
	    return [AfficheFichier $FichierPep "AvecBlasteAvecFormate"]
	}
	"BlastN" { # OnList
	    switch -regexp $Nom \
		    "[PreFixe]"   { set FichierBlast "$RepertoireDuGenome/blastn/$Nom" } \
		    "ARN"         { set FichierBlast "$RepertoireDuGenome/arnblastn/$Nom" } \
		    "TRNA"        { set FichierBlast "$RepertoireDuGenome/trnablastn/$Nom" } \
		    {TROU[0-9]*N} { set FichierBlast "$RepertoireDuGenome/troustblastxgenembl/$Nom" } \
		    "TROU"        { set FichierBlast "$RepertoireDuGenome/trousblastn/$Nom" } \
		    default       { set FichierBlast $FichierExcuse }
	    if {$FichierBlast==$FichierExcuse} {
		set FichierBlast "$RepertoireDuGenome/blastn/$Nom"
		if {[FileAbsent $FichierBlast]} { set FichierBlast $FichierExcuse }
	    } 
	    return [AfficheFichier $FichierBlast \
		    "AvecGrapheAvecSegAlignementAvecAligneurs"]
	}
	"Blast" { # OnList
	    switch -regexp $Nom \
		    "[PreFixe]"   { set FichierBlast "$RepertoireDuGenome/blastp/$Nom" } \
		    "ARN"         { set FichierBlast "$RepertoireDuGenome/arnblastp/$Nom" } \
		    "TRNA"        { set FichierBlast "$RepertoireDuGenome/trnablastp/$Nom" } \
		    {TROU[0-9]*N} { set FichierBlast "$RepertoireDuGenome/trousblastx/$Nom" } \
		    "TROU"        { set FichierBlast "$RepertoireDuGenome/trousblastp/$Nom" } \
		    default       { set FichierBlast $FichierExcuse }
	    if {$FichierBlast==$FichierExcuse} {
		set FichierBlast "$RepertoireDuGenome/blastp/$Nom"
		if {[FileAbsent $FichierBlast]} { set FichierBlast $FichierExcuse }
	    } 
	    return [AfficheFichier $FichierBlast \
		    "AvecGrapheAvecSegAlignementAvecAligneurs"]
	}
	"Ballast" { # OnList
	    switch -regexp $Nom \
		    "[PreFixe]"   { set FichierBlastP "$RepertoireDuGenome/blastp/$Nom" } \
		    "TROU"        { set FichierBlastP "$RepertoireDuGenome/trousblastp/$Nom" } \
		    default       { return "" }
	    return [AfficheBallastDuBlastP $FichierBlastP $Nom]
	}
	"Banque" { # OnList
	    switch -regexp $Nom \
		    "[PreFixe]"   { set FichierBlast "$RepertoireDuGenome/$Banque/$Nom" } \
		    "ARN"         { set FichierBlast "$RepertoireDuGenome/arn$Banque/$Nom" } \
		    "TRNA"        { set FichierBlast "$RepertoireDuGenome/trna$Banque/$Nom" } \
		    {TROU[0-9]+N} { set FichierBlast "$RepertoireDuGenome/$Banque/$Nom" } \
		    {aRemettreTROU[0-9]+N} { regsub "p" $Banque "x" Banque ; set FichierBlast "$RepertoireDuGenome/$Banque/$Nom" } \
		    "TROU"        { set FichierBlast "$RepertoireDuGenome/trou$Banque/$Nom" } \
		    default       { set FichierBlast $FichierExcuse }
	    if {[regexp -nocase "tblastn" $Banque]} {
		set  Maniere "AvecSegAlignement"
	    } else {
		set Maniere "AvecGrapheAvecSegAlignementAvecAligneurs"
	    }
	    return [AfficheFichier $FichierBlast $Maniere]
	}
	"MSF_" { # OnList
	    switch -regexp $Nom \
		    "[PreFixe]" { set FichierMSF "$RepertoireDuGenome/$MsfDir/$Nom" } \
		    "ARN"       { set FichierMSF "" } \
		    "TRNA"      { set FichierMSF "" } \
		    "TROU"      { set FichierMSF "$RepertoireDuGenome/$MsfDir/$Nom" } \
		    default     { set FichierMSF $FichierExcuse }
	    if {$FichierMSF==$FichierExcuse} {
		set FichierMSF "$RepertoireDuGenome/$MsfDir/$Nom"
		if {[FileAbsent $FichierMSF]} { set FichierMSF $FichierExcuse }
	    } 
	    set FenetreMSF [AfficheFichier $FichierMSF "AvecEtudeMSFGrandeLargeur"]
	    return $FenetreMSF
	}
	"MSF" { # OnList
	    set MSFouDBC "msf"
	    switch -regexp $Nom \
		    "[PreFixe]" { set FichierMSF "$RepertoireDuGenome/$MSFouDBC/$Nom" } \
		    "ARN"       { set FichierMSF "" } \
		    "TRNA"      { set FichierMSF "" } \
		    "TROU"      { set FichierMSF "$RepertoireDuGenome/trousmsf/$Nom" } \
		    default     { set FichierMSF $FichierExcuse }
	    if {$FichierMSF==$FichierExcuse} {
		set FichierMSF "$RepertoireDuGenome/$MSFouDBC/$Nom"
		if {[FileAbsent $FichierMSF]} { set FichierMSF $FichierExcuse }
	    } 
	    set FenetreMSF [AfficheFichier $FichierMSF "AvecEtudeMSFGrandeLargeur"]
	    return $FenetreMSF
	}
	"MSF2" { # OnList
	    set FichierMSF "$RepertoireDuGenome/msf2/$Nom"
	    if { ! [file exists $FichierMSF]} {
		set FichierMSFMSF "$RepertoireDuGenome/msf2/$Nom.msf"
		if { ! [file exists $FichierMSFMSF]} { return "" }
		set FichierMSF $FichierMSFMSF
	    }
	    if {[file isdirectory $FichierMSF]} {
		set RepMSF "$RepertoireDuGenome/msf2/$Nom"
		set FichierMSF [ChoixParmi [glob -nocomplain "$RepMSF/*"]]
	    }
	    if {$FichierMSF==""} { return "" }
	    set FenetreMSF [AfficheFichier $FichierMSF "AvecEtudeMSFGrandeLargeur"]
	    return $FenetreMSF
	}
	"MSF3" { # OnList
	    set FichierMSF "$RepertoireDuGenome/msf3/$Nom"
	    if { ! [file exists $FichierMSF]} {
		set FichierMSFMSF "$RepertoireDuGenome/msf3/$Nom.msf"
		if { ! [file exists $FichierMSFMSF]} { return "" }
		set FichierMSF $FichierMSFMSF
	    }
	    if {[file isdirectory $FichierMSF]} {
		set RepMSF "$RepertoireDuGenome/msf3/$Nom"
		set FichierMSF [ChoixParmi [glob -nocomplain "$RepMSF/*"]]
	    }
	    if {$FichierMSF==""} { return "" }
	    set FenetreMSF [AfficheFichier $FichierMSF "AvecEtudeMSFGrandeLargeur"]
	    return $FenetreMSF
	}
	"SpineXml" { # Onlist
	    set FichierXml "$RepertoireDuGenome/XmlFromSpine/$Nom"
	    return [AfficheFichier $FichierXml \
		    "AvecXmlGrandeLargeur"]
	}
	"MacsimXml" { # Onlist
	    set FichierXml "$RepertoireDuGenome/macsimXml/$Nom"
	    return [AfficheFichier $FichierXml \
		    "AvecXmlGrandeLargeur"]
	}	    
	"Para" { # OnList
	    set FichierMSF "$RepertoireDuGenome/msfparalogues/$Nom"
	    return [AfficheFichier $FichierMSF \
		    "AvecEtudeMSFGrandeLargeur"]
	}
	"Disphy" { # OnList
	    set Fichier "$RepertoireDuGenome/disphy/$Nom"
	    if {$Fichier==""} { return "" }
	    return [AfficheFichier $Fichier ""]
	}
	default {
	    set Fichier "$RepertoireDuGenome/$Quoi/$Nom"
	    if {$Fichier==""} { return "" }
	    return [AfficheFichier $Fichier "AutoManiere"]
	}
    }
}

proc AligneLesHomologuesDuBlast {Aligneur FichierBlast} {
    global RepertoireDuGenome

    set SeuilExpect 1e-3
    set MaxLongueurDuBlast 50

    DecortiqueBlast $FichierBlast $SeuilExpect $MaxLongueurDuBlast Query lBanqueId lAccess lDE lProfil lPN
    set Nom [file tail $Query]
    if {[YaPABdans $Nom]} {
	set lHomos "$RepertoireDuGenome/prottfa/$Nom"
    } elseif {[regexp "TROU" $Nom]} {
	set lHomos "$RepertoireDuGenome/trousprottfa/$Nom"
    } else {
	set lHomos $Query
    }
    if { [info exists lBanqueId] && [llength $lBanqueId] > 0 } {
	foreach BanqueId $lBanqueId Access $lAccess {
	    if {[FetchTest $BanqueId]} {
		lappend lHomos $BanqueId
		continue
	    }
	    if {[FetchTest "protein:$Access"]} {
		lappend lHomos "protein:$Access"
		continue
	    }
	    Warne "$BanqueId $Access introuvable"
	}
    }
    set Destination "$RepertoireDuGenome/${Aligneur}/$Nom"
    if { [llength $lHomos] < 2 } {
	Warne "$Aligneur inutile. Pas de sequences a aligner dans $FichierBlast"
	return ""
	return [Sauve "$Aligneur inutile. Pas de sequences a aligner dans $FichierBlast" dans $Destination]
    }
    set Selection [join $lHomos "\n"]
    set MSF [AlignePar $Aligneur $Selection "Interactif" $Nom]
    file rename $MSF $Destination 
    return $Destination
} 

proc AligneLesHomologuesDuBlastContreSeq {Aligneur FichierBlast {Seq ""}} {
    global RepertoireDuGenome

    set SeuilExpect 1e-3
    set MaxLongueurDuBlast 50

    DecortiqueBlast $FichierBlast $SeuilExpect $MaxLongueurDuBlast Query lBanqueId lAccess lDE lProfil lPN
    set Nom [file tail $Query]
    if { $Seq == ""} { set Seq $Query }
    set lHomos [linsert $lAccess 0 $Seq]
    if { [llength $lHomos] < 2 } { return "" }
    set Selection [join $lHomos "\n"]
    set MSF [AlignePar $Aligneur $Selection "Batch" $Nom]

    return $MSF
} 

proc Aligne3PdeADN {Nom Devant DebutDevant FinDevant \
	Derriere DebutDerriere FinDerriere Orient} {

    global RepertoireDuGenome
    global Commandes
    global ADN TDN RAC
    global NePlusFaireAligne3P

    if { ! [info exists NePlusFaireAligne3P]} { set NePlusFaireAligne3P 1 }

    if { $Orient == "F" } {
	set ListeDes3Frames {a b c}
    } else {
	set ListeDes3Frames {f e d}
    }

    if { $NePlusFaireAligne3P || ! [OuiOuNon "Je lance 3 alignements ?"]} {
	return "a faire."
    }

    if { ! [info exists ADN]} { ChargeADNetTDNetRAC }

    set NomDesSequences ""

    if {[YaPABdans $Nom]} {
	set FichierBlast "$RepertoireDuGenome/blastp/$Nom"
    }
    if {[regexp "TROU" $Nom]} {
	set FichierBlast "$RepertoireDuGenome/trousblastp/$Nom"
    }

    if { $Devant == "Laisser" } {
	set SequenceDevant [BoutADN $DebutDevant $FinDevant $Orient]
    }
    set LongueurPepDevant [expr ($FinDevant-$DebutDevant+1)/3]

    if { $Derriere == "Laisser" } {
	set SequenceDerriere [BoutADN $DebutDerriere $FinDerriere $Orient]
    }
    set LongueurPepDerriere [expr ($FinDerriere-$DebutDerriere+1)/3]

    set Sens [expr $Orient=="F" ? -1 : 1]
    foreach Frame $ListeDes3Frames {
	set CasseDevant "toupper"
	if { $Devant == "Changer" } {
	    incr DebutDevant $Sens 
	    incr FinDevant $Sens
	    set SequenceDevant [BoutADN $DebutDevant $FinDevant $Orient]
	    set SequenceDevant [string tolower $SequenceDevant]
	    set CasseDevant "tolower"
	    set NomDeLaSequence "${Nom}_${LongueurPepDevant}_${Frame}"
	}
	set CasseDerriere "toupper"
	if { $Derriere == "Changer" } {
	    incr DebutDerriere $Sens 
	    incr FinDerriere $Sens
	    set SequenceDerriere [BoutADN $DebutDerriere $FinDerriere $Orient]
	    set SequenceDerriere [string tolower $SequenceDerriere]
	    set CasseDerriere "tolower"
	    set NomDeLaSequence "${Nom}_${Frame}_${LongueurPepDerriere}"
	}
	append NomDesSequences "$NomDeLaSequence "
	set SequenceADN "$SequenceDevant$SequenceDerriere"

	set SeqGCG [NucToGCG $SequenceADN $NomDeLaSequence]

	set iPP [string first "\.\." $SeqGCG]
	set EncoreDevant $LongueurPepDevant 
	set EncoreDerriere $LongueurPepDerriere 
	catch {unset VraiDebutDevant VraiDebutDerriere}
	for {set i $iPP} {$i < [string length $SeqGCG]} {incr i} {
	    if {[regexp {[a-zA-Z\*]} [string range $SeqGCG $i $i]]} {
		if { $EncoreDevant } {
		    if { ! [info exists VraiDebutDevant]} {
			set VraiDebutDevant $i
		    }
		    set VraiFinDevant $i
		    incr EncoreDevant -1
		} else {
		    if { $EncoreDerriere } {
			if { ! [info exists VraiDebutDerriere]} {
			    set VraiDebutDerriere $i
			}
			set VraiFinDerriere $i
			incr EncoreDerriere -1
		    }
		}
	    }
	}
	set LowerSeqGCG "\
		[string range $SeqGCG  0 [expr $VraiDebutDevant-1]]\
		[string $CasseDevant   [string range $SeqGCG $VraiDebutDevant $VraiFinDevant]]\
		[string $CasseDerriere [string range $SeqGCG $VraiDebutDerriere end]]"
	set iL [expr [string first "Length" $LowerSeqGCG]-1]
	set BonneSeqGCG "$NomDeLaSequence[string range $LowerSeqGCG $iL end]"
	set FichierPEP [Sauve $BonneSeqGCG dans $NomDeLaSequence]
	foreach Aligneur [Aligneurs] {
	    if { [Aligneurs $Aligneur] } {
		set MSF [AligneLesHomologuesDuBlastContreSeq \
			$Aligneur $FichierBlast $FichierPEP]
		lappend ListeDesMSF $MSF
	    }
	}
    }
    set Fenetre [AfficheVariable [join $ListeDesMSF "\n"] \
	    "AvecShowAvecEtudeMSF" "Wait all be Highlighted ...\nThen reselect and press a function. "]
    BoutonneLaFenetre $Fenetre "Log" "AfficheLogDesMSF \[selection get\]"
    foreach Fichier $ListeDesMSF {
	set LaFenetreDesMSF($Fichier) $Fenetre
    }	    
    return "Aligne3P est lance sur $NomDesSequences"
}

proc EnterBox {K X Y} {
    global CouleurEnEntree oldText

    set Id [$K find withtag current]
    set CouleurEnEntree [lindex [$K itemconfig $Id -fill] 4]
    $K itemconfigure $Id -fill [Fard $K $X $Y]
#   ShowBox $K $X $Y "Enter"
}

proc LeaveBox {K X Y} {
    global CouleurEnEntree oldText

    if { ! [info exists CouleurEnEntree]} { return }

    set Id [$K find withtag current]
    $K itemconfigure $Id -fill $CouleurEnEntree
#   ShowBox $K $X $Y "Leave"
}

proc PositionCanvaOriginaleX {K xCanva} {
    global ScrollRectangleOriginal IdScrollRectangle
    scan "[$K coords [set IdScrollRectangle($K)]]" "%f %f %f %f" xMin  yMin  xMax  yMax
    scan "[set ScrollRectangleOriginal($K)]"      "%f %f %f %f" xMinO yMinO xMaxO yMaxO
    set xOrig [expr $xMinO+($xCanva-$xMin)*($xMaxO-$xMinO)/($xMax-$xMin)]
    return [expr int($xOrig)]
}

proc PositionCanvaOriginaleY {K yCanva} {
    global ScrollRectangleOriginal IdScrollRectangle
    scan "[$K coords [set IdScrollRectangle($K)]]" "%f %f %f %f" xMin  yMin  xMax  yMax
    scan "[set ScrollRectangleOriginal($K)]"      "%f %f %f %f" xMinO yMinO xMaxO yMaxO
    set yOrig [expr $yMinO+($yCanva-$yMin)*($yMaxO-$yMinO)/($yMax-$yMin)]
    return [expr int($yOrig)]
}

proc PositionCanvaActuelleX {K xOrig} {
    global ScrollRectangleOriginal IdScrollRectangle
    scan "[$K coords [set IdScrollRectangle($K)]]" "%f %f %f %f" xMin  yMin  xMax  yMax
    scan "[set ScrollRectangleOriginal($K)]"      "%f %f %f %f" xMinO yMinO xMaxO yMaxO
    set xCanva [expr $xMin+($xOrig-$xMinO)*($xMax-$xMin)/($xMaxO-$xMinO)]
    return $xCanva
}

proc PositionCanvaActuelleY {K yOrig} {
    global ScrollRectangleOriginal IdScrollRectangle
    scan "[$K coords [set IdScrollRectangle($K)]]" "%f %f %f %f" xMin  yMin  xMax  yMax
    scan "[set ScrollRectangleOriginal($K)]"      "%f %f %f %f" xMinO yMinO xMaxO yMaxO
    set yCanva [expr $yMin+($yOrig-$yMinO)*($yMax-$yMin)/($yMaxO-$yMinO)]
    return $yCanva
}

proc SearchOnBoard Texte {

    Gs "DeplaceK"

    scan $Texte "%s" Nom
    if {[EstUnPAB $Nom]} { return [RepereBox "Nom: $Nom"] }

    foreach Mot [LesMotsDeLaLigne $Texte] {
	if {[EstUnPAB $Mot]} { return [RepereBox "Nom: $Mot"] }
    }
    return ""
}

proc LesPABsAvecInfo Texte {
    return [RepereBox $Texte "AllPlease"]
}

proc RepereBox {Texte {K ""} {Next ""}} {
    global RepertoireDuGenome
    global ListeDesContenuInfo
    global ListeDeBoites
    global ListeRestante
    global OldTexte


    #rR Next peut être AllPlease AllPleaseInfo et même AllPleaseWith_Alias_ValiGN etc qui marche dans ExtraitInfo

    if {[PourWscope]} { regsub -all {\+} $Texte " " Texte }
    
    Gs "DeplaceK"

    if {[regexp -nocase "AllPlease" $K]} {
	set Next $K
	set K "Bidon"
    }
    
    if {$K==""} {
	if {[PourWscope]} {
	    set K "PourWscope"
	} else {
	    set K [KanvaCourant]
	}
    }

    set DontDisplay 0
    if {[PourWscope] || $K=="PourWscope"} { set DontDisplay 1 }

    if { ! [info exists ListeDeBoites]} { ChargeListeDeBoites }
    
    #jM Petit changement de ma part voir original ci dessous,ajout de [PreFixe] JEAN
    if {[regexp "^Nom: [PreFixe]" $Texte] || [regexp {^Nom: (TROU|TRNA|ARN|GLIMMER)}  $Texte] } {
	set Nom [StringApres "Nom: " dans $Texte]
	if {[Box $Nom nom] == $Nom} {
	    if {$DontDisplay} { return $Nom }
	    return [PositionneEtInforme $Nom $K $Next]
	}
    }
    
    if {[regexp "^Nom: [ExpressionReguliereDesPABs]" $Texte] || [regexp {^Nom: (TROU|TRNA|ARN|GLIMMER)}  $Texte] } {
	set Nom [StringApres "Nom: " dans $Texte]
	if {[Box $Nom nom] == $Nom} {
	    if {DontDisplay} { return $Nom }
	    return [PositionneEtInforme $Nom $K $Next]
	}
    }

    set Texte [string toupper $Texte]

    if { ! [info exists ListeDesContenuInfo]} {
	Wup "ExtraitInfo loads ListeDesContenuInfo"
	ExtraitInfo "Bidon"
    }

    if {[regexp -nocase "AllPlease" $Next]} {
	set FinString 30
	if {[regexp -nocase "Info" $Next]} { set FinString "end" }
	set Start 0
	set LesTrouves {}
	set LesInfosTrouves {}
	set iTrouveOld 99999999999999
	while {[set iTrouve [lsearch -start $Start -regexp $ListeDesContenuInfo $Texte]]>-1} {
	    if {$iTrouveOld==$iTrouve} { break }
	    set iTrouveOld $iTrouve
	    set NomTrouve [lindex $ListeDeBoites $iTrouve]
	    set InfoTrouve [string range [lindex $ListeDesContenuInfo $iTrouve] 0 $FinString]
	    if {[regexp -nocase "Info" $Next]} {
	    } else {  
		regsub -all "\n" $InfoTrouve "/" InfoTrouve
	    }
	    lappend LesTrouves "$NomTrouve"
	    lappend LesInfosTrouvees "$InfoTrouve"
	    set Start [expr $iTrouve + 1]
	}
	if {[regexp -nocase "Info" $Next]} { return $LesInfosTrouvees }
	if {[regexp -nocase "With_(.*)" $Next Match Keys]} {
	    set Keys [split $Keys "_"]
	    foreach Trouve $LesTrouves {
		set LaLigneResultat [list $Trouve]
		foreach K $Keys {
		    set Info [ExtraitInfo $Trouve $K]
		    lappend LaLigneResultat $Info
		}
		lappend LesTrouvesInfos [join $LaLigneResultat "\t"]
	    }
	    return [join $LesTrouvesInfos "\n"]
	}
	return $LesTrouves
    }
    
    if { ! [info exists ListeRestante]} {
	set ListeRestante $ListeDesContenuInfo
    }

    if { $Next != "" && [info exists OldTexte] } { set Texte $OldTexte }
    set OldTexte $Texte

    if { [regexp "Next" $Next] } {
	set iTrouve [lsearch -regexp $ListeRestante $Texte]
	if { $iTrouve == -1 } {
	    set ListeRestante $ListeDesContenuInfo
	    set iTrouve [lsearch -regexp $ListeRestante $Texte]
	}
    } else {
	set ListeRestante $ListeDesContenuInfo
	set iTrouve [lsearch -regexp $ListeRestante $Texte]    
    }
    if { $iTrouve == -1 } { return "" }
    set DebutNom [string length "Nom: "]
    scan [string range [lindex $ListeRestante $iTrouve] $DebutNom end] "%s" Nom
    set ListeRestante [lrange $ListeRestante [expr $iTrouve+1] end]

    regsub -nocase [PreFixe] $Nom [PreFixe] Nom

    if {$DontDisplay} { return $Nom }
    return [PositionneEtInforme $Nom $K $Next]
}

proc PositionneEtInforme {Nom K {Next ""}} {
JeMeSignale
    global ScrollRectangleOriginal IdScrollRectangle
    global RepertoireDuGenome
    global NePasEffacerLesRepereBox
    global KanvaCourant
    
#    puts stderr "PositionneEtInforme [Box $Nom nom]"
    
    
    if {[Box $Nom nom] != $Nom} {
	if { $K=="OrdrePourGif"} { return "rien" }
	return $K
    }

    if {$K==""} { set K $KanvaCourant }

    scan "[$K coords [set IdScrollRectangle($K)]]" "%f %f %f %f" xMin  yMin  xMax  yMax
    scan "[set ScrollRectangleOriginal($K)]"      "%f %f %f %f" xMinO yMinO xMaxO yMaxO
    
#    puts stderr "$xMin  $yMin  $xMax  $yMax $xMinO $yMinO $xMaxO $yMaxO"
    
    if {[regexp "rond" $K]} {
	if { ! [info exists NePasEffacerLesRepereBox]} {
	    set LesId [$K find withtag "RepereBox"]
	    foreach Id $LesId {
		$K delete $Id
	    }
	}
	Aiguille $Nom "black" $K "RepereBox" "milieu"
    } else {
	set Milieu [expr ([Box $Nom debut]+[Box $Nom fin])/2]
	set Fraction [expr ($Milieu-$xMinO)/($xMaxO-$xMinO)]
#	puts stderr "$Milieu $Fraction"
	$K xview moveto $Fraction
	$K xview scroll -5 units
    }
    if { $K=="OrdrePourGif"} { return "$Nom $Fraction" }
    if { ! [regexp "SansInforme" $Next] && [file exists "$RepertoireDuGenome/infos/$Nom"]} {
	Informe $Nom
    }
    return $K
}

proc ShowBoxAction {{Action "Enter"}} {
    global RepertoireDuGenome
    global ShowBoxEnter DefautShowBoxEnter
    global ShowBoxClic  DefautShowBoxClic
    
    if {$Action!="Which" && ($Action=="EnterDefaults" || ! [info exists ShowBoxEnter])} {
	set ShowBoxEnter(Definition)     1
	set ShowBoxEnter(OrthoOperons)   [file exists "$RepertoireDuGenome/fiches/oooperons"]
	set ShowBoxEnter(OrthoTBlastN)   [file exists "$RepertoireDuGenome/fiches/ootblastn"]
	set ShowBoxEnter(OrthoBlastP)    [file exists "$RepertoireDuGenome/fiches/ooblastp"]
	set ShowBoxEnter(OrthoMissed)    [file exists "$RepertoireDuGenome/fiches/oomsf"]
	set ShowBoxEnter(OrthoDbClustal) [file exists "$RepertoireDuGenome/fiches/oomsf"]
	if {[PreFixe]=="PEROX"} {
	    set ShowBoxEnter(OrthoDbClustal) 0
	    set ShowBoxEnter(OrthoTBlastN)   0
	}
    }
    Wup "Clic ne sert pas encore"
    if {$Action=="Clic" ||  ! [info exists ShowBoxClic]} {
	foreach R [LesRepertoiresPourSeeAbyShow] {
	    set ShowBoxClic($R) 0
	}
    }

    if {$Action=="Which"} {
	set Entete "When you enter in a box it appears :"
	set Affiche [list $Entete]
	if { ! [info exists ShowBoxEnter]} {
	    FaireLire "$Entete nothing. (You can choose an action)"
	} else {
	    foreach {Act ValShowBoxEnter} [array get ShowBoxEnter] {
		if { ! $ValShowBoxEnter} { continue }
		lappend Affiche $Act
	    }
	    FaireLire [join $Affiche "\n"]
	}
	return
    }

    foreach Act [array names ShowBox$Action] {
	set DefautShowBox[set Action]($Act) [set ShowBox[set Action]($Act)]
    }
    if {$Action=="Which" || $Action=="EnterDefaults" || $Action=="ClicDefaults"} { return }
    set Tableau [CochonsLes ShowBox$Action DefautShowBox$Action]
    if {$Tableau=="ShowBoxClic"} {
	set LesDevant {}
	foreach {K V} [array get ShowBoxClic] {
	    if {$V==0} { continue }
	    lappend LesDevant $K
	}
	return [LesRepertoiresPourSeeAbyShow "PutInFront" $LesDevant]
    }
}

proc ShowBox {K X Y Action} {
    global ShowBoxEnter
    global YaQuelquUnDansShowBox
    global OnEstSortiDUneBox
    global SeparationShowBox
    global LesEvenementsShowBox

    Wup "Pour ne pas revenir pendant le traitement"
    if {[info exists YaQuelquUnDansShowBox] && $YaQuelquUnDansShowBox} {
	if { $Action == "Leave" } { set OnEstSortiDUneBox 1 }
	return
    }

    regsub ".canvas" $K ".message" M
    catch {destroy $M}

    set Boite [BoiteDuCourant $K $X $Y]
    if { $Boite == "" || [regexp "GLIMMER" $Boite] } { return }
    set Nom [Box $Boite nom]

    if { $Action == "Fixe"} {
	return "JeNeSaisPasCeQueFaitFixe"
    }
    if { $Action == "Leave" } {
	set OnEstSortiDUneBox 1
	return ""
    }
    set OnEstSortiDUneBox 0

    set YaQuelquUnDansShowBox 1

    set LesLignes {}
    if {[info exists ShowBoxEnter(Definition)] && [set ShowBoxEnter(Definition)]} {
	if {[set DE [Definition $Nom "ApproxDansInfo"]]!=""} {
	    regsub { +ID\:.*} $DE "" DE
	    while {[string length $DE]>100} {		
		lappend LesLignes [string trim [string range $DE 0 99]]
		set DE [string range $DE 100 end]
	    }
	    lappend LesLignes [string trim $DE]
	}
    }
    set QuelsOrthos {}
    if {[info exists ShowBoxEnter(OrthoOperons)] && [set ShowBoxEnter(OrthoOperons)]} {
	lappend QuelsOrthos "O"
    }
    if {[info exists ShowBoxEnter(OrthoTBlastN)] && [set ShowBoxEnter(OrthoTBlastN)]} {
	lappend QuelsOrthos "T"
    }
    if {[info exists ShowBoxEnter(OrthoBlastP)] && [set ShowBoxEnter(OrthoBlastP)]} {
	lappend QuelsOrthos "P"
    }
    if {[info exists ShowBoxEnter(OrthoMissed)] && [set ShowBoxEnter(OrthoMissed)]} {
	lappend QuelsOrthos "M"
    }
    if {[info exists ShowBoxEnter(OrthoDbClustal)] && [set ShowBoxEnter(OrthoDbClustal)]} {
	lappend QuelsOrthos "A"
    }

    if {$QuelsOrthos!={}} {
	lappend LesLignes [RecapitulatifDesOrthologues $Nom [join $QuelsOrthos ""]]
    }

    set Texte [join $LesLignes "\n"]

    if {$OnEstSortiDUneBox} {
	set YaQuelquUnDansShowBox 0
	return ""
    }
    if {$Texte!=""} {
	label $M -borderwidth 3 -font {Courier 10} -relief raise \
		-background "lightyellow" -foreground "black" -justify left -anchor w \
		-text $Texte
	if {$Y < 200} { set dY 40 ; set Anc "nw" } else { set dY -40 ; set Anc "sw" }
	place $M -x 10 -y [expr $Y+$dY] -anchor $Anc
	update idletasks
    }
    set YaQuelquUnDansShowBox 0
    return $M
}

proc ChargeADNetTDNetRAC {{Extension ""}} {
    global RepertoireDuGenome
    global ADN TDN RAC

    set Fadn "$RepertoireDuGenome/beton/adn$Extension"
    set Ftdn "$RepertoireDuGenome/beton/tdn$Extension"
    set Frac "$RepertoireDuGenome/beton/rac$Extension"

    if {[OnTraiteDesCDS] && ! [file exists $Fadn]} {
	set Dernier [DernierPAB "EnPosition" "AvecBornes"]
	scan $Dernier "%s %d %d %s" PAB Debut Fin Orient
	incr Fin 1000
	set ADN [string repeat "n" $Fin]
	foreach PAB [ListeDesPABs] {
	    set Debut  [Box $PAB debut]
	    set Fin    [Box $PAB fin]
	    set Orient [Box $PAB orient]
	    set FiNucTFA "[RepertoireDuGenome]/nuctfa/$PAB"
	    if { ! [file exists $FiNucTFA]} { continue }
	    set SeqNuc [QueLaSequenceDuFichierTFA $FiNucTFA]
	    if {$Orient=="F"} {
		set ADN [string replace $ADN $Debut $Fin $SeqNuc]
	    } else {
		set RacSeqNuc [NucToReverseAndComplementNuc $SeqNuc]
		set ADN [string replace $ADN $Debut $Fin $RacSeqNuc]
	    }
	}
	set TDN "n[NucToComplementNuc $ADN]"
	set RAC "n[NucToReverseAndComplementNuc $ADN]"
	return "ADNetTDNetRACFromNucTFA"
    }

    if { ! [file exists $Fadn]} {
	return "ADNetTDNetRACNotAvailable"
    } 

    set f [open $Fadn "r"]
    gets $f ADN
    close $f
    set f [open $Ftdn "r"]
    gets $f TDN
    close $f
    set f [open $Frac "r"]
    gets $f RAC
    close $f

    return "ADNetTDNetRACFromBeton"

}

proc CouleurDeLaBoite {Boite TypeDeCouleur} {
    global RepertoireDuGenome
    global CouleurDeFrame
    global CouleurDuFond

    set Nom [Box $Boite nom]

    return [CouleurParTypeEtNom $TypeDeCouleur $Nom]
}

proc FetcheBox {K X Y {Quoi "Show"}} {
    global RepertoireDuGenome
    
    if {[YaPABouTROUouTRNAouARNdans $X]} {
	set Boite $X
    } else {
	set Boite [BoiteDuCourant $K $X $Y]
    }
    
    if { $Boite == "" } { return }

    set Nom [Box $Boite nom]

    if {[regexp "GLIMMER" $Nom]} {
	return [AfficheNuc $Nom]
    }
    return [SeeAby $Quoi $Nom]

    set Fichier "BidonBidon"
    if { [YaPABdans                $Nom] } { set Fichier "$RepertoireDuGenome/msf/$Nom" }
    if { [regexp {TROU[0-9]*[A-F]} $Nom] } { set Fichier "$RepertoireDuGenome/trousmsf/$Nom" }
    if { [regexp {TROU[0-9]*N}     $Nom] } { set Fichier "$RepertoireDuGenome/trousmsf/$Nom" }
    if { [regexp {TRNA|ARN}        $Nom] } { set Fichier "$RepertoireDuGenome/msf/$Nom" }
    if {[file exists $Fichier]} {
	return [SeeAby Show $Nom]
    }

    if { [YaPABdans                $Nom] } { set Fichier "$RepertoireDuGenome/prottfa/$Nom" }
    if { [regexp {TROU[0-9]*[A-F]} $Nom] } { set Fichier "$RepertoireDuGenome/trousprottfa/$Nom" }
    if { [regexp {TROU[0-9]*N}     $Nom] } { set Fichier "$RepertoireDuGenome/nuctfa/$Nom" }
    if { [regexp {TRNA|ARN}        $Nom] } { set Fichier "$RepertoireDuGenome/nuctfa/$Nom" }
    if {[file exists $Fichier]} {
	return [AfficheFichier $Fichier "AvecSeeBlastAvecBlasteAvecFormate"]
    }

    if { [YaPABdans                $Nom] } { set Fichier "$RepertoireDuGenome/ver/$Nom" }
    if { [regexp {TROU[0-9]*[A-F]} $Nom] } { set Fichier "$RepertoireDuGenome/trousprottfa/$Nom" }
    if { [regexp {TROU[0-9]*N}     $Nom] } { set Fichier "$RepertoireDuGenome/nuctfa/$Nom" }
    if { [regexp {TRNA|ARN}        $Nom] } { set Fichier "$RepertoireDuGenome/nuctfa/$Nom" }
    if {[file exists $Fichier]} {
	return [AfficheFichier $Fichier "AvecSeeBlastAvecBlasteAvecFormate"]
    }
}

proc BoiteDuCourant {K X Y} {
    global MemoBoiteDuCourantKXY MemoBoiteDuCourantRetour

    if {[info exists MemoBoiteDuCourantKXY] && $MemoBoiteDuCourantKXY=="$K$X$Y"} {
	return $MemoBoiteDuCourantRetour
    }
    
    set MemoBoiteDuCourantKXY "$K$X$Y"
    set MemoBoiteDuCourantRetour ""

    set x [$K canvasx $X]
    set y [$K canvasy $Y]
    set Courants [$K find withtag current]
    foreach Id $Courants {
	set SesTags [$K gettags $Id]
	if { [lindex $SesTags 0] == "Box" } {
	    set MemoBoiteDuCourantRetour [lindex $SesTags 1]
	    break
	}
	if { [lindex $SesTags 0] == "TEXTE" } {
	    set MemoBoiteDuCourantRetour [StringApres "Txt_" dans [lindex $SesTags 1]]
	    break
	}
    }
    return $MemoBoiteDuCourantRetour
}

proc BoundingBoxDuGenome {} {
    global BoundingBoxDuGenome
    if { ! [info exists BoundingBoxDuGenome]} {
	set DF [BoundingBox [ListeDeBoites]]
	scan $DF "%d %d" xDebut xFin
	set xDebut [Maxi 0 [expr $xDebut-3000]]
	incr xFin  1000
	set BoundingBoxDuGenome "$xDebut $xFin"
    }
    return $BoundingBoxDuGenome
}

proc BoundingBox UneListeDeBoites {
    set xMin  999999999
    set xMax -999999999
    foreach Boite $UneListeDeBoites {
	set xMin [Mini $xMin [Box $Boite debut]]
	set xMax [Maxi $xMax [Box $Boite fin]]
    }
    return "$xMin $xMax"
}

proc Box {Boite Arg {Valeur ""}} {
    global ContenusDesBox
    global ListeDeBoites

    if { $Valeur != "" } {
	set ContenusDesBox($Boite,$Arg) $Valeur
	return $Valeur
    }

    if { ! [info exists ListeDeBoites]} { ChargeListeDeBoites }

    if { ! [info exists ContenusDesBox($Boite,$Arg)] } { return "" }
    return [set ContenusDesBox($Boite,$Arg)]
}


Index by: file name | procedure name | procedure call | annotation
File generated 2022-04-05 at 12:55.