タブ区切りファイルをソートするためにPythonからUNIXソートコマンドを呼び出そうとしていますが、できませんでした。私がそれについてグーグルで調べたところ、コマンドに -t$'\t' を追加すると機能することがわかり、シェルからソートしようとしたときにも機能しましたが、Python から試行すると機能しません。
これは私がスクリプトで試したことです
tabdel="$'\t'"
sort_file_cmd="sort -t {1} -k2,2 -k6,6n {0}".format(file_to_be_sorted.name,tabdel)
print sort_file_cmd,shlex.split(sort_file_cmd)
subprocess.call(sort_file_cmd,stdout=sort_bt,shell=True)
はこれprint sort_file_cmd
を印刷します
sort -t $'\t' -k2,2 -k6,6n human_vs_mouse.tab
シェルから実行すると完全に機能しますが、Pythonスクリプトから実行すると sort: multi-character tab '$\t' エラーが発生します
どうすればこれを克服できますか?
サンプルデータ
gi|52317161|ref|NM_001004713.1| Homo sapiens olfactory receptor, family 1, subfamily I, member 1 (OR1I1), mRNA gnl|BL_ORD_ID|10980 gi|58801268|ref|NP_001011737.1| olfactory receptor 1357 [Mus musculus] 3071921 1 307 1.90237e-150 1108.0
gi|52317161|ref|NM_001004713.1| Homo sapiens olfactory receptor, family 1, subfamily I, member 1 (OR1I1), mRNA gnl|BL_ORD_ID|460 gi|22129025|ref|NP_667153.1| olfactory receptor 351 [Mus musculus] 302 10 915 2 303 5.70073e-105 806.0
gi|52317161|ref|NM_001004713.1| Homo sapiens olfactory receptor, family 1, subfamily I, member 1 (OR1I1), mRNA gnl|BL_ORD_ID|4490 gi|33238878|ref|NP_666817.1| olfactory receptor 24 [Mus musculus] 308 1 921 1 307 9.58658e-105 805.0
gi|52317161|ref|NM_001004713.1| Homo sapiens olfactory receptor, family 1, subfamily I, member 1 (OR1I1), mRNA gnl|BL_ORD_ID|458 gi|22129031|ref|NP_667152.1| olfactory receptor 353 [Mus musculus] 302 10 915 2 303 1.01585e-103 798.0
gi|52317161|ref|NM_001004713.1| Homo sapiens olfactory receptor, family 1, subfamily I, member 1 (OR1I1), mRNA gnl|BL_ORD_ID|13639 gi|268837230|ref|NP_667200.2| olfactory receptor 1496 [Mus musculus] 3071921 3 309 1.50986e-99 771.0
gi|52317161|ref|NM_001004713.1| Homo sapiens olfactory receptor, family 1, subfamily I, member 1 (OR1I1), mRNA gnl|BL_ORD_ID|13345 gi|283837936|ref|NP_666450.2| olfactory receptor 374 [Mus musculus] 310 1 930 1 310 4.18033e-99 768.0
gi|52317161|ref|NM_001004713.1| Homo sapiens olfactory receptor, family 1, subfamily I, member 1 (OR1I1), mRNA gnl|BL_ORD_ID|455 gi|22129035|ref|NP_667150.1| olfactory receptor 354 [Mus musculus] 302 13 918 8 309 1.85488e-98 764.0
gi|52317161|ref|NM_001004713.1| Homo sapiens olfactory receptor, family 1, subfamily I, member 1 (OR1I1), mRNA gnl|BL_ORD_ID|410 gi|22129071|ref|NP_667122.1| olfactory receptor 1377 [Mus musculus] 305 1 915 1 304 3.06622e-97 755.0
gi|52317161|ref|NM_001004713.1| Homo sapiens olfactory receptor, family 1, subfamily I, member 1 (OR1I1), mRNA gnl|BL_ORD_ID|312 gi|53933206|ref|NP_001005569.1| olfactory receptor 366 [Mus musculus] 307 1 921 1 307 2.14345e-96 749.0
gi|52317161|ref|NM_001004713.1| Homo sapiens olfactory receptor, family 1, subfamily I, member 1 (OR1I1), mRNA gnl|BL_ORD_ID|4458 gi|58801284|ref|NP_001011748.1| olfactory receptor 867 [Mus musculus] 3091927 1 309 7.36974e-96 748.0