2016-11-15 4 views
0

저는 파이썬을 처음 사용 합니다만, 리눅스 서버 명령 행에서 다음 함수를 실행하고 싶습니다. 다음 스크립트 (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") 
+2

모두 당신이하는 일은 기능을 정의하는 것입니다. 넌 그걸 부르지 않을거야. –

+0

"print"결과는 다음과 같습니다 : ", get_minimal_representation (pos = 1001, ref ="CTCC ", alt ="CCC, C, CCCC ") 아니요? – user3781528

+0

무엇을 실행하고 싶습니까? 함수를 정의하는 것 외에도 함수를 호출해야하며이를 수행하려면 함수에 전달할 3 개의 값이 필요합니다. – chepner

답변

1

당신은 마지막 인쇄 문장의 들여 쓰기에 문제가 있었다. 함수 외부에 있어야합니다.

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

이것은 Perl에서는 발생하지 않습니다. :) 나는 배울 것이 많다. 고마워요 – user3781528

+0

문제 없습니다 .Happens. 들여 쓰기가 정확한지 확인하십시오. :) – Inconnu

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")