2006-05-03 16:04:28 +02:00
|
|
|
import unittest
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.append("../..")
|
|
|
|
from workflows.affy_workflow import PhenotypeDataset
|
|
|
|
|
|
|
|
class PhenotypeDatasetTest(unittest.TestCase):
|
|
|
|
def testEmptyData(self):
|
|
|
|
# we have a list of cel-files, but no categories
|
|
|
|
cel_data = """\
|
|
|
|
CEL
|
|
|
|
02-05-33
|
|
|
|
03-07-38
|
|
|
|
"""
|
|
|
|
dataset = PhenotypeDataset(cel_data)
|
|
|
|
self.assertEquals(['CEL', 'phenotypes'], dataset.get_dim_names())
|
|
|
|
self.assertEquals(['02-05-33', '03-07-38'], dataset.get_identifiers('CEL'))
|
|
|
|
self.assertEquals([], dataset.get_identifiers('phenotypes'))
|
|
|
|
|
|
|
|
def testFloatData(self):
|
|
|
|
cel_data = """\
|
|
|
|
CEL\tage
|
2006-05-03 16:27:38 +02:00
|
|
|
02-05-33\t8.5
|
2006-05-03 16:04:28 +02:00
|
|
|
03-07-38\t9
|
|
|
|
"""
|
|
|
|
dataset = PhenotypeDataset(cel_data)
|
|
|
|
self.assertEquals(['CEL', 'phenotypes'], dataset.get_dim_names())
|
|
|
|
self.assertEquals(['age'], dataset.get_identifiers('phenotypes'))
|
2006-05-03 16:27:38 +02:00
|
|
|
self.assertEquals([[8.5],
|
2006-05-03 16:04:28 +02:00
|
|
|
[9]], dataset.asarray().tolist())
|
|
|
|
|
|
|
|
def testCategoryData(self):
|
|
|
|
"""Categories expand to one numeric column for each category choice."""
|
|
|
|
cel_data = """\
|
|
|
|
CEL\tsick
|
|
|
|
02-05-33\tyes
|
|
|
|
03-07-38\tno
|
|
|
|
04-93-33\tyes
|
|
|
|
08-32-33\tmaybe
|
|
|
|
"""
|
|
|
|
dataset = PhenotypeDataset(cel_data)
|
|
|
|
self.assertEquals(['CEL', 'phenotypes'], dataset.get_dim_names())
|
|
|
|
self.assertEquals(['sick-yes', 'sick-no', 'sick-maybe'], dataset.get_identifiers('phenotypes'))
|
|
|
|
self.assertEquals([[1, 0, 0],
|
|
|
|
[0, 1, 0],
|
|
|
|
[1, 0, 0],
|
|
|
|
[0, 0, 1]], dataset.asarray().tolist())
|
|
|
|
|
|
|
|
def testMultipleCategoriesAndFloats(self):
|
|
|
|
cel_data = """\
|
|
|
|
CEL\tsex\tage\tinfected
|
|
|
|
02-05-33\tF\t8\tI
|
|
|
|
02-05-34\tF\t9\tN
|
|
|
|
02-05-35\tM\t8\tI
|
|
|
|
"""
|
|
|
|
dataset = PhenotypeDataset(cel_data)
|
|
|
|
self.assertEquals(['sex-F', 'sex-M', 'age', 'infected-I', 'infected-N'],
|
|
|
|
dataset.get_identifiers('phenotypes'))
|
|
|
|
|
|
|
|
self.assertEquals([[1, 0, 8, 1, 0],
|
|
|
|
[1, 0, 9, 0, 1],
|
|
|
|
[0, 1, 8, 1, 0]], dataset.asarray().tolist())
|
|
|
|
|
|
|
|
def testGetPhenotypeTable(self):
|
|
|
|
cel_data = """\
|
|
|
|
CEL\tsex\tage\tinfected
|
|
|
|
02-05-33\tF\t8\tI
|
|
|
|
02-05-34\tF\t9\tN
|
|
|
|
02-05-35\tM\t8\tI
|
|
|
|
"""
|
|
|
|
dataset = PhenotypeDataset(cel_data)
|
|
|
|
|
|
|
|
self.assertEquals([['CEL', 'sex', 'age', 'infected'],
|
|
|
|
['02-05-33', 'F', '8', 'I'],
|
|
|
|
['02-05-34', 'F', '9', 'N'],
|
|
|
|
['02-05-35', 'M', '8', 'I']], dataset.get_phenotype_table())
|
|
|
|
|
2006-05-04 15:30:04 +02:00
|
|
|
def testGetCategories(self):
|
|
|
|
cel_data = """\
|
|
|
|
CEL\tsex\tage\tinfected
|
|
|
|
02-05-33\tF\t8\tI
|
|
|
|
02-05-34\tF\t9\tN
|
|
|
|
02-05-35\tM\t8\tI
|
|
|
|
"""
|
|
|
|
dataset = PhenotypeDataset(cel_data)
|
|
|
|
|
|
|
|
self.assertEquals(set(['F', 'M', 'I', 'N']), set(dataset.get_categories()))
|
|
|
|
|
2006-05-03 16:04:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__=='__main__':
|
|
|
|
unittest.main()
|