Skip to content
This repository has been archived by the owner. It is now read-only.

Commit d1ac81f

Browse files
committed
Move CSV files into a specific directory
1 parent e690b1a commit d1ac81f

7 files changed

Lines changed: 30 additions & 26 deletions
File renamed without changes.

nat/modelingParameter.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
__author__ = "Christian O'Reilly"
44

5-
import os
65
import csv
76
from io import StringIO
7+
88
import pandas as pd
99

10+
from nat.utils import data_path
1011
from .tag import RequiredTag
1112

1213

13-
14-
1514
class ParameterTypeTree:
1615

1716
def __init__(self, value):
@@ -89,7 +88,7 @@ def addChildren(tree, df):
8988
def getParamTypeDF(fileName = None):
9089

9190
if fileName is None:
92-
fileName = os.path.join(os.path.dirname(__file__), "modelingDictionary.csv")
91+
fileName = data_path("modelingDictionary.csv")
9392

9493
df = pd.read_csv(fileName, skip_blank_lines=True, comment="#",
9594
delimiter=";", quotechar='"',
@@ -103,7 +102,7 @@ def getParamTypeDF(fileName = None):
103102
def getParameterTypes(fileName = None):
104103

105104
if fileName is None:
106-
fileName = os.path.join(os.path.dirname(__file__), "modelingDictionary.csv")
105+
fileName = data_path("modelingDictionary.csv")
107106

108107
with open(fileName, 'r') as f:
109108
lines = f.readlines()

nat/paramSample.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import numpy as np
1313
from quantities import Quantity
1414

15-
from nat import utils
15+
from nat.utils import data_directory
1616
from .ageResolver import AgeResolver
1717
from .aggregators import SampleAggregator
1818
from .annotationSearch import ParameterGetter
@@ -63,7 +63,7 @@ def copy(self):
6363
def setZoteroLib(self, library_id, library_type, api_key):
6464
# FIXME Delayed refactoring.
6565
if library_id is not None and library_type is not None and api_key is not None:
66-
work_dir = utils.working_directory()
66+
work_dir = data_directory()
6767
self.zotWrap = ZoteroWrap(library_id, library_type, api_key, work_dir)
6868
# TODO Implement an offline mode. Catch PyZoteroError.
6969
self.zotWrap.initialize()

nat/treeData.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
__author__ = 'oreilly'
44
__email__ = 'christian.oreilly@epfl.ch'
55

6+
import os
7+
import pickle
68

7-
from .tagUtilities import nlx2ks
8-
from .tag import RequiredTag
9-
from .modelingParameter import ParameterTypeTree
10-
#from .scigraph_client import Graph
11-
from .ontoDic import OntoDic
9+
import numpy as np
10+
import pandas as pd
1211
import requests
1312

14-
import os
15-
import pandas as pd
16-
import numpy as np
17-
import pickle
13+
from nat.utils import data_path
14+
from .modelingParameter import ParameterTypeTree
15+
# from .scigraph_client import Graph
16+
from .ontoDic import OntoDic
17+
from .tag import RequiredTag
18+
from .tagUtilities import nlx2ks
1819

1920
rootIDs = {}
2021

@@ -33,7 +34,7 @@ def flatten_list(l):
3334

3435
def getBBPChildren(root_id, df=None, childrenDic=None):
3536
if df is None:
36-
csvFileName = os.path.join(os.path.dirname(__file__), './additionsToOntologies.csv')
37+
csvFileName = data_path("additionsToOntologies.csv")
3738

3839
df = pd.read_csv(csvFileName, skip_blank_lines=True, comment="#",
3940
delimiter=";", names=["id", "label", "definition", "superCategory", "synonyms"])
@@ -173,7 +174,7 @@ def addSuppTerms(dic):
173174

174175

175176
def appendAdditions(treeData, dicData):
176-
csvFileName = os.path.join(os.path.dirname(__file__), './additionsToOntologies.csv')
177+
csvFileName = data_path("additionsToOntologies.csv")
177178

178179
df = pd.read_csv(csvFileName, skip_blank_lines=True, comment="#",
179180
delimiter=";", names=["id", "label", "definition", "superCategory", "synonyms"])

nat/utils.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@
66
"""
77

88
import os
9-
import sys
109
from copy import copy
1110
from glob import glob
1211
from os.path import basename
1312

1413

15-
def working_directory():
16-
"""Return the working directory according to it being bundled/frozen."""
17-
if getattr(sys, 'frozen', False):
18-
return os.path.dirname(sys.executable)
19-
else:
20-
return os.path.dirname(__file__)
14+
def data_directory():
15+
"""Return the absolute path to the directory containing the package data."""
16+
package_directory = os.path.abspath(os.path.dirname(__file__))
17+
return os.path.join(package_directory, "data")
18+
19+
20+
def data_path(filename):
21+
"""Return the absolute path to a file in the directory containing the package data."""
22+
return os.path.join(data_directory(), filename)
23+
24+
2125

2226
# See http://www.w3schools.com/tags/ref_urlencode.asp for list of encoders
2327

@@ -91,7 +95,7 @@ def test_ID_conversion():
9195
library_type = "group"
9296
api_key = "4D3rDZsAVBd139alqoVZBKOO"
9397
library_id = "427244"
94-
work_dir = working_directory()
98+
work_dir = data_directory()
9599
zot_wrap = ZoteroWrap(library_id, library_type, api_key, work_dir)
96100
# TODO Implement an offline mode. Catch PyZoteroError.
97101
zot_wrap.initialize()

0 commit comments

Comments
 (0)