diff --git a/README.md b/README.md index cf4ef91..c32e5ea 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ # SWCtools Tools for SWC file handling + + + + +#### csv_to_swc.py +This script converts CSV files, generated by the Cardona Lab CATMAID software, to neuron SWC format. +The units of the generated csv file are in nanometers. +This script converts the units to micrometers \ No newline at end of file diff --git a/csv_to_swc.py b/csv_to_swc.py index af7c2f1..5b8178d 100644 --- a/csv_to_swc.py +++ b/csv_to_swc.py @@ -1,4 +1,5 @@ -#File for converting a generated csv file to an swc formatted file as well as an id mapped csv file +#Script for converting a generated CSV file to an SWC formatted file as well as an id mapped csv file +#CSV files exported by Albert Cardona from his lab's CATMAID software: http://catmaid.readthedocs.io/en/stable/ #Author:Boima Massaquoi #FILE USEAGE BELOW @@ -8,6 +9,13 @@ #In the command prompt provide The following Arguments: #"python" "csv_to_swc.py" ".csv file you want to convert" ".swc outputfile you want to generate" +#IMPORTANT NOTE +#The CSV files are generated from the Cardona Lab CATMAID software have the node xyzr values in the form of nanometers +#This script assumes that the values are in nano meters and uses a conversion factor to convert values from nanometers to micrometers + +#factor for converting nanometers to micrometers +um_factor = 1000 + import sys import csv import operator @@ -17,9 +25,9 @@ class nnode(object): def __init__(self,n_id,_type,x,y,z,r,p_id): self.n_id = int(n_id) self._type = _type - self.x = x - self.y = y - self. z = z + self.x = float(x) + self.y = float(y) + self.z = float(z) self.r = float(r) if p_id == '': p_id = '-1' @@ -97,6 +105,10 @@ def write_swc(): h_tnode = tnode(n) elif n.r<=0: n.r = 5.0 + n.x = n.x/um_factor + n.y = n.y/um_factor + n.z = n.z/um_factor + n.r = n.r/um_factor n_list.append(n) #build the tree using the soma as the head node