Display a HISTOGRAM module step by step

0. Download all files in this tutorial.

Download HISTOGRAM.zip and click *.html file(in HISTOGRAM.zip) to open this demo in local browser!.

1. Input data.

    Example file: HISTOGRAM01.txt

    Data structure

    Users should prepare the input data in the following format (separated by tabs).

    #chr    start   end     name    value
    2L      1       1011544 test histogram  0.8
    2L      1011548 2011544 test histogram  0.3
    2L      2011548 3011544 test histogram  0.1
    2L      2011545 2011546 test histogram  0.01
    ......
    X       18011548        19011544        test histogram  0.83
    X       19011548        20011544        test histogram  0.39
    X       20011548        21146708        test histogram  0.49
    X       21011548        22422827        test histogram  0.83
    

    Following fields are required:

    • The 1 column(chr) is the name of the chromosome.

    • The 2 column(start) is the start of the region.

    • The 3 column(end) is the end of the region.

    • The 4 column(name) is the name of the region.

    • The 5 column(value) is the value of the region.

2. Prepare module through python script.

    Use:

    python NGCircos_PrepareData.py HISTOGRAM HISTOGRAM01.txt > HISTOGRAM01.js

    Example file: HISTOGRAM01.js

    Details in js file:

    var HISTOGRAM01 = [ "HISTOGRAM01" , {
      maxRadius: 220,
      minRadius: 185,
      histogramFillColor: "#FF6666",
    } , [
      {chr: "2L", start: "1", end: "1011544", name: "test histogram", value: "0.8"},
      {chr: "2L", start: "1011548", end: "2011544", name: "test histogram", value: "0.3"},
      {chr: "2L", start: "2011548", end: "3011544", name: "test histogram", value: "0.1"},
      {chr: "2L", start: "2011545", end: "2011546", name: "test histogram", value: "0.01"},
      ......
      {chr: "X", start: "18011548", end: "19011544", name: "test histogram", value: "0.83"},
      {chr: "X", start: "19011548", end: "20011544", name: "test histogram", value: "0.39"},
      {chr: "X", start: "20011548", end: "21146708", name: "test histogram", value: "0.49"},
      {chr: "X", start: "21011548", end: "22422827", name: "test histogram", value: "0.83"},
    ]];
        
    Note: explaination for each parameter is available in document

3. Including HISTOGRAM data

    Use <script> tag to include HISTOGRAM01.js.

    <script src="js/HISTOGRAM01.js"></script> 

4. Initialize NG-Circos with HISTOGRAM data

    Prepare a <div> tag with “example” id to set the picture position your will draw in html, e.g.:

    NGCircos01 = new NGCircos(HISTOGRAM01,NGCircosGenome,{ // Initialize with "HISTOGRAM01" data tag

5. Source code

    When step 1 to 4 are finished, the configuration for NGCircos:

    <button class="svg-action-btn download-img" style="height: 18px;line-height: 18px;padding: 0 11px;background: #FFFFFF;border: 1px #D9D9D9 solid;border-radius: 3px;display: inline-block;font-size: 12px;outline: none;color: black">Download png ↓</button>
    <a href="javascript:(function () { var e = document.createElement('script');if (window.location.protocol === 'https:') { e.setAttribute('src', './lib/svg-crowbar.js'); } else { e.setAttribute('src', './lib/svg-crowbar.js'); } e.setAttribute('class', 'svg-crowbar'); document.body.appendChild(e); })();" style="height: 18px;line-height: 18px;padding: 0 11px;background: #FFFFFF;border: 1px #D9D9D9 solid;border-radius: 3px;display: inline-block;font-size: 12px;outline: none;color: black" >Download svg ↓</a>
    <div id="NGCircos"></div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-12">
                        <div id="NGCircos"></div>
                    </div>
                </div>
    <!-- Data configuration -->
    <script src="./lib/jquery.js"></script>
    <script src="./lib/d3.js"></script>
    <script src="./lib/NGCircos.js"></script>
    <script src="js/HISTOGRAM01.js"></script>
    <!-- Genome configuration -->
    <script>
    var NGCircosGenome = [      // Configure your own genome here.
        [
         ["2L" , 23011544],
         ["2R" , 21146708],
         ["3L" , 24543557],
         ["3R" , 27905053],
         ["X" , 22422827],
         ["4" , 1351857]
        ]
      ];
      NGCircos01 = new NGCircos(HISTOGRAM01,NGCircosGenome,{       // Initialize NGCircos.js with "NGCircosGenome" and Main configuration
         target : "NGCircos",                              // Main configuration "target"
         svgWidth : 900,                                  // Main configuration "svgWidth"
         svgHeight : 600,                                 // Main configuration "svgHeight"
         innerRadius: 246,
         outerRadius: 252,
         ticks : {
            display : true,
            len : 5,
            color : "#000",
            textSize : 8,
            textColor : "#000",
            scale : 5000000
         },
         genomeLabel : {
            display : true,
            textSize : 16,
            textColor : "#000",
            dx : 3.14,
            dy : "-0.95em"
         },
         HISTOGRAMMouseEvent: true,
         HISTOGRAMMouseOutDisplay: true,
         HISTOGRAMMouseOutAnimationTime: 500,
         HISTOGRAMMouseOutColor: "red",
         HISTOGRAMMouseOutOpacity: 1,
         HISTOGRAMMouseOutStrokeColor: "red",
         HISTOGRAMMouseOutStrokeWidth: 0,
         HISTOGRAMMouseOverDisplay: true,
         HISTOGRAMMouseOverColor: "red",
         HISTOGRAMMouseOverOpacity: 1,
         HISTOGRAMMouseOverStrokeColor: "#F26223",
         HISTOGRAMMouseOverStrokeWidth: 3,
      });
      NGCircos01.draw_genome(NGCircos01.genomeLength);  // NGCircos.js callback
      NGCircos01.draw_genome(NGCircos01.genomeLength2); // NGCircos2.js callback second time
    </script>
    <script src="./lib/saveSvgAsPng.js"></script>
    <script>
    
          (function(){
            var downloadImg = getEle(".download-img"),
              imgName = getEle("."+NGCircos01.svgClassName);
    
            //          imgScale = getEle(".img-scale");
    
            downloadImg.addEventListener("click",function(){
              var mySvg = getEle("."+NGCircos01.svgClassName),
                //iImgScale = parseInt(imgScale.value) || 1,
                oImgName = imgName.value || NGCircos01.svgClassName;
    
    //          saveSvgAsPng(mySvg, oImgName+".png", iImgScale);
              saveSvgAsPng(mySvg, oImgName+".png");
    
            })
    
            function getEle(obj){
              var d = document;
              return d.querySelector(obj);
            }
          })()
    </script>

6. Visualization of HISTOGRAM data using NG-Circos

Download svg ↓