本文整理汇总了Python中CGAT.Genomics.resolveAmbiguousNA方法的典型用法代码示例。如果您正苦于以下问题:Python Genomics.resolveAmbiguousNA方法的具体用法?Python Genomics.resolveAmbiguousNA怎么用?Python Genomics.resolveAmbiguousNA使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGAT.Genomics
的用法示例。
在下文中一共展示了Genomics.resolveAmbiguousNA方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updateSNPs
# 需要导入模块: from CGAT import Genomics [as 别名]
# 或者: from CGAT.Genomics import resolveAmbiguousNA [as 别名]
def updateSNPs(self, snp, is_negative_strand, pos):
"""update SNPs."""
contig = snp.chromosome
lcontig = self.mFasta.getLength(contig)
reference_base = snp.reference_base
if snp.genotype in "ACGTacgt":
# homozygous substitution
self.mVariantType.append("O")
else:
# heterozygous substitution
self.mVariantType.append("E")
# switch reference strand codon to correct strand
if reference_base != "*" and is_negative_strand:
reference_base = Genomics.complement(reference_base)
# collect all possible variants of reference codons
for reference_codon in self.mReferenceCodons:
self.mReferenceAAs.append(Genomics.translate(reference_codon))
# process single base changes
variant_bases = Genomics.resolveAmbiguousNA(snp.genotype)
if reference_codon[pos] != reference_base:
raise ValueError(
"base mismatch at %i (codon=%s,%i): codon:%s != genome:%s; `%s`"
% (snp.pos, reference_codon, pos, reference_codon[pos], reference_base, ";".join(map(str, snp)))
)
for variant_base in variant_bases:
if is_negative_strand:
variant_base = Genomics.complement(variant_base)
self.mVariantAAs.extend([Genomics.translate(x) for x in self.mVariantCodons])
示例2: buildSequenceVariants
# 需要导入模块: from CGAT import Genomics [as 别名]
# 或者: from CGAT.Genomics import resolveAmbiguousNA [as 别名]
def buildSequenceVariants(self, seq, strand, pos, snp):
'''build new sequence by modifying a sequence fragment in seq at
pos with snp.
It is assumed that seq is already oriented according to strand.
The strand is used to revert the snp if necessary.
Note that only sequences different from seq will be returned.
returns is_homozygous, seqs
'''
is_negative_strand = Genomics.IsNegativeStrand(strand)
reference_base = snp.reference_base
if reference_base != "*" and is_negative_strand:
reference_base = Genomics.complement(reference_base)
new_sequences = []
is_homozygous = True
if reference_base != "*":
if seq[pos].upper() != reference_base.upper():
raise ValueError("base mismatch at snp %i, expected %s, got %s in %s at position %i; snp=%s" %
(snp.pos, reference_base, seq[pos], seq, pos,
";".join(map(str, snp))))
# single base changes
variant_bases = Genomics.resolveAmbiguousNA(snp.genotype)
if len(variant_bases) == 1:
is_homozygous = True
else:
is_homozygous = False
for variant_base in variant_bases:
if is_negative_strand:
variant_base = Genomics.complement(variant_base)
s = list(seq)
s[pos] = variant_base
s = "".join(s)
if s != seq:
new_sequences.append(s)
else:
variants = snp.genotype.split("/")
is_homozygous = False
for variant in variants:
s = list(seq)
# samtools denotes insert/deletion after position
# while python is before/at position, hence the pos+1
if variant[0] == "+":
toinsert = variant[1:].upper()
if is_negative_strand:
toinsert = Genomics.complement(toinsert)
s.insert(pos, toinsert)
else:
s.insert(pos + 1, toinsert)
elif variant[0] == "-":
# pos+1+len(x)-1 = pos+len(x)
todelete = variant[1:].upper()
l = len(todelete)
if is_negative_strand:
# delete left of pos
xstart = max(0, pos - l)
xend = pos
todelete = todelete[:min(l, pos)]
else:
# delete right of pos
xstart = pos + 1
xend = min(self.mSize, pos + 1 + l)
todelete = todelete[:self.mSize - (pos + 1)]
deleted = "".join(s[xstart:xend])
if is_negative_strand:
deleted = Genomics.complement(deleted)
if deleted != todelete:
raise ValueError("base mismatch at indel %i, expected %s, got %s in %s at position %i(%i:%i); is_negative_strand=%s, snp=%s" %
(snp.pos, todelete, deleted, seq, pos, xstart, xend,
is_negative_strand,
";".join(map(str, snp))))
del s[xstart:xend]
elif variant[0] == "*":
is_homozygous = True
else:
raise ValueError("unknown variant sign '%s'" % variant[0])
s = "".join(s)
if s != seq:
new_sequences.append(s)
return is_homozygous, new_sequences