これは私の最初のスクリプトで、2つのゲノムファイルを比較しようとしています。正規表現でリスト要素を使って大文字で一致するものを探す
rs3094315 1 742429 AA
rs12562034 1 758311 GG
rs3934834 1 995669 CC
各フィールド間のタブがあります。
ファイルの内容は次のようになります。各ファイルには約50万行あります。
これらを簡単に比較するために、両方のファイルに含まれているデータポイントのみを保持し、いずれかのデータポイントを破棄したいと考えました。これを行うために、私はユニークなすべてのDNA位置のリストを作成しましたが、元のデータファイルの各行を検索し、これらのユニークなDNA位置を含まないすべての行を新しいファイルに印刷しようとしています。
正規表現を使用してゲノムファイルを検索してすべての固有でないDNA位置を表示しようとするまで、コード内のすべてが機能しました。私の質問は2倍である
Traceback (most recent call last):
File "/Users/laurelhochstetler/scripts/identify_SNPs.py", line 57, in <module>
if re.match(item,"(.*)", Line):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 137, in match
return _compile(pattern, flags).match(string)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 242, in _compile
p = sre_compile.compile(pattern, flags)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_compile.py", line 500, in compile
p = sre_parse.parse(p, flags)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_parse.py", line 673, in parse
p = _parse_sub(source, pattern, 0)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_parse.py", line 308, in _parse_sub
itemsappend(_parse(source, state))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_parse.py", line 401, in _parse
if state.flags & SRE_FLAG_VERBOSE:
TypeError: unsupported operand type(s) for &: 'str' and 'int'
:私は、スクリプトがfor
ループ内LaurelSNP_left
リスト内のすべての項目を印刷するために得ることができますが、私は、各項目のre.match
を使用しようとすると、私はこのエラーメッセージが表示されます
- 正規表現でリストを使用するにはどうすればよいですか?
- ここでやろうとしていることを達成するためのよりよい方法はありますか?ここで
私のコードです:
#!/usr/bin/env python
import re #this imports regular expression module
import collections
MomGenome=open('/Users/laurelhochstetler/Documents/genetics fun/genome_Mary_Maloney_Full_20110514145353.txt', 'r')
LaurelGenome=open('/Users/laurelhochstetler/Documents/genetics fun/genome_Laurel_Hochstetler_Full_20100411230740.txt', 'r')
LineNumber = 0
momSNP = []
LaurelSNP = []
f = open("mom_edit.txt","w")
for Line in MomGenome:
if LineNumber > 0:
Line=Line.strip('\n')
ElementList=Line.split('\t')
momSNP.append(ElementList[0])
LineNumber = LineNumber + 1
MomGenome.close()
for Line in LaurelGenome:
if LineNumber > 0:
Line=Line.strip('\n')
ElementList=Line.split('\t')
LaurelSNP.append(ElementList[0])
LineNumber = LineNumber + 1
momSNP_multiset = collections.Counter(momSNP)
LaurelSNP_multiset = collections.Counter(LaurelSNP)
overlap = list((momSNP_multiset and LaurelSNP_multiset).elements())
momSNP_left = list((momSNP_multiset - LaurelSNP_multiset).elements())
LaurelSNP_left = list((LaurelSNP_multiset - momSNP_multiset).elements())
LaurelGenome=open('/Users/laurelhochstetler/Documents/genetics fun/genome_Laurel_Hochstetler_Full_20100411230740.txt', 'r')
i = 0
for Line in LaurelGenome:
for item in LaurelSNP_left:
if i < 1961:
if re.match(item, Line):
pass
else:
print Line
i = i + 1
LineNumber = LineNumber + 1
入力ファイルの表示例を教えてください。 – Thomas
23&meからの生データを使用している人を見て涼しいです! – Stedy
さて、ファイルの行のいくつかの例を追加しました!そしてはい、Stedy、私は家系図の目的のために対立遺伝子のデータに夢中になります! – blizpix