Presets

<= Back to main page

makePresets.sql

How presets work

A preset contains a list of literal values and paramlists

Example using Preset_Displayer

     INSERT INTO heatmap_presetdisplay(name, desc, author, ops, majs, mins) VALUES
    ("DEFAULT", "Default preset", "Clement", "ALL-OPS", "ALL-MAJ", "ALL-MIN"),
    ("Expressions","Preset for displaying snoRNA expressions","Clement","Expressions-Display","ALL-MAJ","ALL-MIN");

All preset classes should have a name, a description and an author. Those are literal values

ops,majs,mins are paramlists:

  1. ops Refers to the Param property in the model. It specifies which columns from the datatable snoTHAW is allowed evaluate. It only accepts references to OperandList objects.
  2. majs Refers to the Major property in the model. It specifies what rows will be identified as (i.e Symbol, ensemblID, etc.). It only accepts references to MajorList objects.
  3. mins Refers to the Minor property in the model. It specified characteristics to display along each entry. It only accepts references to MinorList objects.

Paramlists

There are three types of Paramlists:

  1. OperandList: contains references to Operands
  2. MajorList: contains references to Majors
  3. MinorList: contains reference to Minors

They all also have a name and a description. The name will be displayed on the GUI, while the description is solely for documentation purposes (for now).

References to Operands,Majors and Minors are done through another table which makes the associations between ParamLists and Params.

For example:

    INSERT INTO heatmap_majorlist (name, desc) VALUES
        ("ALL-MAJ", "All available major labels");

Creates the MajorList “ALL-MAJ” while

    INSERT INTO heatmap_majorlist_param (majorlist_id, major_id) VALUES
        ("ALL-MAJ","atlas"),
        ("ALL-MAJ","symbol"),
        ("ALL-MAJ","ensg");

Associates the majors “atlas”, “symbol” and “ensg” with the list “ALL-MAJ”.

Params

There are three types of Params:

  1. Operands
  2. Majors
  3. Minors

All three have 2 properties: value and verbose.

For example, displaying “ensg” might be confusing to the user, by setting verbose to “EnsemblID”, its purpose becomes clearer to the end-user.

Tricks

models.py

Preset Models

As long as your Preset model contains a method named to_JSON() and a Name and Desc property is mentionned in them, your custom tools should work fine. The way the JSON is formatted is entirely up to you since you have to provide, in HeatmapToolbox, a DataParser class object to your Tool object. Note that Param and ParamList to_JSON() methods are already implemented and I suggest you use those for your ParamList references.

Example with PresetDisplayer

Model definition

#Line 200
class PresetDisplay(m.Model):
    name = m.CharField(max_length=50, primary_key=True)
    desc = m.TextField(null=True)
    author = m.CharField(max_length=50)
    ops= m.ForeignKey(OperandList, related_name='ops', db_column="ops")
    majs= m.ForeignKey(MajorList, related_name='majs', db_column="majs")
    mins= m.ForeignKey(MinorList, related_name='mins', db_column="mins")

to_JSON()

#Line 264
def to_JSON(self):
        return "{%s,%s,%s,%s,%s,%s}" % (
            "\"Author\":\"%s\"" % (self.author),
            "\"Desc\":\"%s\"" % (self.desc),
            "\"Name\":\"%s\"" % (self.name), 
            "\"Param\":%s" % (self.ops.to_JSON()),
            "\"Major\":%s" % (self.majs.to_JSON()),
            "\"Minor\":%s" % (self.mins.to_JSON()),
        )

Output of loading default preset

{
  "Author": "Clement",
  "Desc": "Default preset",
  "Name": "DEFAULT",
  "Param": [
    {
      "value": "breast",
      "verbose": "Breast"
    },
    {
      "value": "host_breast",
      "verbose": "Host Breast"
    },
    {
      "value": "host_liver",
      "verbose": "Host Liver"
    },
    {
      "value": "host_ovaries",
      "verbose": "Host Ovaries"
    },
    {
      "value": "host_prostate",
      "verbose": "Host Prostate"
    },
    {
      "value": "lengths",
      "verbose": "Lengths"
    },
    {
      "value": "liver",
      "verbose": "Liver"
    },
    {
      "value": "ovaries",
      "verbose": "Ovaries"
    },
    {
      "value": "prostate",
      "verbose": "Prostate"
    }
  ],
  "Major": [
    {
      "value": "symbol",
      "verbose": "*Symbol"
    },
    {
      "value": "ensg",
      "verbose": "Ensembl ID"
    },
    {
      "value": "atlas",
      "verbose": "~Atlas"
    }
  ],
  "Minor": [
    {
      "value": "box_type",
      "verbose": "Box Type"
    },
    {
      "value": "chr",
      "verbose": "Chromosome"
    },
    {
      "value": "conservation",
      "verbose": "Conservation"
    },
    {
      "value": "strand",
      "verbose": "Strand"
    }
  ]
}

Don’t forget to include your preset creating queries in makePresets.sql

views.py

Views contains the methods that make the vizualization objects as well as the methods that fetch preset data

Preset List Fetching

getPresetList() returns a list of presets for a given tool in a JSON format. I recommend the following line of code:

json_data = '{\"%s\":[%s]}' % (
    "Presets",
    ','.join('\"'+a.getName()+'\"' for a in PresetTOOLNAME.objects.all())
    )

Where TOOLNAME is the name of the model class in models.py for the given tool.

If you add tools, be sure to include them in the current if tree.

Preset Fetching

fetchPreset() returns the Preset model object as JSON data. I recommend the following line to fetch a preset:

json_data = PresetTOOLNAME.objects.get(name=preset).to_JSON()

Where TOOLNAME is the name of the model class in models.py for the given tool.

If you add tools, be sure to include them in the current if tree

The method to JSON-ify the data should be located in the definition of the model.