Skip to content

Instantly share code, notes, and snippets.

@dyf
Last active November 27, 2017 16:34
Show Gist options
  • Save dyf/88783324bc06fc24c9f64adcddcfea20 to your computer and use it in GitHub Desktop.
Save dyf/88783324bc06fc24c9f64adcddcfea20 to your computer and use it in GitHub Desktop.
ruby read SWC
require 'csv'
def read_swc(file_path)
rows = CSV.read(file_path, col_sep: ' ')
good_rows = rows.select { |row| not row[0].starts_with?('#') }
return good_rows.collect do |row|
{
'id' => row[0],
'type' => row[1].to_i,
'x' => row[2].to_f,
'y' => row[3].to_f,
'z' => row[4].to_f,
'radius' => row[5].to_f,
'parent' => row[6],
}
end
end
# to convert to JSON:
# read_swc(some_path).to_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment