Giter VIP home page Giter VIP logo

gql's Introduction

Build Status

NPM version

Information

Packagegql
Description Query language for interpreting genome SNPs
Node Version >= 0.4

Compatibility

This query language is for use with the genomejs JSON format. See the dna2json repository for more information.

Usage

This example will create a query that determines if the gender is male.

var gql = require('gql');

var query = gql.query();
query.needs(2);
query.exact("rs2032651", "D");
query.has("rs2032651", "A");
query.has("rs9341296", "C");
query.has("rs9341296", "T");
query.has("rs13304168", "C");
query.has("rs13304168", "T");
query.has("rs1118473", "A");
query.has("rs1118473", "G");
query.has("rs150173", "A");
query.has("rs150173", "C");
query.has("rs16980426", "G");
query.has("rs16980426", "T");
query.or(query.exact("rs1558843", "C"), query.exact("rs1558843", "A"));
query.or(query.exact("rs17222419", "C"), query.exact("rs17222419", "T"));

Processing SNPs

Simple async

var async = require('async');
var snps = require('./genome.json');
async.forEach(snps, query.process.bind(query), function(){
  console.log(query.matches().length, "matches for genoset 144");
  console.log(query.percentage(), "chance that gene matches");
});

Streaming

var async = require('async');
var JSONStream = require('JSONStream');
var fs = require('fs');

var jsonStream = fs.createReadStream('./genome.json');

var queryStream = query.stream();

jsonStream
  .pipe(JSONStream.parse('*'))
  .pipe(queryStream);

queryStream.on('end', function(){
  console.log(query.matches().length, "matches for genoset 144");
  console.log(query.percentage(), "chance that gene matches");
});

API

query()

Creates a new GQL chainable query. Keep in mind that each condition is tested against one SNP at a time. If the condition is met then it is marked as a match and not tested again.

exact(id, genotype)

Evaluates to true if this was the only allele observed

q.exact("rs2032651", "D"); // will only match genotype D
q.exact("rs2032651", "AT"); // will only match genotype AT

has(id, genotype)

Evaluates to true if the allele was observed at all

q.has("rs2032651", "A"); // will match GA, GAT, AB, etc.

exists(id)

Evaluates to true if any allele has been observed

q.exists("rs2032651");

doesntExist(id)

Evaluates to true if no allele has been observed

q.doesntExist("rs2032651");

or(conditions...)

Evaluates to true if any of the argument conditions evaluates to true

q.or(q.has("rs2032651", "A"), q.doesntExist("rs2032651"));

and(conditions...)

Evaluates to true if all of the argument conditions evaluates to true

q.and(q.exists("rs2032651"), q.has("rs2032651", "A"));

add(fn)

This will let you add a custom condition. Callback signature is (error, isMatch)

q.add(function(snp, cb){
  cb(null, (snp.id === "rswhatever" && snp.genotype === "A"))
});

needs(num)

Adjusts the reporting of percentages. For example, to determine if a genome is male I only need to two matches for it to be 100% (even though I have 12 possible SNPs). 4 matches should be 200% not 33% in this scenario.

q.exact("rs2032651", "D"); // will only match genotype D
q.exact("rs2032651", "AT"); // will only match genotype AT

process(snp[, cb])

Runs the SNP through all of the conditions. If a condition is evaluated as true it will not be evaluated again and a match for it will be registered.

stream()

Turns the query into a through stream. Sugar for es.map(q.process);

percentage()

Returns expecting/matches

matches()

Returns condition matches so far

unmatched()

Returns all conditions yet to be matched

completed()

Returns true or false if all conditions have been matches

LICENSE

(MIT License)

Copyright (c) 2013 Fractal [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

gql's People

Contributors

yocontra avatar

Watchers

error.d avatar

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.