일부 유전자 ID 매핑을 수행하려면 Python 패키지 https://pypi.python.org/pypi/mygene 을 사용하고 있습니다. 나는 아래의 코드를 가지고 :리디렉션 API Stderr python
#! /usr/bin/env python
# ID mapping using mygene
# https://pypi.python.org/pypi/mygene
# http://nbviewer.ipython.org/gist/newgene/6771106
# http://mygene-py.readthedocs.org/en/latest/
# 08/30/14
__author__ = 'tommy'
import mygene
import fileinput
import sys
mg = mygene.MyGeneInfo()
# mapping gene symbols to Entrez gene ids and Ensemble gene ids.
# fileinput will loop through all the lines in the input specified as file names given in command-line arguments,
# or the standard input if no arguments are provided.
# build a list from an input file with one gene name in each line
def get_gene_symbols():
gene_symbols = []
for line in fileinput.input():
gene_symbol = line.strip() # assume each line contains only one gene symbol
gene_symbols.append(gene_symbol)
fileinput.close()
return gene_symbols
Entrez_ids = mg.querymany(get_gene_symbols(), scopes='symbol', fields='entrezgene', species='human', as_dataframe=True)
# set as_dataframe to True will return a pandas dataframe object
Entrez_ids.to_csv(sys.stdout, sep="\t") # write the dataframe to stdout
# sys.stdout.write() expects the character buffer object
Entrez_ids.to_csv("Entrez_ids.txt", sep="\t") # write the pandas dataframe to csv
내 질문은 내가 Entrez_ids.to_csv ("Entrez_ids.txt"9 월 = "\의 t")를 사용하는 경우 '완료 같은 결과 파일은 표준 오류가 포함되지 것입니다 .. .)하지만 Entrez_ids.to_csv (sys.stdout, sep = "\ t")는 stderr 메시지와 데이터 프레임을 모두 인쇄합니다.
Entrez_ids.to_csv (sys.stdout, sep = "\ t")를 사용하는 경우 어떻게 stderr를 리디렉션 할 수 있습니까? 감사합니다.
명령 행에서, 당신은'2 your-file.py 파이썬을 사용할 수 있습니다 > error.log.txt'를 입력하여 출력을 리디렉션하십시오. 다른 걸 원해? – doptimusprime
감사합니다. 나는이 트릭을 알고 있습니다. 내가 한 일은 : python my-file.py input.txt 2>/dev/null하지만 표준 오류는 여전히 화면에 출력됩니다. 입력 파일이 같다 : CCDC83 MAST3 FLOT1 RPL11 ZDHHC20 LUC7L3 SNORD49A 라인 당 하나의 유전자 이름 CTSH ACOT8. 당신은 혼자서 그것을 테스트 할 수 있습니다. mg.querymany 함수가 오류 메시지와 데이터 프레임을 모두 반환하기 때문이라고 생각합니다. – crazyhottommy