Last active
          November 27, 2017 16:34 
        
      - 
      
- 
        Save dyf/88783324bc06fc24c9f64adcddcfea20 to your computer and use it in GitHub Desktop. 
    ruby read SWC
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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