   end
 
   def menu_types(species, group) do
-    query = """
-    select distinct Tissue.Name
-    from ProbeFreeze,ProbeSetFreeze,InbredSet,Tissue,Species
-    where Species.Name = '#{species}' and Species.Id = InbredSet.SpeciesId and
-      InbredSet.Name = '#{group}' and
-      ProbeFreeze.TissueId = Tissue.Id and
-      ProbeFreeze.InbredSetId = InbredSet.Id and
-      ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id and
-      ProbeSetFreeze.public > 0
-      order by Tissue.Name
-    """
-    {:ok, rows} = DB.query(query)
-    for r <- rows, do: ( {tissue} = r; [tissue] )
+    # query = """
+    # select distinct Tissue.Name
+    # from ProbeFreeze,ProbeSetFreeze,InbredSet,Tissue,Species
+    # where Species.Name = '#{species}' and
+      # Species.Id = InbredSet.SpeciesId and
+      # InbredSet.Name = '#{group}' and
+      # ProbeFreeze.TissueId = Tissue.Id and
+      # ProbeFreeze.InbredSetId = InbredSet.Id and
+      # ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id and
+      # ProbeSetFreeze.public > 0
+      # order by Tissue.Name
+    # """
+    # {:ok, rows} = DB.query(query)
+    # for r <- rows, do: ( {tissue} = r; [tissue] )
+
+    query = from tab_species in Species,
+      join: inbredset in InbredSet,
+      on: tab_species.id == inbredset."SpeciesId",
+      join: probefreeze in ProbeFreeze,
+      on: probefreeze."InbredSetId" == inbredset.id,
+      join: tissue in Tissue,
+      on: probefreeze."TissueId" == tissue.id,
+      join: probesetfreeze in ProbeSetFreeze,
+      on: probesetfreeze."ProbeFreezeId" == probefreeze.id,
+      where: tab_species."Name" == ^species and
+             inbredset."Name" == ^group and
+             probesetfreeze.public > 0,
+      select: {tissue."Name"},
+      distinct: true,
+      order_by: tissue."Name"
+
+      Repo.all(query) |> Enum.map(&(Tuple.to_list(&1)))
   end
 
   def menu_datasets(species, group, type) do

  end

  def marker_info(species,marker) do
      query = """
SELECT Geno.Chr, Geno.Mb, Species.Id,Geno.source FROM Geno, Species
WHERE Species.Name = '#{species}'
AND Geno.Name = '#{marker}'
     """
     query = from tab_species in Species,
     join: geno in Geno,
     on: tab_species."SpeciesId" == geno."SpeciesId",
     where: tab_species."Name" == ^species and geno."Name" == marker,
     select: {geno."Chr", geno."Mb", tab_species.id, geno.source}

    # {:ok, rows} = DB.query(query)
    Repo.all(query) |> Enum.map(&(
      {chr_name,chr_len,species_id,source} = &1
      %{
        species: species,
        species_id: species_id,

        chr:     chr_name,
        chr_len: chr_len
      } 
    end

    Repo.all(query) |> Enum.map(from_tuple_to_structure)

    
    # for r <- rows, do: ( {chr_name,chr_len,species_id,source} = r;
