Class: FCSParse::FCSFile
- Inherits:
-
Object
- Object
- FCSParse::FCSFile
- Defined in:
- lib/fcsparse.rb
Overview
A class representing an FCS-encoded file. Has methods to parse the data, manage it, and convert it to human-readable format.
Currently reads FCS v3.x files. Files must have data encoded in list mode, and data points must be in float or double format (this will change eventually to support all formats in the specification).
Analysis sections of the file are ignored.
Data can be written to delimited text files, and metadata to plain text files, or the objects containing the data can be used by other code to process the data further.
Constant Summary
- MetadataExtension =
".meta.txt"
- DataExtension =
".data.csv"
- DataDelimiter =
FCSEvent::DefaultDelimiter
- SupportedVersions =
["FCS3.0", "FCS3.1"]
Instance Attribute Summary (collapse)
-
- (Object) events
Returns the value of attribute events.
-
- (Object) filename
Returns the value of attribute filename.
Class Method Summary (collapse)
-
+ (FCSFile) new_from_file(filename)
Generates a new FCSFile object from the specified file.
Instance Method Summary (collapse)
-
- (String) get_metadata_string
Gets the metadata (that is all the information in the text block of the fcs file) as a string, where there is one key, value pair per line, separated by the characters “ => ”.
-
- (FCSFile) initialize(file_string)
constructor
Generates a new FCSFile from the specified FCS-encoded data string.
-
- (Object) parse
Parses the raw data loaded in the FCSFile to metadata, events, and parameters.
-
- (Object) print_metadata
Prints the metadata string returned by #get_metadata_string.
-
- (Object) write_metadata_and_data(write_header_row = true)
Writes the metadata and data from the FCS-formatted file to disk in human readable format.
Constructor Details
- (FCSFile) initialize(file_string)
Generates a new FCSFile from the specified FCS-encoded data string.
87 88 89 90 |
# File 'lib/fcsparse.rb', line 87 def initialize(file_string) @data = file_string @keywords = Hash.new end |
Instance Attribute Details
- (Object) events
Returns the value of attribute events
58 59 60 |
# File 'lib/fcsparse.rb', line 58 def events @events end |
- (Object) filename
Returns the value of attribute filename
58 59 60 |
# File 'lib/fcsparse.rb', line 58 def filename @filename end |
Class Method Details
+ (FCSFile) new_from_file(filename)
Generates a new FCSFile object from the specified file.
Calling this will read the entire file into memory but will not parse it.
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/fcsparse.rb', line 69 def self.new_from_file(filename) fcsfile = nil File.open(filename) do |f| fcsfile = self.new(f.read) end fcsfile.filename = filename fcsfile end |
Instance Method Details
- (String) get_metadata_string
Gets the metadata (that is all the information in the text block of the fcs file) as a string, where there is one key, value pair per line, separated by the characters “ => ”
252 253 254 255 256 257 258 |
# File 'lib/fcsparse.rb', line 252 def str = "" @keywords.keys.map{|e| e.to_s}.sort.each do |k| str << k.to_s + " => " + @keywords[k.to_sym].to_s + "\n" end str end |
- (Object) parse
Parses the raw data loaded in the FCSFile to metadata, events, and parameters.
Erases the raw data from the FCSFile object after parsing is complete.
324 325 326 327 328 329 |
# File 'lib/fcsparse.rb', line 324 def parse read_header parse_text_segment parse_data_segment @data = nil end |
- (Object) print_metadata
Prints the metadata string returned by #get_metadata_string.
263 264 265 266 267 268 269 |
# File 'lib/fcsparse.rb', line 263 def puts nil end |
- (Object) write_metadata_and_data(write_header_row = true)
Writes the metadata and data from the FCS-formatted file to disk in human readable format.
The metadata is written as a text file (formatted by #get_metadata_string), in the same location as the input FCS file and with the same name except for an extra extension specified in MetadataExtension.
The data, delimited by the data delimiter specified as DataDelimiter, one row per event, is written to a text file in the same location as the input FCS file and with the same name except for an extra extension specified in DataExtension.
the data file should have a header row with the name of each column’s parameter. Defaults to true.
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/fcsparse.rb', line 289 def (write_header_row = true) = @filename + MetadataExtension data_filename = @filename + DataExtension File.open(, "w") do |f| f.write() end File.open(data_filename, "w") do |f| if write_header_row then f.puts(@events[0].names_to_s_delim(DataDelimiter)) end @events.each do |e| f.puts(e.to_s_delim(DataDelimiter)) end end nil end |