Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-boolean results e.g. percentages #6

Closed
mathiasbynens opened this issue Apr 26, 2015 · 3 comments
Closed

Non-boolean results e.g. percentages #6

mathiasbynens opened this issue Apr 26, 2015 · 3 comments

Comments

@mathiasbynens
Copy link
Contributor

http://www.snpedia.com/index.php/Gs122/criteria (I’m working on a repo for this one btw) is an example of a genoset for which each criterium has a certain weight that contributes to the end result.

# gs122 looks for increased risk of baldness based on
# 
# rs6625163(A;A) 1.2 (increased risk of baldness)
# rs1160312(A;A) 2 (1.6x increased risk of Male Pattern Baldness.)
# rs1160312(A;G) 2 (1.6x increased risk of Male Pattern Baldness.)
# rs201571(T;T) 2 (more likely to go bald)
# rs6036025(G;G) 1.2 (more likely to go bald)

The number e.g. the 1.2 following rs6625163(A;A) is the magnitude value as provided by SNPedia.

Should there be a way to give each criterium a weight in gql queries? If so, any ideas on what the API should look like? Discuss.

@yocontra
Copy link
Member

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...
]);

@mathiasbynens
Copy link
Contributor Author

mathiasbynens commented May 8, 2015

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.

@yocontra
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants