Skip to content

Commit

Permalink
Merge 72130c8 into 7802d45
Browse files Browse the repository at this point in the history
  • Loading branch information
neolei committed Jan 12, 2019
2 parents 7802d45 + 72130c8 commit 67f8135
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
22 changes: 11 additions & 11 deletions .travis.yml
Expand Up @@ -7,21 +7,21 @@ python:
- '3.5'

install:
- sudo apt-get update

- wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
# - sudo apt-get update
- pip install -r requirements.txt
# - wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
# - bash miniconda.sh -b -p $HOME/miniconda
# - export PATH="$HOME/miniconda/bin:$PATH"
# - hash -r
# - conda config --set always_yes yes --set changeps1 no
# - conda update -q conda

# Useful for debugging any issues with conda.
- conda info -a
# - conda info -a

# Create conda environment.
- conda create -q -n test python=$TRAVIS_PYTHON_VERSION
- source activate test
# - conda create -q -n test python=$TRAVIS_PYTHON_VERSION
# - source activate test

# Install with test dependencies.
- pip install .[dev]
Expand Down
32 changes: 24 additions & 8 deletions src/pybiomart/dataset.py
Expand Up @@ -6,7 +6,6 @@
from future.utils import native_str

from io import StringIO
from xml.etree import ElementTree

import pandas as pd

Expand All @@ -15,6 +14,12 @@

# pylint: enable=import-error

# xml
try:
from xml.etree import cElementTree as ET
except ImportError:
from xml.etree import ElementTree as ET

class Dataset(ServerBase):
"""Class representing a biomart dataset.
Expand Down Expand Up @@ -148,7 +153,7 @@ def _fetch_configuration(self):
'check the dataset name and schema.')

# Get filters and attributes from xml.
xml = ElementTree.fromstring(response.content)
xml = ET.fromstring(response.content)

filters = {f.name: f for f in self._filters_from_xml(xml)}
attributes = {a.name: a for a in self._attributes_from_xml(xml)}
Expand All @@ -159,8 +164,19 @@ def _fetch_configuration(self):
def _filters_from_xml(xml):
for node in xml.iter('FilterDescription'):
attrib = node.attrib
# remove the id_list and boolean_list type
if attrib.get('type', 'None') in ['id_list', 'boolean_list']:
continue
if attrib.get('type') is None:
yield Filter(name=attrib['pointerFilter'], type='text')
continue
yield Filter(
name=attrib['internalName'], type=attrib.get('type', ''))
name=attrib['internalName'], type=attrib['type'])
# tag:Option with type
# python2.7 iter() takes no keyword arguments
for node in xml.iter('Option'):
if node.attrib.get('type'):
yield Filter(name=node.attrib['internalName'], type=node.attrib['type'])

@staticmethod
def _attributes_from_xml(xml):
Expand Down Expand Up @@ -224,15 +240,15 @@ def query(self,
# </Query>

# Setup query element.
root = ElementTree.Element('Query')
root = ET.Element('Query')
root.set('virtualSchemaName', self._virtual_schema)
root.set('formatter', 'TSV')
root.set('header', '1')
root.set('uniqueRows', native_str(int(only_unique)))
root.set('datasetConfigVersion', '0.6')

# Add dataset element.
dataset = ElementTree.SubElement(root, 'Dataset')
dataset = ET.SubElement(root, 'Dataset')
dataset.set('name', self.name)
dataset.set('interface', 'default')

Expand Down Expand Up @@ -262,7 +278,7 @@ def query(self,
'for a list of valid filters.'.format(name))

# Fetch response.
response = self.get(query=ElementTree.tostring(root))
response = self.get(query=ET.tostring(root))

# Raise exception if an error occurred.
if 'Query ERROR' in response.text:
Expand All @@ -287,13 +303,13 @@ def query(self,

@staticmethod
def _add_attr_node(root, attr):
attr_el = ElementTree.SubElement(root, 'Attribute')
attr_el = ET.SubElement(root, 'Attribute')
attr_el.set('name', attr.name)

@staticmethod
def _add_filter_node(root, filter_, value):
"""Adds filter xml node to root."""
filter_el = ElementTree.SubElement(root, 'Filter')
filter_el = ET.SubElement(root, 'Filter')
filter_el.set('name', filter_.name)

# Set filter value depending on type.
Expand Down

0 comments on commit 67f8135

Please sign in to comment.