本文整理汇总了Python中cogent.struct.rna2d.Pairs.hasConflicts方法的典型用法代码示例。如果您正苦于以下问题:Python Pairs.hasConflicts方法的具体用法?Python Pairs.hasConflicts怎么用?Python Pairs.hasConflicts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cogent.struct.rna2d.Pairs
的用法示例。
在下文中一共展示了Pairs.hasConflicts方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_residues
# 需要导入模块: from cogent.struct.rna2d import Pairs [as 别名]
# 或者: from cogent.struct.rna2d.Pairs import hasConflicts [as 别名]
def parse_residues(residue_lines, num_base, unpaired_symbol):
"""Return RnaSequence and Pairs object from residue lines.
residue_lines -- list of lines or anything that behaves like it.
Lines should contain:
residue_position, residue_identiy, residue_partner.
num_base -- int, basis of the residue numbering. In bpseq files from
the CRW website, the numbering starts at 1.
unpaired_symbol -- string, symbol in the 'partner' column that indicates
that a base is unpaired. In bpseq files from the CRW website, the
unpaired_symbol is '0'. This parameter should be a string to allow
other symbols that can't be casted to an integer to indicate
unpaired bases.
Checks for double entries both in the sequence and the structure, and
checks that the structre is valid in the sense that if (up,down) in there,
that (down,up) is the same.
"""
#create dictionary/list for sequence and structure
seq_dict = {}
pairs = Pairs()
for line in residue_lines:
try:
pos, res, partner = line.strip().split()
if partner == unpaired_symbol:
# adjust pos, not partner
pos = int(pos) - num_base
partner = None
else:
# adjust pos and partner
pos = int(pos) - num_base
partner = int(partner) - num_base
pairs.append((pos,partner))
#fill seq_dict
if pos in seq_dict:
raise BpseqParseError(\
"Double entry for residue %s (%s in bpseq file)"\
%(str(pos), str(pos+1)))
else:
seq_dict[pos] = res
except ValueError:
raise BpseqParseError("Failed to parse line: %s"%(line))
#check for conflicts, remove unpaired bases
if pairs.hasConflicts():
raise BpseqParseError("Conflicts in the list of basepairs")
pairs = pairs.directed()
pairs.sort()
# construct sequence from seq_dict
seq = RnaSequence(construct_sequence(seq_dict))
return seq, pairs
示例2: PairsTests
# 需要导入模块: from cogent.struct.rna2d import Pairs [as 别名]
# 或者: from cogent.struct.rna2d.Pairs import hasConflicts [as 别名]
#.........这里部分代码省略.........
self.assertRaises(Exception,b.toVienna,7) #old test for exception
self.assertRaises(ValueError,c.toVienna,7)
#pairs containging None are being skipped
self.assertEquals(d.toVienna(7),'.(....)')
#raises error when trying to insert at non-existing indices
self.assertRaises(IndexError,a.toVienna,3)
self.assertEqual(Pairs().toVienna(3),'...')
#test when parsing in the sequence
self.assertEqual(a.toVienna('ACGUAGCUAG'),'.(.())(())')
self.assertEqual(a.toVienna(Rna('AACCGGUUAGCUA'), offset=3),\
'....(.())(())')
self.assertEqual(e.toVienna(10),'.(((...)))')
self.assertEqual(f.toVienna(20),'.((..))...((..))....')
def test_tuples(self):
"""Pairs tuples() should transform the elements of list to tuples"""
x = Pairs([])
x.tuples()
assert x == []
x = Pairs([[1,2],[3,4]])
x.tuples()
assert x == [(1,2),(3,4)]
x = Pairs([(1,2),(3,4)])
x.tuples()
assert x == [(1,2),(3,4)]
assert x != [[1,2],[3,4]]
def test_unique(self):
"""Pairs unique() should remove double occurences of certain tuples"""
self.assertEqual(self.Empty.unique(),[])
self.assertEqual(self.MoreTuples.unique(),self.MoreTuples)
self.assertEqual(self.Doubles.unique(),Pairs([(1,2),(2,3),(1,3)]))
def test_directed(self):
"""Pairs directed() should change all pairs so that a<b in (a,b)"""
self.assertEqual(self.Empty.directed(),[])
res = self.Undirected.directed()
res.sort()
self.assertEqual(res,Pairs([(1,2),(1,7),(3,8),(4,6)]))
res = self.UndirectedNone.directed()
self.assertEqual(res,Pairs([]))
res = self.UndirectedDouble.directed()
self.assertEqual(res,Pairs([(1,2)]))
def test_symmetric(self):
"""Pairs symmetric() should add (down,up) for each (up,down)"""
self.assertEqual(self.Empty.symmetric(),[])
self.assertEqualItems(self.OneTuple.symmetric(),[(2,1),(1,2)])
self.assertEqualItems(Pairs([(1,2),(1,2)]).symmetric(),[(1,2),(2,1)])
self.assertEqualItems(Pairs([(1,2),(3,4)]).symmetric(),\
[(1,2),(2,1),(3,4),(4,3)])
self.assertEqualItems(Pairs([(1,None)]).symmetric(),[])
def test_paired(self):
"""Pairs paired() should omit all pairs containing None"""
self.assertEqual(self.Empty.paired(),[])
self.assertEqual(Pairs([(1,2),(2,None),(None,3),(None,None)]).paired()\
,[(1,2)])
def test_hasConflicts(self):
"""Pairs hasConflicts() should return True if there are conflicts"""
assert not self.Empty.hasConflicts()
assert not Pairs([(1,2),(3,4)]).hasConflicts()
assert Pairs([(1,2),(2,3)]).hasConflicts()
assert Pairs([(1,2),(2,None)]).hasConflicts()
def test_mismatches(self):
"""Pairs mismatches() should return #pairs that can't be formed"""
# with plain string
self.assertEqual(Pairs([(0,1)]).mismatches('AC',{}),1)
self.assertEqual(Pairs([(0,1)]).mismatches('AC',{('A','C'):None}),0)
self.assertEqual(Pairs([(0,1)]).mismatches('AC',{('A','G'):None}),1)
self.assertEqual(Pairs([(0,1),(2,3),(3,1)]).\
mismatches('ACGU',{('A','U'):None}),3)
# using sequence with alphabet
sequence = Rna('ACGUA')
self.assertEqual(Pairs([(0,1),(0,4),(0,3)]).mismatches(sequence),2)
def test_hasPseudoknots(self):
"""Pairs hasPseudoknots() should return True if there's a pseudoknot"""
assert not self.NoPseudo.hasPseudoknots()
assert not self.NoPseudo2.hasPseudoknots()
#add tests for ((.))() etc
assert self.p0.hasPseudoknots()
assert self.p1.hasPseudoknots()
assert self.p2.hasPseudoknots()
assert self.p3.hasPseudoknots()
assert self.p4.hasPseudoknots()
assert self.p5.hasPseudoknots()
assert self.p6.hasPseudoknots()
assert self.p7.hasPseudoknots()