-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp3.py
66 lines (51 loc) · 1.61 KB
/
temp3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
converts the NIF-GrossAnatomy_reasonar.owl ontology into a networkx graph and saves the graph object as a .pkl file. using a networkx graph to find parents, children, etc. is much, much faster
for our purposes than using rdflib to do a SPARQL query on the .owl.
"""
import os.path
import nibabel as nb
import networkx as nx
import cPickle as pickle
import xml.etree.ElementTree as ET
from xml.dom import minidom
def split_filename(fname):
"""Split a filename into parts: path, base filename and extension.
Parameters
----------
fname : str
file or path name
Returns
-------
pth : str
base path from fname
fname : str
filename from fname, without extension
ext : str
file extension from fname
Examples
--------
>>> from nipype.utils.filemanip import split_filename
>>> pth, fname, ext = split_filename('/home/data/subject.nii.gz')
>>> pth
'/home/data'
>>> fname
'subject'
>>> ext
'.nii.gz'
"""
special_extensions = [".nii.gz", ".tar.gz"]
if fname and fname.endswith(os.path.sep):
fname = fname[:-1]
pth, fname = os.path.split(fname)
ext = None
for special_ext in special_extensions:
ext_len = len(special_ext)
if (len(fname) > ext_len) and \
(fname[-ext_len:].lower() == special_ext.lower()):
ext = fname[-ext_len:]
fname = fname[:-ext_len]
break
if not ext:
fname, ext = os.path.splitext(fname)
return pth, fname, ext
print split_filename('http://neurovault.org/media/images/268/STN-maxprob-thr0-05mm.nii.gz')