奇怪的输出到txt文件?

时间:2018-10-01 16:24:13

标签: python python-2.7

我正在尝试测量特定PDB文件中CA原子之间的距离。输出看起来像在Spyder中一样,但是书面文本文件看起来很奇怪,我不知道如何搜索输出,因为老实说我不知道​​它写的是什么。下面是我的代码:

import sys
import os
from Bio.PDB.PDBParser import PDBParser
import numpy as np
import warnings
def plot(data):    

# import matplotlib # matplotlib.use( 'Agg' ) 
import pylab

fig = pylab.figure()
ax = fig.add_subplot(111)

cax = ax.imshow(data, interpolation='nearest')
ax.set_title('Ca-Ca distance plot')

# Add colorbar, make sure to specify tick locations to match desired ticklabels 
min = np.min(data)
max = np.max(data)
cbar = fig.colorbar(cax, ticks=[min, max])
cbar.set_ticks([min,max])

pylab.show()
# pylab.savefig( 'distmat.png', format='png' ) 

if __name__ == '__main__':


fnam = 'myfile.pdb'
if not os.path.exists(fnam):
    print "file not found"
    raise SystemExit

id = 'myfile'

warnings.simplefilter('ignore')
parser = PDBParser()

s = parser.get_structure(id, fnam)

chains = [c for c in s.get_chains()]

x = []
for r in chains[0]:
    if 'CA' in r.child_dict:
        ca = r.child_dict['CA']
        x.append(ca.get_coord())

coords = np.array(x)
print (coords)
import scipy.spatial
data = scipy.spatial.distance.cdist(coords, coords, 'euclidean')
print data.shape
plot(data)
print(data)
with open('some file.txt', 'w') as f:
    f.write(data)
    f.close()

以下是输出的一部分。这是什么,我该如何解决?谢谢您的帮助!:

    ‹ñ:(tO@m f\⁄l@cÿÖ∂r!@²«1pi"@ß!•=E6'@=∫;oÆ)@cQ¥Ë¢a(@O)[hÉû/@Æ$≠€781@‹∞'å©X1@x±Mjû+@…‘0™û¥)@Ø1”P/@·uùπ„,@SrÆ¡·˙%@-‰Ÿ^>Â*@QCy‘O/@B?˜+@͵øµÇ|'@e∫≤òÌÄ.@ú?1@Õú…È.@«wX˜¥,@´i¥Ç–è+@◊s°(¯%@βø¶·+@¨ÉSίz.@k`rÕ=C(@åܪÆ'@ï¯ÛU’.@kc÷é.@(¢·F£%*@óqÖîMµ0@Xö1Â

Here is before

[Here is after data = scipy.spatial.distance.cdist(coords, coords, 'euclidean')[2]

0 个答案:

没有答案