本文整理汇总了Python中pbcore.io.AlignmentSet类的典型用法代码示例。如果您正苦于以下问题:Python AlignmentSet类的具体用法?Python AlignmentSet怎么用?Python AlignmentSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AlignmentSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mainCmpH5
def mainCmpH5(options):
alnReader = AlignmentSet(options.inputCmpH5,
referenceFastaFname=options.referenceFilename)
if options.fofn is not None:
alnReader.attach(options.fofn)
if options.referenceFilename:
referenceTable = loadReferences(options.referenceFilename, alnReader)
else:
referenceTable = None
for refWindow in options.referenceWindows:
refId = refWindow.refId
refName = alnReader.referenceInfo(refWindow.refId).FullName
refLength = alnReader.referenceInfo(refWindow.refId).Length
refWindow = refWindow._replace(refId=refId)
refWindow = makeDisplayWindow(refLength, options.width, refWindow)
if options.rowNumbers != None:
alns = alnReader[options.rowNumbers]
else:
alns = readsInWindow(alnReader, refWindow, options.depth,
minMapQV=options.minMapQV, strategy=options.sorting)
print windowToGffString(Window(refName, refWindow.start, refWindow.end))
if options.oneAtATime:
formatIndividualAlignments(alnReader, refWindow, alns)
else:
formatWindow(alnReader, refWindow, alns,
referenceTable, options.aligned, options.color,
options.realign, options.consensus)
print
示例2: test_refWindows
def test_refWindows(self):
ds = AlignmentSet(data.getBam())
dss = ds.split(chunks=2, contigs=True)
self.assertEqual(len(dss), 2)
log.debug(dss[0].filters)
log.debug(dss[1].filters)
self.assertTrue(
'( rname = E.faecalis.2 '
in str(dss[0].filters)
or
'( rname = E.faecalis.2 '
in str(dss[1].filters))
ds = AlignmentSet(data.getBam())
ds.filters.addRequirement(rname=[('=', 'E.faecalis.2'),
('=', 'E.faecalis.2')],
tStart=[('<', '99'),
('<', '299')],
tEnd=[('>', '0'),
('>', '100')])
self.assertEqual(str(ds.filters),
'( rname = E.faecalis.2 AND tstart '
'< 99 AND tend > 0 ) OR ( rname = '
'E.faecalis.2 AND tstart < 299 AND tend > 100 )')
self.assertEqual(ds.refWindows, [('E.faecalis.2', 0, 99),
('E.faecalis.2', 100, 299)])
示例3: test_alignment_reference
def test_alignment_reference(self):
rs1 = ReferenceSet(data.getXml(9))
fasta_res = rs1.externalResources[0]
fasta_file = urlparse(fasta_res.resourceId).path
ds1 = AlignmentSet(data.getXml(8),
referenceFastaFname=rs1)
aln_ref = None
for aln in ds1:
aln_ref = aln.reference()
break
self.assertTrue(aln_ref is not None)
ds1 = AlignmentSet(data.getXml(8),
referenceFastaFname=fasta_file)
aln_ref = None
for aln in ds1:
aln_ref = aln.reference()
break
self.assertTrue(aln_ref is not None)
ds1 = AlignmentSet(data.getXml(8))
ds1.addReference(fasta_file)
aln_ref = None
for aln in ds1:
aln_ref = aln.reference()
break
self.assertTrue(aln_ref is not None)
示例4: test_len_h5
def test_len_h5(self):
# HdfSubreadSet
# len means something else in bax/bas land. These numbers may actually
# be correct...
sset = HdfSubreadSet(data.getXml(17), strict=True)
self.assertEqual(len(sset), 9)
self.assertEqual(sset._length, (9, 128093))
self.assertEqual(sset.totalLength, 128093)
self.assertEqual(sset.numRecords, 9)
sset.totalLength = -1
sset.numRecords = -1
self.assertEqual(sset.totalLength, -1)
self.assertEqual(sset.numRecords, -1)
sset.updateCounts()
self.assertEqual(sset.totalLength, 128093)
self.assertEqual(sset.numRecords, 9)
# AlignmentSet with cmp.h5
aln = AlignmentSet(upstreamData.getBamAndCmpH5()[1], strict=True)
self.assertEqual(len(aln), 112)
self.assertEqual(aln._length, (112, 59970))
self.assertEqual(aln.totalLength, 59970)
self.assertEqual(aln.numRecords, 112)
aln.totalLength = -1
aln.numRecords = -1
self.assertEqual(aln.totalLength, -1)
self.assertEqual(aln.numRecords, -1)
aln.updateCounts()
self.assertEqual(aln.totalLength, 59970)
self.assertEqual(aln.numRecords, 112)
示例5: _make_alignmentset
def _make_alignmentset(file_name=None):
bam = pbcore.data.getBamAndCmpH5()[0]
ds = AlignmentSet(bam)
if file_name is None:
file_name = tempfile.NamedTemporaryFile(suffix=".alignmentset.xml").name
ds.write(file_name)
return file_name
示例6: test_len
def test_len(self):
# AlignmentSet
aln = AlignmentSet(data.getXml(8), strict=True)
self.assertEqual(len(aln), 92)
self.assertEqual(aln._length, (92, 123588))
self.assertEqual(aln.totalLength, 123588)
self.assertEqual(aln.numRecords, 92)
aln.totalLength = -1
aln.numRecords = -1
self.assertEqual(aln.totalLength, -1)
self.assertEqual(aln.numRecords, -1)
aln.updateCounts()
self.assertEqual(aln.totalLength, 123588)
self.assertEqual(aln.numRecords, 92)
self.assertEqual(sum(1 for _ in aln), 92)
self.assertEqual(sum(len(rec) for rec in aln), 123588)
# AlignmentSet with filters
aln = AlignmentSet(data.getXml(15), strict=True)
self.assertEqual(len(aln), 40)
self.assertEqual(aln._length, (40, 52023))
self.assertEqual(aln.totalLength, 52023)
self.assertEqual(aln.numRecords, 40)
aln.totalLength = -1
aln.numRecords = -1
self.assertEqual(aln.totalLength, -1)
self.assertEqual(aln.numRecords, -1)
aln.updateCounts()
self.assertEqual(aln.totalLength, 52023)
self.assertEqual(aln.numRecords, 40)
# SubreadSet
sset = SubreadSet(data.getXml(10), strict=True)
self.assertEqual(len(sset), 92)
self.assertEqual(sset._length, (92, 124093))
self.assertEqual(sset.totalLength, 124093)
self.assertEqual(sset.numRecords, 92)
sset.totalLength = -1
sset.numRecords = -1
self.assertEqual(sset.totalLength, -1)
self.assertEqual(sset.numRecords, -1)
sset.updateCounts()
self.assertEqual(sset.totalLength, 124093)
self.assertEqual(sset.numRecords, 92)
self.assertEqual(sum(1 for _ in sset), 92)
self.assertEqual(sum(len(rec) for rec in sset), 124093)
# ReferenceSet
sset = ReferenceSet(data.getXml(9), strict=True)
self.assertEqual(len(sset), 59)
self.assertEqual(sset.totalLength, 85774)
self.assertEqual(sset.numRecords, 59)
sset.totalLength = -1
sset.numRecords = -1
self.assertEqual(sset.totalLength, -1)
self.assertEqual(sset.numRecords, -1)
sset.updateCounts()
self.assertEqual(sset.totalLength, 85774)
self.assertEqual(sset.numRecords, 59)
示例7: test_filter
def test_filter(self):
ds2 = AlignmentSet(data.getXml(8))
ds2.filters.addRequirement(rname=[('=', 'E.faecalis.1')])
self.assertEqual(len(list(ds2.records)), 20)
ds2.disableFilters()
self.assertEqual(len(list(ds2.records)), 92)
ds2.enableFilters()
self.assertEqual(len(list(ds2.records)), 20)
示例8: test_readGroupTable
def test_readGroupTable(self):
aln = AlignmentSet(data.getBam(0), data.getBam(1), data.getBam(2))
readers = aln.resourceReaders()
self.assertEqual(len(readers[0].readGroupTable), 1)
self.assertEqual(len(readers[1].readGroupTable), 1)
self.assertEqual(len(readers[2].readGroupTable), 1)
self.assertEqual(len(aln.readGroupTable), 3)
示例9: test_referenceInfo
def test_referenceInfo(self):
aln = AlignmentSet(data.getBam(0))
readers = aln.resourceReaders()
self.assertEqual(len(readers[0].referenceInfoTable), 59)
self.assertEqual(
str(readers[0].referenceInfo('E.faecalis.1')),
"(27, 27, 'E.faecalis.1', 'E.faecalis.1', 1482, "
"'a1a59c267ac1341e5a12bce7a7d37bcb', 0L, 0L)")
示例10: test_alignment_reference
def test_alignment_reference(self):
rfn = data.getXml(9)
rs1 = ReferenceSet(data.getXml(9))
fasta_res = rs1.externalResources[0]
fasta_file = urlparse(fasta_res.resourceId).path
ds1 = AlignmentSet(data.getXml(8),
referenceFastaFname=rs1)
aln_ref = None
for aln in ds1:
aln_ref = aln.reference()
break
self.assertTrue(aln_ref is not None)
self.assertEqual(ds1.externalResources[0].reference, fasta_file)
self.assertEqual(ds1.resourceReaders()[0].referenceFasta.filename,
fasta_file)
ds1 = AlignmentSet(data.getXml(8),
referenceFastaFname=fasta_file)
aln_ref = None
for aln in ds1:
aln_ref = aln.reference()
break
self.assertTrue(aln_ref is not None)
self.assertEqual(ds1.externalResources[0].reference, fasta_file)
self.assertEqual(ds1.resourceReaders()[0].referenceFasta.filename,
fasta_file)
ds1 = AlignmentSet(data.getXml(8))
ds1.addReference(fasta_file)
aln_ref = None
for aln in ds1:
aln_ref = aln.reference()
break
self.assertTrue(aln_ref is not None)
self.assertEqual(ds1.externalResources[0].reference, fasta_file)
self.assertEqual(ds1.resourceReaders()[0].referenceFasta.filename,
fasta_file)
fofn_out = tempfile.NamedTemporaryFile(suffix=".fofn").name
log.debug(fofn_out)
with open(fofn_out, 'w') as f:
f.write(data.getXml(8))
f.write('\n')
f.write(data.getXml(11))
f.write('\n')
ds1 = AlignmentSet(fofn_out,
referenceFastaFname=fasta_file)
aln_ref = None
for aln in ds1:
aln_ref = aln.reference()
break
self.assertTrue(aln_ref is not None)
self.assertEqual(ds1.externalResources[0].reference, fasta_file)
self.assertEqual(ds1.resourceReaders()[0].referenceFasta.filename,
fasta_file)
示例11: test_split_by_contigs_with_split
def test_split_by_contigs_with_split(self):
# test to make sure the refWindows work when chunks == # refs
ds3 = AlignmentSet(data.getBam())
dss = ds3.split(contigs=True)
self.assertEqual(len(dss), 12)
refWindows = sorted(reduce(lambda x, y: x + y,
[ds.refWindows for ds in dss]))
# not all references have something mapped to them, refWindows doesn't
# care...
self.assertNotEqual(refWindows, sorted(ds3.refWindows))
random_few = [('C.beijerinckii.13', 0, 1433),
('B.vulgatus.4', 0, 1449),
('E.faecalis.1', 0, 1482)]
for reference in random_few:
found = False
for ref in refWindows:
if ref == reference:
found = True
self.assertTrue(found)
old_refWindows = refWindows
dss = ds3.split(contigs=True, chunks=1)
self.assertEqual(len(dss), 1)
refWindows = sorted(reduce(lambda x, y: x + y,
[ds.refWindows for ds in dss]))
self.assertEqual(refWindows, old_refWindows)
dss = ds3.split(contigs=True, chunks=24)
self.assertEqual(len(dss), 24)
refWindows = sorted(reduce(lambda x, y: x + y,
[ds.refWindows for ds in dss]))
random_few = [('E.faecalis.2', 0, 741),
('E.faecalis.2', 741, 1482)]
for ref in random_few:
found = False
for window in refWindows:
if ref == window:
found = True
if not found:
log.debug(ref)
self.assertTrue(found)
dss = ds3.split(contigs=True, chunks=36)
self.assertEqual(len(dss), 36)
refWindows = sorted(reduce(lambda x, y: x + y,
[ds.refWindows for ds in dss]))
random_few = [('E.faecalis.2', 0, 494),
('E.faecalis.2', 494, 988),
('E.faecalis.2', 988, 1482)]
for ref in random_few:
found = False
for window in refWindows:
if ref == window:
found = True
self.assertTrue(found)
示例12: test_referenceInfoTable
def test_referenceInfoTable(self):
aln = AlignmentSet(data.getBam(0), data.getBam(1), data.getBam(2))
readers = aln.resourceReaders()
self.assertEqual(len(readers[0].referenceInfoTable), 1)
self.assertEqual(len(readers[1].referenceInfoTable), 59)
self.assertEqual(len(readers[2].referenceInfoTable), 1)
self.assertEqual(readers[0].referenceInfoTable.Name,
readers[2].referenceInfoTable.Name)
self.assertEqual(len(aln.referenceInfoTable), 60)
示例13: test_relativize_cli
def test_relativize_cli(self):
fn = tempfile.NamedTemporaryFile(suffix=".alignmentset.xml").name
aln = AlignmentSet(data.getXml(8))
aln.copyTo(fn)
self.assertFalse(_is_relative(fn))
cmd = "dataset relativize {d}".format(d=fn)
log.debug(cmd)
o, r, m = backticks(cmd)
self.assertEqual(r, 0)
self.assertTrue(os.path.exists(fn))
self.assertTrue(_is_relative(fn))
示例14: test_updateCounts
def test_updateCounts(self):
log.info("Testing updateCounts without filters")
aln = AlignmentSet(data.getBam(0))
readers = aln.resourceReaders()
expLen = 0
for reader in readers:
for record in reader:
expLen += record.readLength
self.assertEqual(
record.aStart, record.bam.pbi[record.rowNumber]['aStart'])
self.assertEqual(
record.aEnd, record.bam.pbi[record.rowNumber]['aEnd'])
expNum = 0
for reader in readers:
expNum += len(reader)
accLen = aln.metadata.totalLength
accNum = aln.metadata.numRecords
self.assertEqual(expLen, accLen)
self.assertEqual(expNum, accNum)
log.info("Testing whether filters are respected")
aln.filters.addRequirement(rname=[('=', 'E.faecalis.1')])
aln.updateCounts()
accLen = aln.metadata.totalLength
accNum = aln.metadata.numRecords
def count(gen):
count = 0
for _ in gen:
count += 1
return count
expLen = 0
for reader in readers:
for record in reader:
expLen += record.readLength
bfile = openIndexedAlignmentFile(data.getBam(0))
rWin = (bfile.referenceInfo('E.faecalis.1').ID,
0,
bfile.referenceInfo('E.faecalis.1').Length)
reads = bfile.readsInRange(*rWin)
expNum = count(reads)
expLen = 0
reads = bfile.readsInRange(*rWin)
for read in reads:
expLen += read.readLength
self.assertEqual(expLen, accLen)
self.assertEqual(expNum, accNum)
示例15: test_newUuid_cli
def test_newUuid_cli(self):
fn = tempfile.NamedTemporaryFile(suffix=".alignmentset.xml").name
aln = AlignmentSet(data.getXml(8))
aln.copyTo(fn)
pre_uuid = AlignmentSet(fn).uuid
cmd = "dataset newuuid {d}".format(d=fn)
log.debug(cmd)
o, r, m = backticks(cmd)
post_uuid = AlignmentSet(fn).uuid
self.assertEqual(r, 0)
self.assertTrue(os.path.exists(fn))
self.assertNotEqual(pre_uuid, post_uuid)