Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed script error and updated readme with script info #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
20 changes: 16 additions & 4 deletions csv_to_swc.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand Down