Code Monkey home page Code Monkey logo

fcs's Introduction

Build Status License NPM Downloads Known Vulnerabilities Coverage Status

fcs

Javascript / node.js code to read FCS flow cytometry data. Will read all of the HEADER, TEXT, and ANALYSIS segments into key/value pairs. Reads raw (likely uncompensated) data as well, either into numeric arrays for further analysis, or as Strings for quickly scanning the data.

basic usage

  1. Get the FCS file into a Buffer
  2. Create a new FCS(theBuffer, options)

e.g. to read from a file asynchronously

    var FCS = require('fcs');
    FS.readFile(filename, function(err, databuf) {
        if (err) {
            console.error(err);
            }
            else {
           var fcs = new FCS(options, databuf);
           // do something with fcs
            }
   });

see fcscli.js or fcshttp.js in the examples folder for usage examples

options (default in bold)

  • dataFormat: 'asNumber', 'asString', 'asBoth', or 'asNone'
  • groupBy: 'byEvent', 'byParameter'
  • decimalsToPrint: 2
  • eventsToRead: 1000 // an integer, -1 means "all events"
  • maxPerLine: 10
  • eventSkip: 0 if eventsToRead is less than the events in the file, this allows you to more randomly sample. A value of 'true' has them equally distributed. 0 means read the first events from the file.

Any additional options are ignored, but will be printed under a "meta" segment in the JSON. For example, you might want to include a date, your laboratory, etc...

api

creational

var myFCS = new FCS(options, buffer)

Constructor. Both arguments are optional. If buffer is present it will be read, otherwise you need to call readBuffer() or readStreamAsync() later

myFCS.options(options)

Set or add options.

myFCS.readBuffer(buffer, moreOptions)

Read data from buffer. moreOptions are optional. Hopefully by now you've set them all! :-)

myFCS.readStreamAsync(readStream, moreOptions, callback)

Reads data asynchronously from a readStream. moreOptions is optional. When complete, calls callback(err, fcs).

myFCS.prepareWriteableStream(callback, readableStream)

The readableStream arg is optional. Creates a writeableStream ready to parse an FCS format file. e.g.

var fws = fcs.prepareWriteableStream(callback, readableStream);
readableStream.pipe(fws);

When piping is complete, will call callback(err, fcs).

retrieving the data

get(segment, keywords...)

segment should be one of ('text', 'analysis', or, more rarely, 'header', 'meta'). If no keywords are provided, returns that entire segment otherwise, returns a single value, stopping at the first match to the keyword. Returns null if none were found.

getText(keywords...)

Equivalent to get('text', keywords) e.g. `text('$P3N') might return 'FL1-H'

get$PnX(x)

Return an array of all N keywords for that P.X combination. The 0th value will be empty. e.g. `get$PnX('N') might return ['', 'FSC, 'SSC', 'FL1-H', ...]

getAnalysis(keyword, additionalKeywords...)

Equivalent to get('analysis', keywords)

getNumericData(oneBasedIndex)

Returns an array of Numbers for the respective event or parameter, iff you requested numeric data.

getStringData(oneBasedIndex)

Returns an array of Strings for the respective event or parameter, iff you requested string data.

getOnly(onlys)

Returns a subset of the JSON, based upon onlys, an array of dot delimited Strings e.g. getOnlys(['meta','text.$P1N') would return all of meta, plus parameter 1 name

fields

.header

Holds the HEADER segment (first 256 bytes). The version is header.FCSVersion

.text

Holds all the TEXT segment

.analysis

Holds all the ANALYSIS segment. If none, is an empty object {}

.meta

Holds all the options, plus a bit more

Todos and Gotchas official bugs here

  • doesn't handle $BEGINSTEXT, $ENDSTEXT
  • could do more with Millipore's XML ANALYSIS

Changelog

  • v0.1.0 17 Nov 2018 partly converted to use ES6 features

fcs's People

Contributors

morganconrad avatar strelka145 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fcs's Issues

cannot handle $BYTEORD= 1,2

For some FCS files I get the above error. I see it in the code here:

    if ('4,3,2,1' === this.text.$BYTEORD)
       isBE = true;
    else if ('1,2,3,4' === this.text.$BYTEORD)
        isBE = false;
    else
       throw 'cannot handle $BYTEORD= ' + this.text.$BYTEORD;

Any plans to fix this? Ill try myself

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.