Giter Site home page Giter Site logo

power_calculator's Introduction

#CSG CaTS power calculator

CaTS is an interactive power calculator for genetic association studies.

power_calculator's People

Contributors

jenlij avatar frencil avatar

Stargazers

Freeman Wang avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

frencil

power_calculator's Issues

Refactor PHP script to return proper HTTP codes and JSON objects

As discussed today, the PHP script processing an ajax request should:

  1. Return HTTP error codes (such as 400 - Bad Request) when something goes wrong, instead of just text
  2. Return a data object on success so that the client side is fully responsible for how to do the formatting of the result

Here's a sample refactored PHP script. It hasn't been tested!

<?php

//variables from user input
$ncases = intval($_POST['ncases']);
$ncontrols = intval($_POST['ncontrols']);
$pisamples = floatval($_POST['pisamples']);
$pimarkers = floatval($_POST['pimarkers']);
$freq = floatval($_POST['freq']);
$risk = floatval($_POST['risk']);
$prevalence = floatval($_POST['prevalence']);
$alpha = floatval($_POST['alpha']);

//command line input
$cmdstr = '/usr/cluster/bin/CaTS';
$cmdstr .= ' --cases '.$ncases.' --controls '. $ncontrols.' --pisamples '. $pisamples.' --pimarkers '.$pimarkers.' --freq '. $freq.' --risk '.$risk.' --prevalence '.$prevalence.' --alpha '.$alpha;
$outVal = exec($cmdstr);

$error = "I don't like the genetic model you requested!";
if ($outVal == $error) {
    http_response_code(400);
    exit;
} else {   
    $data = explode(" ", $outVal);
    $json = [
      "genotypeAA" => [
        "frequency"  => $data[0],
        "percentage" => $data[1]
      ],
      "genotypeAB" => [
        "frequency"  => $data[2],
        "percentage" => $data[3]
      ],
      "genotypeBB" => [
        "frequency"  => $data[4],
        "percentage" => $data[5]
      ],
      "power"      => $data[8],
      "cases"      => $data[6],
      "controls"   => $data[7]
    ];
    echo json_encode($json);
    exit;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.