def testFastaReadWriteC(self): """Tests consistency with C version of this function. """ tempFile = getTempFile() self.tempFiles.append(tempFile) tempFile2 = getTempFile() self.tempFiles.append(tempFile2) for test in xrange(0, self.testNo): fastaNumber = random.choice(xrange(10)) l = [ getRandomSequence() for i in xrange(fastaNumber) ] fileHandle = open(tempFile, 'w') for name, seq in l: fastaWrite(fileHandle, name, seq) fileHandle.close() command = "sonLib_fastaCTest %s %s" % (tempFile, tempFile2) print command system(command) fileHandle = open(tempFile2, 'r') l.reverse() for i in fastaRead(fileHandle): name, seq = i assert i == l.pop() fastaWrite(sys.stdout, name, seq) fileHandle.close()
def main(): parser = argparse.ArgumentParser() parser.add_argument("--unmasked") parser.add_argument("--hardmasked") parser.add_argument("--softmasked") options = parser.parse_args() unmasked = open(options.unmasked, 'r') hardmasked = open(options.hardmasked, 'r') softmasked = open(options.softmasked, 'w') for unmaskedInfo, hardmaskedInfo in itertools.izip(bioio.fastaRead(unmasked), bioio.fastaRead(hardmasked)): unmaskedName, unmaskedSeq = unmaskedInfo hardmaskedName, hardmaskedSeq = hardmaskedInfo print("processing sequence: %s" % unmaskedName) assert unmaskedName == hardmaskedName softmaskedSeq = '' for unmaskedBase, hardmaskedBase in zip(unmaskedSeq, hardmaskedSeq): if unmaskedBase.upper() == hardmaskedBase.upper(): softmaskedBase = unmaskedBase.upper() else: if not hardmaskedBase.upper() == 'N': print("Warning: encountered differing base: %s %s" % (unmaskedBase, hardmaskedBase)) softmaskedBase = unmaskedBase.lower() softmaskedSeq += softmaskedBase bioio.fastaWrite(softmasked, unmaskedName, softmaskedSeq)
def testFastaReadWrite(self): tempFile = getTempFile() self.tempFiles.append(tempFile) for test in xrange(0, self.testNo): fastaNumber = random.choice(xrange(10)) l = [ getRandomSequence() for i in xrange(fastaNumber) ] fileHandle = open(tempFile, 'w') for name, seq in l: fastaWrite(fileHandle, name, seq) fileHandle.close() fileHandle = open(tempFile, 'r') l.reverse() for i in fastaRead(fileHandle): assert i == l.pop() name, seq = i fastaWrite(sys.stdout, name, seq) fileHandle.close()