10 個のデータ ファイルを取得し、それらを 1 行ずつ読み取り、ファイル内の最初の (遺伝子) 項目と 3 番目の (値) 項目の辞書を作成し、これらすべてを 1 つの出力ファイルに結合するスクリプトを作成しようとしています。 10 回の反復の平均を示す 12 列目。(これをいくつかの異なるサンプルに対して行い、それぞれ 10 回の複製を行います。) for ループと range 関数を使用して、ファイル名、辞書名などを自動的に生成しようとしています。辞書を作成するコードを 10 回書き出すよりも仕事をする方法。しかし、私はコーディングが初めてで、コードの 11 行目 ('gene{0}key'.format(i) = []) で「SyntaxError: can't assign to function call」というメッセージが引き続き表示されます。同じように構造化された他のいくつかのコード行に対しても同じことが行われます。誰かが私が間違っていることを知っているなら、それが何であるか知りたいです! 前もって感謝します!
#!/usr/bin/env ipython
import re
import itertools
import numpy
sample = raw_input('sample: ')
for i in range(10):
filename = sample+'_rand{0}.genes.tajD'.format(i)
'gene{0}key'.format(i) = []
'taj{0}value'.format(i) = []
with open(filename, 'r') as data:
for line in data:
line = line.strip().split('\t')
gene, taj = line[0], line[3]
'gene{0}key'.format(i).append(gene)
'taj{0}value'.format(i).append(taj)
'dic{0}'.format(i) = dict(itertools.izip('gene{0}key'.format(i),'taj{0}value'.format(i)))
outfilename = sample+'_tajD.genes.all'
with open(sample+'_rand0.genes.tajD', 'r') as genes, open(outfilename, 'w') as outfile :
for line in genes :
line = line.strip().split('\t')
mastergene = line[0]
for i in range(10):
'value{0}'.format(i) = 'dic{0}'.format(i)[mastergene]
allrand = [value0, value1, value2, value3, value4, value5, value6, value7, value8, value9]
avg = numpy.mean(allrand)
outfile.write(mastergene + '\t' + value0 + '\t' + value1 + '\t' + value2 +'\t' + value3 + '\t' + value4 + '\t' + value5 + '\t' + value6 + '\t' + value7 + '\t' + value8 + '\t' + value9 + '\t' + avg + '\n')