Skip to content

Commit

Permalink
Merge branch 'stable-1.x' into bloody
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqdaouda committed Nov 25, 2014
2 parents 1ff2c7b + 8c43751 commit 4dbf40e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 26 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.1.7
=====

* BUG FIX: looping through CSV lines now works
* Added tests for CSV

1.1.6
=====

Expand Down
2 changes: 1 addition & 1 deletion pyGeno/pyGenoObjectBases.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def flushIndexes(cls) :
def help(cls) :
"""Returns a list of available field for queries. Ex
Transcript.help()"""
return cls._wrapped_class.help()
return cls._wrapped_class.help().replace("_Raba", "")

@classmethod
def ensureGlobalIndex(cls, fields) :
Expand Down
32 changes: 32 additions & 0 deletions pyGeno/tests/csv_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import unittest
from pyGeno.tools.parsers.CSVTools import *

class CSVTests(unittest.TestCase):

def setUp(self):
pass

def tearDown(self):
pass

def test_createParse(self) :
testVals = ["test", "test2"]
c = CSVFile(legend = ["col1", "col2"], separator = "\t")
l = c.newLine()
l["col1"] = testVals[0]
l = c.newLine()
l["col1"] = testVals[1]
c.save("test.csv")

c2 = CSVFile()
c2.parse("test.csv", separator = "\t")
i = 0
for l in c2 :
self.assertEqual(l["col1"], testVals[i])
i += 1

def runTests() :
unittest.main()

if __name__ == "__main__" :
runTests()
37 changes: 16 additions & 21 deletions pyGeno/tests/tests.py → pyGeno/tests/genome_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,21 @@

class pyGenoSNPTests(unittest.TestCase):

def importAll(self) :
try :
importHumanReference_YOnly()
except ValueError :
pass
#~ print "--> Seems to already exist in db"

try :
importDummySRY()
except ValueError :
pass
#~ print "--> Seems to already exist in db"

self.ref = Genome(name = 'GRCh37.75_Y-Only')

def setUp(self):
self.importAll()
self.ref = Genome(name = 'GRCh37.75_Y-Only')

def tearDown(self):
pass

def testVanilla(self) :
def test_vanilla(self) :
dummy = Genome(name = 'GRCh37.75_Y-Only', SNPs = 'dummySRY')
persProt = dummy.get(Protein, id = 'ENSP00000438917')[0]
refProt = self.ref.get(Protein, id = 'ENSP00000438917')[0]

self.assertEqual('ATGCAATCATATGCTTCTGC', refProt.transcript.cDNA[:20])
self.assertEqual('HTGCAATCATATGCTTCTGC', persProt.transcript.cDNA[:20])

def testNoModif(self) :
def test_noModif(self) :
from pyGeno.SNPFiltering import SNPFilter

class MyFilter(SNPFilter) :
Expand All @@ -52,7 +37,7 @@ def filter(self, chromosome, dummySRY) :

self.assertEqual(persProt.transcript.cDNA[:20], refProt.transcript.cDNA[:20])

def testInsert(self) :
def test_insert(self) :
from pyGeno.SNPFiltering import SNPFilter

class MyFilter(SNPFilter) :
Expand All @@ -72,7 +57,7 @@ def filter(self, chromosome, dummySRY) :
self.assertEqual('ATGCAATCATATGCTTCTGC', refProt.transcript.cDNA[:20])
self.assertEqual('ATGATGCAATCATATGCTTC', persProt.transcript.cDNA[:20])

def testSNP(self) :
def test_SNP(self) :
from pyGeno.SNPFiltering import SNPFilter

class MyFilter(SNPFilter) :
Expand All @@ -90,7 +75,7 @@ def filter(self, chromosome, dummySRY) :
self.assertEqual('M', refProt.sequence[0])
self.assertEqual('L', persProt.sequence[0])

def testDeletion(self) :
def test_deletion(self) :
from pyGeno.SNPFiltering import SNPFilter

class MyFilter(SNPFilter) :
Expand Down Expand Up @@ -122,6 +107,16 @@ def test_find(self) :
self.assertEqual(len(prot)-10, prot.find(needle))

def runTests() :
try :
importHumanReference_YOnly()
except ValueError :
print "--> Seems to already exist in db"

try :
importDummySRY()
except ValueError :
print "--> Seems to already exist in db"

unittest.main()

if __name__ == "__main__" :
Expand Down
9 changes: 7 additions & 2 deletions pyGeno/tools/parsers/CSVTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(self, csvFile, lineNumber = None) :
self.data = []
if lineNumber != None :
self.lineNumber = lineNumber

tmpL = csvFile.lines[lineNumber].replace('\r', '\n').replace('\n', '')
tmpData = tmpL.split(csvFile.separator)

Expand All @@ -91,7 +92,11 @@ def __init__(self, csvFile, lineNumber = None) :

def __getitem__(self, key) :
"""Returns the value of field 'key'"""
return self.data[self.csvFile.legend[key.lower()]]
try :
indice = self.csvFile.legend[key.lower()]
except KeyError :
raise KeyError("CSV File has no column: '%s'" % key)
return self.data[indice]

def __setitem__(self, key, value) :
"""Sets the value of field 'key' to 'value' """
Expand Down Expand Up @@ -209,7 +214,7 @@ def next(self) :
self.currentPos += 1
if self.currentPos >= len(self) :
raise StopIteration
return CSVEntry(self, self[self.currentPos])
return CSVEntry(self, self.currentPos)

def __getitem__(self, line) :
if self.lines[line].__class__ is not CSVEntry :
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
setup(
name='pyGeno',

version='1.1.6',
version='1.1.7',

description='A python package for Personalized Proteogenomics',
long_description=long_description,
Expand All @@ -21,7 +21,7 @@
author='Tariq Daouda',
author_email='[email protected]',

test_suite="pyGeno.tests.tests",
test_suite="pyGeno.tests",

license='ApacheV2.0',

Expand Down

0 comments on commit 4dbf40e

Please sign in to comment.