我是Python的新手,但我真的想在Linux服务器命令行上执行以下功能。当我执行以下脚本(test.py)时,请帮助弄清楚为什么没有打印出来?要执行,我键入python test.py
。谢谢。
##!/usr/bin/python
def get_minimal_representation(pos, ref, alt):
"""
Get the minimal representation of a variant, based on the ref + alt alleles in a VCF
This is used to make sure that multiallelic variants in different datasets,
with different combinations of alternate alleles, can always be matched directly.
Note that chromosome is ignored here - in xbrowse, we'll probably be dealing with 1D coordinates
Args:
pos (int): genomic position in a chromosome (1-based)
ref (str): ref allele string
alt (str): alt allele string
Returns:
tuple: (pos, ref, alt) of remapped coordinate
"""
pos = int(pos)
# If it's a simple SNV, don't remap anything
if len(ref) == 1 and len(alt) == 1:
return pos, ref, alt
else:
# strip off identical suffixes
while(alt[-1] == ref[-1] and min(len(alt),len(ref)) > 1):
alt = alt[:-1]
ref = ref[:-1]
# strip off identical prefixes and increment position
while(alt[0] == ref[0] and min(len(alt),len(ref)) > 1):
alt = alt[1:]
print "Alt: ", alt
ref = ref[1:]
print "Ref: ", ref
pos += 1
print "Pos: ", pos
return pos, ref, alt
print "the result is: ", get_minimal_representation( pos = 1001, ref = "CTCC", alt = "CCC,C,CCCC")
答案 0 :(得分:4)
您没有调用此功能。
尝试
if __name__ == '__main__':
print "the result is: ", get_minimal_representation( pos = 1001, ref = "CTCC", alt = "CCC,C,CCCC")
位于文件底部。
应该是这样的:
##!/usr/bin/python
def get_minimal_representation(pos, ref, alt):
"""
Get the minimal representation of a variant, based on the ref + alt alleles in a VCF
This is used to make sure that multiallelic variants in different datasets,
with different combinations of alternate alleles, can always be matched directly.
Note that chromosome is ignored here - in xbrowse, we'll probably be dealing with 1D coordinates
Args:
pos (int): genomic position in a chromosome (1-based)
ref (str): ref allele string
alt (str): alt allele string
Returns:
tuple: (pos, ref, alt) of remapped coordinate
"""
pos = int(pos)
# If it's a simple SNV, don't remap anything
if len(ref) == 1 and len(alt) == 1:
return pos, ref, alt
else:
# strip off identical suffixes
while(alt[-1] == ref[-1] and min(len(alt),len(ref)) > 1):
alt = alt[:-1]
ref = ref[:-1]
# strip off identical prefixes and increment position
while(alt[0] == ref[0] and min(len(alt),len(ref)) > 1):
alt = alt[1:]
print "Alt: ", alt
ref = ref[1:]
print "Ref: ", ref
pos += 1
print "Pos: ", pos
return pos, ref, alt
if __name__ == '__main__':
print "the result is: ", get_minimal_representation( pos = 1001, ref = "CTCC", alt = "CCC,C,CCCC")
答案 1 :(得分:1)
您对上一个print语句的缩进有问题。它应该在函数之外。
v2.0.0