Skip to content

Instantly share code, notes, and snippets.

@audy
Created January 29, 2015 19:45
Show Gist options
  • Save audy/6ab4ccd5d9e8489af0a5 to your computer and use it in GitHub Desktop.
Save audy/6ab4ccd5d9e8489af0a5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
var fs = require('fs');
var fasta = require('bionode-fasta');
var crypto = require('crypto');
fasta.obj('proteins.fasta').on('data', function(x) {
var seq = x.seq
.replace(/\*/g, '') // remove asterisks (stop codons)
.toUpperCase(); // enforce case
var hash = crypto.createHash('md5').update(seq).digest('hex')
console.log(hash + "\t" + x.id);
});
@bmpvieira
Copy link

#!/usr/bin/env node

var crypto = require('crypto')
var through = require('through2')
var fasta = require('bionode-fasta')

fasta.obj('node_modules/bionode-fasta/test/test.fasta')
.pipe(md5())
.pipe(process.stdout)

function md5 () {
  var stream = through.obj(transform)
  return stream
  function transform (obj, enc, next) {
    var seq = obj.seq
    .replace(/\*/g, '') // remove asterisks (stop codons)
    .toUpperCase()     // enforce case
    var hash = crypto.createHash('md5').update(seq).digest('hex')
    this.push(hash + '\t' + obj.id + '\n')
    next()
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment