Method: FCSParse::FCSEvent.new_with_data_and_format

Defined in:
lib/fcsparse/fcsevent.rb

.new_with_data_and_format(event_data_string, event_format_string, parameter_info_hash) ⇒ FCSEvent

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