示例#1
0
 def testAddColumn(self):
     tsv = TSVTable(self.getInputFile("mrna1.tsv"), uniqKeyCols="qName")
     tsv.addColumn("joke")
     i = 0
     for row in tsv:
         row.joke = i
         i += 1
     fh = open(self.getOutputFile(".tsv"), "w")
     tsv.write(fh)
     fh.close()
     self.diffExpected(".tsv")
示例#2
0
    def testColTypeDefault(self):
        # default to int type
        typeMap = {
            "strand": str,
            "qName": str,
            "tName": str,
            "blockSizes": intArrayType,
            "qStarts": intArrayType,
            "tStarts": intArrayType
        }

        tsv = TSVTable(self.getInputFile("mrna1.tsv"),
                       uniqKeyCols="qName",
                       typeMap=typeMap,
                       defaultColType=int)
        r = tsv.idx.qName["AK095183"]
        self.failUnlessEqual(r.tStart, 4222)
        self.failUnlessEqual(r.tEnd, 19206)
        self.failUnlessEqual(r.tName, "chr1")
        self.failUnlessEqual(r.tStart, 4222)

        tStarts = (4222, 4832, 5658, 5766, 6469, 6719, 7095, 7355, 7777, 8130,
                   14600, 19183)
        self.failUnlessEqual(len(r.tStarts), len(tStarts))
        for i in xrange(len(tStarts)):
            self.failUnlessEqual(r.tStarts[i], tStarts[i])
示例#3
0
 def testMissingIdxCol(self):
     err = None
     try:
         tsv = TSVTable(self.getInputFile("mrna1.tsv"),
                        multiKeyCols=("noCol", ))
     except TSVError, e:
         err = e
示例#4
0
 def testLoad(self):
     tsv = TSVTable(self.getInputFile("mrna1.tsv"))
     self.failUnlessEqual(len(tsv), 10)
     for r in tsv:
         self.failUnlessEqual(len(r), 22)
     r = tsv[0]
     self.failUnlessEqual(r["qName"], "BC032353")
     self.failUnlessEqual(r[10], "BC032353")
     self.failUnlessEqual(r.qName, "BC032353")
示例#5
0
    def testMultiIdx(self):
        tsv = TSVTable(self.getInputFile("mrna1.tsv"),
                       multiKeyCols=("tName", "tStart"))
        rows = tsv.idx.tName["chr1"]
        self.failUnlessEqual(len(rows), 10)
        self.failUnlessEqual(rows[1].qName, "AK095183")

        rows = tsv.idx.tStart["4268"]
        self.failUnlessEqual(len(rows), 5)
        self.failUnlessEqual(rows[0].qName, "BC015400")
示例#6
0
 def testAddColumn(self):
     tsv = TSVTable(self.getInputFile("mrna1.tsv"), uniqKeyCols="qName")
     tsv.addColumn("joke")
     i = 0
     for row in tsv:
         row.joke = i
         i += 1
     fh = open(self.getOutputFile(".tsv"), "w")
     tsv.write(fh)
     fh.close()
     self.diffExpected(".tsv")
示例#7
0
    def doTestColType(self, inFile):
        typeMap = {
            "intCol": int,
            "floatCol": float,
            "onOffCol": (self.onOffParse, self.onOffFmt)
        }

        tsv = TSVTable(self.getInputFile(inFile), typeMap=typeMap)

        r = tsv[0]
        self.failUnlessEqual(r.strCol, "name1")
        self.failUnlessEqual(r.intCol, 10)
        self.failUnlessEqual(r.floatCol, 10.01)
        self.failUnlessEqual(str(r), "name1\t10\t10.01\ton")

        r = tsv[2]
        self.failUnlessEqual(r.strCol, "name3")
        self.failUnlessEqual(r.intCol, 30)
        self.failUnlessEqual(r.floatCol, 30.555)
        self.failUnlessEqual(str(r), "name3\t30\t30.555\toff")
示例#8
0
    def testColNameMap(self):
        typeMap = {
            "int_col": int,
            "float_col": float,
            "onOff_col": (self.onOffParse, self.onOffFmt)
        }

        tsv = TSVTable(self.getInputFile('typesColNameMap.tsv'),
                       typeMap=typeMap,
                       columnNameMapper=lambda s: s.replace(' ', '_'))

        r = tsv[0]
        self.failUnlessEqual(r.str_col, "name1")
        self.failUnlessEqual(r.int_col, 10)
        self.failUnlessEqual(r.float_col, 10.01)
        self.failUnlessEqual(str(r), "name1\t10\t10.01\ton")

        r = tsv[2]
        self.failUnlessEqual(r.str_col, "name3")
        self.failUnlessEqual(r.int_col, 30)
        self.failUnlessEqual(r.float_col, 30.555)
        self.failUnlessEqual(str(r), "name3\t30\t30.555\toff")
示例#9
0
 def testAllowEmptyTbl(self):
     tbl = TSVTable("/dev/null", allowEmpty=True)
     self.failUnlessEqual(len(tbl), 0)
示例#10
0
 def testDupColumn(self):
     err = None
     try:
         tsv = TSVTable(self.getInputFile("dupCol.tsv"))
     except TSVError, e:
         err = e
示例#11
0
 def testWrite(self):
     tsv = TSVTable(self.getInputFile("mrna1.tsv"), uniqKeyCols="qName")
     fh = open(self.getOutputFile(".tsv"), "w")
     tsv.write(fh)
     fh.close()
     self.diffExpected(".tsv")
示例#12
0
 def testWrite(self):
     tsv = TSVTable(self.getInputFile("mrna1.tsv"), uniqKeyCols="qName")
     fh = open(self.getOutputFile(".tsv"), "w")
     tsv.write(fh)
     fh.close()
     self.diffExpected(".tsv")