bionode-gff
Advanced tools
Comparing version 1.0.0 to 2.0.0
var fs = require('fs'); | ||
var readline = require('readline'); | ||
var stream = require('stream'); | ||
/** | ||
* | ||
* @type {{read: Function}} | ||
*/ | ||
var GFF3 = { | ||
/** | ||
* | ||
* @param path | ||
* @param onFeature | ||
* @param onEnd | ||
*/ | ||
read: function (path, onFeature, onEnd) { | ||
var events = require('events'); | ||
var gff = new events.EventEmitter(); | ||
gff.read = function (path) { | ||
var instream = fs.createReadStream(path); | ||
@@ -22,54 +17,47 @@ var outstream = new stream(); | ||
rl.on('line', function (line) { | ||
if (line.indexOf('#') != 0) { | ||
//its not a comment, ill process it | ||
if (line.indexOf('#') != 0) { | ||
//its not a comment, ill process it | ||
var parts = line.split('\t'); | ||
var parts = line.split('\t'); | ||
if (parts.length !== 9) { | ||
//the file might use spaces instead of tabs | ||
//ill try to split it by spaces | ||
parts = line.trim().split(/\s+/); | ||
} | ||
if (parts.length !== 9) { | ||
//the file might use spaces instead of tabs | ||
//ill try to split it by spaces | ||
parts = line.trim().split(/\s+/); | ||
} | ||
if (parts.length == 9) { | ||
var attParts = parts[8].split(';'); | ||
var arrayObject = {}; | ||
for (var i = 0; i < attParts.length; ++i) { | ||
var pair = attParts[i].split("="); | ||
arrayObject[pair[0]] = pair[1]; | ||
} | ||
if (parts.length == 9) { | ||
var attParts = parts[8].split(';'); | ||
var arrayObject = {}; | ||
for (var i = 0; i < attParts.length; ++i) { | ||
var pair = attParts[i].split("="); | ||
arrayObject[pair[0]] = pair[1]; | ||
} | ||
var feature = { | ||
seqid: parts[0], | ||
source: parts[1], | ||
type: parts[2], | ||
start: parts[3], | ||
end: parts[4], | ||
score: parts[5], | ||
strand: parts[6], | ||
phase: parts[7], | ||
attributes: arrayObject | ||
}; | ||
onFeature(feature); | ||
} else { | ||
console.log(parts); | ||
error(new Error('9 parts of feature not found')); | ||
var feature = { | ||
seqid: parts[0], | ||
source: parts[1], | ||
type: parts[2], | ||
start: parts[3], | ||
end: parts[4], | ||
score: parts[5], | ||
strand: parts[6], | ||
phase: parts[7], | ||
attributes: arrayObject | ||
}; | ||
gff.emit('data', feature); | ||
} else { | ||
var err = new Error('9 parts of feature not found'); | ||
gff.emit('error', err); | ||
} | ||
} | ||
} | ||
}); | ||
rl.on('close', function () { | ||
onEnd(); | ||
gff.emit('end'); | ||
}); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* | ||
* @param err | ||
*/ | ||
function error(err) { | ||
console.error(err); | ||
throw err; | ||
} | ||
module.exports = GFF3; | ||
module.exports = gff; |
{ | ||
"name": "bionode-gff", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "gff parser for nodejs", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,2 +11,5 @@ <p align="center"> | ||
[![NPM](https://nodei.co/npm/bionode-gff.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/bionode-gff/) | ||
[![Build Status](https://travis-ci.org/bionode/bionode-gff.svg)](https://travis-ci.org/bionode/bionode-gff) | ||
@@ -30,3 +33,3 @@ | ||
var ncbi = require('bionode-gff') | ||
GFF.read(filePath, onFeature, done); | ||
GFF.read(filePath).on('data',onFeatures).on('end', done); | ||
@@ -33,0 +36,0 @@ function onFeature(feature){ |
559
test/test.js
@@ -10,238 +10,32 @@ var GFF = require('../index'); | ||
describe('GFF', function () { | ||
describe('.read', function () { | ||
it('should read without error', function (done) { | ||
describe('.read', function () { | ||
it('should read without error', function (done) { | ||
function onFeature(seq) { | ||
allFeatures.push(seq); | ||
//console.log(seq.seqid); | ||
//console.log(seq.source); | ||
//console.log(seq.type); | ||
//console.log(seq.start); | ||
//console.log(seq.end); | ||
//console.log(seq.score || '.'); | ||
//console.log(seq.strand || '?'); | ||
//console.log(seq.phase || '.'); | ||
//console.log(seq.attributes); | ||
} | ||
function onFeature(seq) { | ||
allFeatures.push(seq); | ||
//console.log(seq.seqid); | ||
//console.log(seq.source); | ||
//console.log(seq.type); | ||
//console.log(seq.start); | ||
//console.log(seq.end); | ||
//console.log(seq.score || '.'); | ||
//console.log(seq.strand || '?'); | ||
//console.log(seq.phase || '.'); | ||
//console.log(seq.attributes); | ||
} | ||
GFF.read(filePath, onFeature, done); | ||
}); | ||
it('should look like a valid output', function () { | ||
assert.notStrictEqual(allFeatures, validOutput); | ||
GFF.read(filePath).on('data', onFeature).on('end', done); | ||
//GFF.read(filePath, onFeature, done); | ||
}); | ||
it('should look like a valid output', function () { | ||
assert.notStrictEqual(allFeatures, validOutput); | ||
}) | ||
}) | ||
}) | ||
}); | ||
var validOutput = [{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'gene', | ||
start: '214301', | ||
end: '215772', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {ID: 'HsG8283'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'mRNA', | ||
start: '214360', | ||
end: '215771', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: { | ||
Comments: 'fixed+one+splice+junction', | ||
Parent: 'HsG8283', | ||
Evidence: '7000000069743825', | ||
Transcript_type: 'Novel_Transcript', | ||
Name: 'Novel+Transcript%2C+variant+%28partial%29', | ||
ID: 'HsT20206' | ||
} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '214360', | ||
end: '214441', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20206'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '215299', | ||
end: '215444', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20206'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '215641', | ||
end: '215766', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20206'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'three_prime_UT', | ||
start: '215767', | ||
end: '215771', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20206'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'mRNA', | ||
start: '214590', | ||
end: '215772', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: { | ||
Comments: 'fixed+one+splice+site%0A', | ||
Parent: 'HsG8283', | ||
Evidence: '7000000069600840', | ||
Transcript_type: 'Novel_Transcript', | ||
Name: 'Novel+Transcript%2C+variant+%28partial%29', | ||
ID: 'HsT20207' | ||
} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'five_prime_UTR', | ||
start: '214590', | ||
end: '214590', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20207'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '214591', | ||
end: '214660', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20207'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '215299', | ||
end: '215444', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20207'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '215641', | ||
end: '215769', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20207'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'three_prime_UT', | ||
start: '215770', | ||
end: '215772', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20207'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'mRNA', | ||
type: 'gene', | ||
start: '214301', | ||
end: '215769', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: { | ||
Parent: 'HsG8283', | ||
Evidence: '7000000069974357', | ||
Transcript_type: 'Candidates+for+Deletion', | ||
Name: 'Novel+Transcript+%28partial%29', | ||
ID: 'HsT16028' | ||
} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'five_prime_UTR', | ||
start: '214301', | ||
end: '214302', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT16028'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '214303', | ||
end: '214460', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT16028'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '215299', | ||
end: '215467', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT16028'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'three_prime_UT', | ||
start: '215468', | ||
end: '215769', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT16028'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'mRNA', | ||
start: '215218', | ||
end: '215772', | ||
@@ -251,56 +45,263 @@ score: '.', | ||
phase: '.', | ||
attributes: { | ||
Parent: 'HsG8283', | ||
Evidence: '7000000069512231', | ||
Transcript_type: 'Novel_Transcript', | ||
Name: 'Novel+Transcript%2C+variant', | ||
ID: 'HsT16029' | ||
} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'five_prime_UTR', | ||
start: '215218', | ||
end: '215233', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT16029'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '215234', | ||
end: '215444', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT16029'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '215641', | ||
end: '215735', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT16029'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'three_prime_UT', | ||
start: '215736', | ||
end: '215772', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT16029'} | ||
}]; | ||
attributes: {ID: 'HsG8283'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'mRNA', | ||
start: '214360', | ||
end: '215771', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: { | ||
Comments: 'fixed+one+splice+junction', | ||
Parent: 'HsG8283', | ||
Evidence: '7000000069743825', | ||
Transcript_type: 'Novel_Transcript', | ||
Name: 'Novel+Transcript%2C+variant+%28partial%29', | ||
ID: 'HsT20206' | ||
} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '214360', | ||
end: '214441', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20206'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '215299', | ||
end: '215444', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20206'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '215641', | ||
end: '215766', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20206'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'three_prime_UT', | ||
start: '215767', | ||
end: '215771', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20206'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'mRNA', | ||
start: '214590', | ||
end: '215772', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: { | ||
Comments: 'fixed+one+splice+site%0A', | ||
Parent: 'HsG8283', | ||
Evidence: '7000000069600840', | ||
Transcript_type: 'Novel_Transcript', | ||
Name: 'Novel+Transcript%2C+variant+%28partial%29', | ||
ID: 'HsT20207' | ||
} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'five_prime_UTR', | ||
start: '214590', | ||
end: '214590', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20207'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '214591', | ||
end: '214660', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20207'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '215299', | ||
end: '215444', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20207'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '215641', | ||
end: '215769', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20207'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'three_prime_UT', | ||
start: '215770', | ||
end: '215772', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT20207'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'mRNA', | ||
start: '214301', | ||
end: '215769', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: { | ||
Parent: 'HsG8283', | ||
Evidence: '7000000069974357', | ||
Transcript_type: 'Candidates+for+Deletion', | ||
Name: 'Novel+Transcript+%28partial%29', | ||
ID: 'HsT16028' | ||
} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'five_prime_UTR', | ||
start: '214301', | ||
end: '214302', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT16028'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '214303', | ||
end: '214460', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT16028'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '215299', | ||
end: '215467', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT16028'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'three_prime_UT', | ||
start: '215468', | ||
end: '215769', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT16028'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'mRNA', | ||
start: '215218', | ||
end: '215772', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: { | ||
Parent: 'HsG8283', | ||
Evidence: '7000000069512231', | ||
Transcript_type: 'Novel_Transcript', | ||
Name: 'Novel+Transcript%2C+variant', | ||
ID: 'HsT16029' | ||
} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'five_prime_UTR', | ||
start: '215218', | ||
end: '215233', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT16029'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '215234', | ||
end: '215444', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT16029'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'CDS', | ||
start: '215641', | ||
end: '215735', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT16029'} | ||
}, | ||
{ | ||
seqid: 'human15.1', | ||
source: '.', | ||
type: 'three_prime_UT', | ||
start: '215736', | ||
end: '215772', | ||
score: '.', | ||
strand: '+', | ||
phase: '.', | ||
attributes: {Parent: 'HsT16029'} | ||
}]; | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12897
49
345