diff --git a/Gruntfile.js b/Gruntfile.js index 4151281..2036830 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -170,4 +170,53 @@ module.exports = function(grunt) { grunt.registerTask('build', ['build_x', 'copy:dist', 'copy:dist-examples', 'jsdoc']); + + var browserify = require("browserify"); + var mkdirp = require("mkdirp"); + var fs = require("fs"); + + grunt.registerTask('patch-pviz', 'Makes pviz work for node', function(){ + var done = this.async(); + console.log("patching amd"); + + var outFile = 'dist/pviz-bundle.js'; + var modFile = 'dist/pviz.mod.js'; + fs.readFile(outFile, "utf8", function(err,data){ + // patch the AMD output - this is VERY ugly (but works) + // first patch: backbone-amd needs to be instantiated in via AMD + //data = data.replace(/if \(typeof exports !== 'undefined'\) {\s+?\n\s+\/\/ Node\/CommonJS, no need for jQuery in that case\./, "if (typeof exportsNotDefined !== 'undefined') {"); + data = data.replace(/if \(typeof exports !== 'undefined'\) {\s+?\/\/ Node\/CommonJS, no need for jQuery in that case\./, "if (typeof exportsNotDefined !== 'undefined') {"); + + // second patch: somehow there is sth. wrong with the backbone version and its + // router + data = data.replace("_.bindAll(this, 'checkUrl');", "//_.bindAll(this, 'checkUrl');"); + + console.log("patching finished"); + fs.writeFile(modFile,data, function(){ + done(); + }); + }); + }); + + grunt.registerTask('build-browser', function(){ + // task is async + var done = this.async(); + + // create tmp dir + mkdirp("build"); + + var packageConfig = require("./package.json"); + + // local test build + var outFile = 'build/pviz.local.js'; + var wsExport = fs.createWriteStream(outFile); + wsExport.on('finish', function () { + done(); + }); + + var b = browserify({debug: false,hasExports: true, insertGlobalVars: []}); + b.add('./index.js', {expose: packageConfig.name }); + b.bundle().pipe(wsExport); + }); + grunt.registerTask('browserify', ['build_x','copy:dist', 'patch-pviz','build-browser']); }; diff --git a/build-tools/end.frag.txt b/build-tools/end.frag.txt index 28ccfd8..a890c9f 100644 --- a/build-tools/end.frag.txt +++ b/build-tools/end.frag.txt @@ -2,5 +2,5 @@ //this snippet. Ask almond to synchronously require the //module value for 'main' here and return it as the //value to use for the public API for the built file. - return require('PVizExport'); -})); \ No newline at end of file + return requirejs('PVizExport'); +})); diff --git a/build-tools/start.frag.txt b/build-tools/start.frag.txt index 44bc6fb..4c43cdb 100644 --- a/build-tools/start.frag.txt +++ b/build-tools/start.frag.txt @@ -36,11 +36,13 @@ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. //see this AMD call, not the internal modules in //the closure below. define(factory); - } else { + } else if(typeof exports !== "undefined"){ + module.exports = factory(); + }else { //Browser globals case. Just assign the //result to a property on the global. root.pviz = factory(); } }(this, function () { //almond, and your modules will be inlined here - \ No newline at end of file + diff --git a/index.js b/index.js new file mode 100644 index 0000000..13d1cdc --- /dev/null +++ b/index.js @@ -0,0 +1,2 @@ +_ = require("underscore"); +module.exports = require("./dist/pviz.mod.js"); diff --git a/package.json b/package.json index 9bde3e9..92ffb0c 100644 --- a/package.json +++ b/package.json @@ -1,20 +1,49 @@ { "name": "pviz", - "version": "0.1.10", - "dependencies": {}, + "version": "0.1.12-2", + "description": "pViz.js is a protein sequence features viewer for modern browsers", + "repository": { + "type": "git", + "url": "github.com/genentech/pviz" + }, + "dependencies": { + "underscore": "^1.4.4" + }, "devDependencies": { + "biojs-sniper": "^0.1.0", + "bower": "~1.2.8", + "browserify": "^6.3.2", "grunt": "~0.4.2", + "grunt-bower-requirejs": "~0.8.0", + "grunt-cli": "~0.1.11", + "grunt-contrib-clean": "~0.5.0", + "grunt-contrib-concat": "~0.3.0", + "grunt-contrib-copy": "~0.4.1", "grunt-contrib-jshint": "~0.7.2", "grunt-contrib-uglify": "~0.2.7", "grunt-contrib-watch": "~0.5.3", - "bower": "~1.2.8", - "grunt-bower-requirejs": "~0.8.0", "grunt-devserver": "~0.5.0", + "grunt-jsdoc": "^0.5.6", "grunt-requirejs": "~0.4.0", - "grunt-contrib-concat": "~0.3.0", - "grunt-cli": "~0.1.11", - "grunt-contrib-copy": "~0.4.1", - "grunt-contrib-clean": "~0.5.0", - "grunt-jsdoc": "^0.5.6" - } + "mkdirp": "^0.5.0" + }, + "scripts": { + "prepublish": "bower install && grunt build browserify", + "sniper": "biojs-sniper ." + }, + "main": "./index.js", + "sniper": { + "js": [ + "/build/pviz.local.js" + ], + "css": [ + "/src/css/pviz-core.css" + ], + "first": "example-0" + }, + "keywords": [ + "feature", + "annotation", + "biojs" + ] } diff --git a/snippets/example-0.js b/snippets/example-0.js new file mode 100644 index 0000000..7ca6ab7 --- /dev/null +++ b/snippets/example-0.js @@ -0,0 +1,134 @@ +var pviz = require("pviz"); + +//define the model, a sequence entry with an explicit sequence +var seq = 'MELAALCRWGLLLALLPPGAASTQVCTGTDMKLRLPASPETHLDMLRHLYQGCQVVQGNLELTYLPTNASLSFLQDIQEVQGYVLIAHNQVRQVPLQRLRIVRGTQLFEDNYALAVLDNGDPLNNTTPVTGASPGGLRELQLRSLTEILKGGVLIQRNPQLCYQDTILWKDIFHKNNQLA'; +var seqEntry = new pviz.SeqEntry({ + sequence : seq +}); + +/* + * thefined the view, in a backbone.js fashion + * model: that's the model, who would have guessed + * el: a selector to the target where to insert the view (size and so will be inherited) + * + * .render(): call the rendering + * + * NB: even though the features are not yet added to the model, the view will be recomputed at the end of any feature addition. + * This is to take into account asynchroncity, when data comes from several remote sources + */ +new pviz.SeqEntryAnnotInteractiveView({ + model : seqEntry, + el : yourDiv +}).render(); + +/* we can add featureswith properties + * group: features will be grouped together on this property. they might no be displayed on the same line, but feature with different grous cannot be on the same line + * type: within group, property can have different types + * text: to be displayed or use wherever you want + * start: initial position, starting at 0 + * end: last position of the feature (including), starting at 0 + * + * NB: the explicit loading of features could be replaced by a JSON call. But for the sake of a standalone example, ajax does not work with file queries + d3.tsv('example-features.tsv', function(err, data) { + seqEntry.addFeatures(data); + }); + */ +seqEntry.addFeatures([{ + category : 'ptms', + type : 'mickey', + start : 20, + end : 20, + count : 10 +}, { + category : 'ptms', + type : 'mickey', + start : 22, + end : 22, + count : 3 +}, { + category : 'ptms', + type : 'mickey', + start : 40, + end : 40, + count : 10, + improbable : true //!! an option attribute +}, { + category : 'ptms', + type : 'mickey', + start : 50, + end : 50, + count : 2 +}, { + category : 'regions', + type : 'topological domain', + text : 'extra cellular', + start : 22, + end : 650 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 24, + end : 26 +}, { + category : 'secondary structure', + type : 'helix', + start : 38, + end : 49 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 53, + end : 57 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 59, + end : 63 +}, { + category : 'secondary structure', + type : 'helix', + start : 71, + end : 73 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 78, + end : 81 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 83, + end : 87 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 91, + end : 94 +}, { + category : 'secondary structure', + type : 'turn', + start : 108, + end : 110 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 111, + end : 116 +}, { + category : 'secondary structure', + type : 'turn', + start : 129, + end : 131 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 138, + end : 140 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 150, + end : 155 +}]); + +