Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
Merge pull request #5 from thehyve/dev
Browse files Browse the repository at this point in the history
Get latest fixes and Py3 support from Dev
  • Loading branch information
jochemb committed Mar 18, 2016
2 parents 31e296f + 3d745c0 commit fd8a226
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 20 deletions.
28 changes: 19 additions & 9 deletions arborist/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#!/usr/bin/env python3
import os
import sys
from collections import OrderedDict
Expand All @@ -11,13 +11,13 @@
import urllib
from markupsafe import Markup

from functions.params import Clinical_params, Expression_params, get_study_id
from functions.exceptions import HyveException, HyveIOException
from functions.clinical import columns_to_tree, json_to_columns, getchildren, \
from .functions.params import Clinical_params, Expression_params, get_study_id
from .functions.exceptions import HyveException, HyveIOException
from .functions.clinical import columns_to_tree, json_to_columns, getchildren, \
get_datafiles, get_column_map_file, \
add_to_column_file, get_word_map
from functions.feedback import get_feedback_dict, merge_feedback_dicts
from functions.highdim import subject_sample_to_tree, get_subject_sample_map
from .functions.feedback import get_feedback_dict, merge_feedback_dicts
from .functions.highdim import subject_sample_to_tree, get_subject_sample_map

STUDIES_FOLDER = 'studies'
ALLOWED_EXTENSIONS = set(['txt', 'tsv'])
Expand Down Expand Up @@ -55,13 +55,20 @@ def add_slash_if_not_windows(url_path):
return url_path


def replace_back_with_forward_slash(string):
string = string.replace('\\', '/')
return string


class FolderPathConverter(BaseConverter):
def __init__(self, url_map):
super(FolderPathConverter, self).__init__(url_map)
self.regex = '.*'

def to_python(self, value):
return add_slash_if_not_windows(value)
value = add_slash_if_not_windows(value)
value = replace_back_with_forward_slash(value)
return value

def to_url(self, value):
return value
Expand All @@ -80,7 +87,10 @@ def urlencode_filter(s):
if type(s) == 'Markup':
s = s.unescape()
s = s.encode('utf8')
s = urllib.quote_plus(s)
if sys.version_info.major == 2:
s = urllib.quote_plus(s)
else:
s = urllib.parse.quote_plus(s)
return Markup(s)


Expand Down Expand Up @@ -379,7 +389,7 @@ def save_columnsfile(studiesfolder, study):

columnsfile = get_column_map_file(studiesfolder, study)
if columnsfile is not None:
columnmappingfile = open(columnsfile, 'wb')
columnmappingfile = open(columnsfile, 'w')
columnmappingfile.write(tree)
columnmappingfile.close()

Expand Down
22 changes: 16 additions & 6 deletions arborist/functions/clinical.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import csv
import os

from feedback import get_feedback_dict
from params import Clinical_params
from .feedback import get_feedback_dict
from .params import Clinical_params


outoftree = 'OUT OF TREE'
Expand All @@ -26,6 +26,16 @@
'New Data Value']


def columns_not_present(line, column_list):
"""Return True if one or more of column_list are not present"""
if len(line) == 0:
return False
for column in column_list:
if line[column] == '':
return False
return True


def columns_to_tree(filename):
with open(filename, 'rU') as csvfile:
csvreader = csv.reader(csvfile, delimiter='\t', quotechar='"')
Expand All @@ -36,8 +46,7 @@ def columns_to_tree(filename):

for line in csvreader:
# Skip lines without filename, column number or data label
if line[filenamecolumn] != '' and line[columnnumbercolumn] != '' \
and line[datalabelcolumn] != '':
if columns_not_present(line, [filenamecolumn, columnnumbercolumn, datalabelcolumn]):
# If categorycode is empty this is a special concept that is
# not in the tree
# Eg SUBJ_ID, STUDY_ID, OMIT or DATA LABEL
Expand Down Expand Up @@ -192,7 +201,8 @@ def get_datafiles(columnfilename):
csvreader = csv.reader(csvfile, delimiter='\t', quotechar='"')
next(csvreader)
for line in csvreader:
datafiles.add(line[filenamecolumn])
if len(line) > 0:
datafiles.add(line[filenamecolumn])

return datafiles

Expand All @@ -210,7 +220,7 @@ def get_column_map_file(studiesfolder, study):
def add_to_column_file(datafilename, columnmappingfilename):
with open(datafilename, 'rU') as csvfile:
csvreader = csv.reader(csvfile, delimiter='\t', quotechar='"')
headerline = csvreader.next()
headerline = next(csvreader)
with open(columnmappingfilename, "a") as columnmappingfile:
i = 1
for header in headerline:
Expand Down
2 changes: 1 addition & 1 deletion arborist/functions/feedback.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from exceptions import HyveException
from .exceptions import HyveException
feedback_categories = ['errors', 'warnings', 'infos']


Expand Down
2 changes: 1 addition & 1 deletion arborist/functions/highdim.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import csv
import os

from params import Expression_params
from .params import Expression_params

subject_sample_map_headers = ['STUDY_ID', 'SITE_ID', 'SUBJECT_ID', 'SAMPLE_ID',
'PLATFORM', 'TISSUETYPE', 'ATTR1', 'ATTR2',
Expand Down
4 changes: 2 additions & 2 deletions arborist/functions/params.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from exceptions import HyveException, HyveIOException
from feedback import get_feedback_dict, merge_feedback_dicts
from .exceptions import HyveException, HyveIOException
from .feedback import get_feedback_dict, merge_feedback_dicts


class Params(object):
Expand Down
3 changes: 3 additions & 0 deletions docs/building_on_windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ To build the code into a packaged executable for Windows you can use py2exe. To

## Tips
* Building is recommended when having installed 32bit Python (Windows version should not matter). Building on 64bit Python as not been tested. Furthermore, the executable would not be able to run on 32 bit Windows while not providing any benefits to the user.

## Known issues
* The current version of py2exe (0.9.2.2) does not support python3.5. Building should work for python3.3 and python3.4.
1 change: 0 additions & 1 deletion runserver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
from arborist import app
import socket
import argparse
Expand Down

0 comments on commit fd8a226

Please sign in to comment.