Class: FCSParse::FCSEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/fcsparse/fcsevent.rb

Overview

Class representing a single FCS-encoded event.

Author:

Constant Summary

DefaultDelimiter =

default delimiter for printing output

","

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (FCSEvent) initialize

A new instance of FCSEvent



75
76
77
78
79
# File 'lib/fcsparse/fcsevent.rb', line 75

def initialize
  
  @values = Hash.new
  
end

Class Method Details

+ (FCSEvent) new_with_data_and_format(event_data_string, event_format_string, parameter_info_hash)

Creates a new FCSEvent from the specified information.

Parameters:

  • event_data_string (String)

    the raw data corresponding to the entire event from the fcs file

  • event_format_string (String)

    a string suitable for use with String#unpack that can decode the raw data.

  • parameter_info_hash (Hash)

    a hash containing at minimum the parameters from the text section specifying the names and ranges of the parameters keys should be the parameter names from the fcs file format converted to symbols ($ included), and values should be a string corresponding to the value of the parameter from the fcs file.

Returns:

  • (FCSEvent)

    an FCSEvent that has been created by parsing the raw data.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/fcsparse/fcsevent.rb', line 96

def self.new_with_data_and_format(event_data_string, event_format_string, parameter_info_hash)

  data_points = event_data_string.unpack(event_format_string)
  
  parameter_names = Hash.new
  parameter_limits = Hash.new
  
  parameter_info_hash.each_key do |k|
    
    matchobj = k.to_s.match(T_ParameterNameKeywordRegex)
    
    
    if matchobj then
      
      parameter_names[matchobj[1].to_i] = parameter_info_hash[k]
      
    end
      

    matchobj = k.to_s.match(T_ParameterRangeKeywordRegex)
    
    if matchobj then
      
      parameter_limits[matchobj[1].to_i] = parameter_info_hash[k]

    end

  end
  
  ordered_indices = parameter_names.keys.sort
        
  event = new      
  
  data_points.each_with_index do |e, i|
  
    param = FCSParam.new(parameter_names[ordered_indices[i]], nil, e, parameter_limits[ordered_indices[i]])
    
    event[param.name] = param
    
  end
  
  event
          
end

Instance Method Details

- (FCSParam) [](parameter_name)

Gets a named parameter associated with the event.

Parameters:

  • parameter_name (String)

    the name of the parameter to retrieve; this should be exactly the name specified for the parameter in the text section of the fcs file

Returns:

  • (FCSParam)

    an FCSParam object that holds the information about the named parameter.



149
150
151
152
153
# File 'lib/fcsparse/fcsevent.rb', line 149

def [](parameter_name)
  
  @values[parameter_name]
  
end

- (Object) []=(parameter_name, value)

Sets a named parameter associated with the event.

Parameters:

  • parameter_name (String)

    the name of the parameter to retrieve; this should be exactly the name specified for the parameter in the text section of the fcs file

  • value (FCSParam)

    an FCSParam object that holds the information about the named parameter.



162
163
164
165
166
# File 'lib/fcsparse/fcsevent.rb', line 162

def []=(parameter_name, value)
  
  @values[parameter_name]= value
  
end

- (String) names_to_s_delim(delimiter)

Gets the names of the parameters associated with this event in alphabetical order as a string, delimited by the supplied delimiter.

Parameters:

  • delimiter (String)

    a String containing the desired delimiter.

Returns:

  • (String)

    a String containing delimited alphabetized parameter names.



175
176
177
178
179
180
181
# File 'lib/fcsparse/fcsevent.rb', line 175

def names_to_s_delim(delimiter)
  
  all_param_names = @values.keys.sort
  
  all_param_names.join(delimiter)
  
end

- (String) to_s

Converts the event to a string representation. This is the same as calling #to_s_delim with the delimiter set to DefaultDelimiter.

Returns:

  • (String)

    a String containing delimited ordered parameter values.



207
208
209
210
211
# File 'lib/fcsparse/fcsevent.rb', line 207

def to_s
  
  to_s_delim(DefaultDelimiter)
  
end

- (String) to_s_delim(delimiter)

Gets the values of the parameters associated with this event ordered alphabetically by the parameter names (i.e. in the same order as when calling #names_to_s_delim), delimited by the supplied delimiter.

Parameters:

  • delimiter (String)

    a String containing the desired delimiter.

Returns:

  • (String)

    a String containing delimited ordered parameter values.



191
192
193
194
195
196
197
198
199
# File 'lib/fcsparse/fcsevent.rb', line 191

def to_s_delim(delimiter)
        
  all_param_names = @values.keys.sort
  
  all_param_values = all_param_names.map{|e| @values[e].value}
  
  all_param_values.join(delimiter)
  
end