Giter Club home page Giter Club logo

Comments (3)

yocontra avatar yocontra commented on July 27, 2024

Naive early morning attempt but here are a few possible APIs, slowly getting sugarier

var test = gql.percentage([
  {test: gql.exact('rs6625163', 'AA'), magnitude: 1.2},
  {test: gql.exact('rs1160312', 'AA'), magnitude: 2},
  {test: gql.exact('rs1160312', 'AG'), magnitude: 2},
  {test: gql.exact('rs201571', 'TT'), magnitude: 2},
  {test: gql.exact('rs6036025', 'GG'), magnitude: 1.2}
]);

test(someDNA); // 85
// gql.magnitude would have to error when being used outside of a percentage
// also kind of breaks the whole "everything is a function" thing
// also magnitude should probably be the second arg here but i was too lazy to change the code
var test = gql.percentage([
  gql.magnify(1.2, gql.exact('rs6625163', 'AA')),
  gql.magnify(2, gql.exact('rs1160312', 'AA')),
  gql.magnify(2, gql.exact('rs1160312', 'AG')),
  gql.magnify(2, gql.exact('rs201571', 'TT')),
  gql.magnify(1.2, gql.exact('rs6036025', 'GG'))
]);

test(someDNA); // 85
// every gql test function would have a magnitude fn that returns a clone of the fn with a new _magnitude property that percentage knows about
// this would allow stuff like gql.percentage([isMale.magnitude(2)])
// but it also limits usage of vanilla functions without wrapping them or adding the _magnitude manually
var test = gql.percentage([
  gql.exact('rs6625163', 'AA').magnitude(1.2),
  gql.exact('rs1160312', 'AA').magnitude(2),
  gql.exact('rs1160312', 'AG').magnitude(2),
  gql.exact('rs201571', 'TT').magnitude(2),
  gql.exact('rs6036025', 'GG').magnitude(1.2)
]);

test(someDNA); // 85

We should think about how this plays into being a part of other queries. If (for example) the isMale module is not a boolean and instead returns a percentage a module that depends on it could do what amounts to gql.and([ifPercentage(isMale, 85), otherStuff...]) but at that point it might be easier/cleaner to just write it out and not have an API for that case

gql.and([
  function(dna){
    return isMale(dna) >= 85;  
  },
  otherStuff...
]);

from gql.

mathiasbynens avatar mathiasbynens commented on July 27, 2024

API-wise my preference is option 3 (although it could be a bit hairy to implement), then 2.

As a side note, Iā€™d prefer to return actual percentages, e.g. 0.85 over 85.

from gql.

yocontra avatar yocontra commented on July 27, 2024

With the new update this should be fixed - you can calculate this however you want now, the dna is just an object.

from gql.

Related Issues (8)

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.