이 스크립트의 목적은 텍스트 파일 (sys.argv [1])을 구문 분석하고 특정 문자열을 추출하여 열에 인쇄하는 것입니다. 머리글을 인쇄하는 것으로 시작합니다. 그런 다음 파일을 열고 그 파일을 한 줄씩 살펴 봅니다. 그 라인이 특정 시작을 가지고 있는지 또는 특정 문자열을 포함하는지 확인한 다음 정규 표현식을 사용하여 특정 값을 추출합니다. 일치 및 추출이 올바르게 작동합니다.str.format는 마지막 변수를 먼저 인쇄합니다.
최종 인쇄문이 제대로 작동하지 않습니다.
import re
import sys
print("{}\t{}\t{}\t{}\t{}".format("#query", "target", "e-value",
"identity(%)", "score"))
with open(sys.argv[1], 'r') as blastR:
for line in blastR:
if line.startswith("Query="):
queryIDMatch = re.match('Query= (([^ ])+)', line)
queryID = queryIDMatch.group(1)
queryID.rstrip
if line[0] == '>':
targetMatch = re.match('> (([^ ])+)', line)
target = targetMatch.group(1)
target.rstrip
if "Score = " in line:
eValue = re.search(r'Expect = (([^ ])+)', line)
trueEvalue = eValue.group(1)
trueEvalue = trueEvalue[:-1]
trueEvalue.rstrip()
print('{0}\t{1}\t{2}'.format(queryID, target, trueEvalue), end='')
열을 인쇄하려고하면 문제가 발생합니다. 내가 추가 할 때
#query target e-value identity(%) score
YAL002W Paxin1_129011
YAL003W Paxin1_167503
YAL005C Paxin1_162475
YAL005C Paxin1_167442
제 3 열은 2E-34
같은 과학적 표기법의 숫자입니다하지만 : 내가 처음이 열을 인쇄 할 때, 그것은 예상대로 (여전히 새로운 라인을 인쇄하는 사용자들은 제외) 작동 3 열은 eValue, 그것은 분해 :
#query target e-value identity(%) score
YAL002W Paxin1_129011
4e-43YAL003W Paxin1_167503
1e-55YAL005C Paxin1_162475
0.0YAL005C Paxin1_167442
0.0YAL005C Paxin1_73182
나는 rstrip() 메소드를 사용하여, 지금까지의 내가 알고, 모든 새로운 라인을 제거했습니다.
그래, 그게 다야! 나는 항상 완고한 끈이 어떻게 변하는 지 잊고있다. – Glubbdrubb