import gzip#compresses the .bed example file
input_file = open("example.bed","rb")
data = input_file.read()
#convert_data = bytearray(data)
with gzip.open("example.bed.gz", "wb") as filez:
filez.write(data)
filez.close()
#failed attempts
with gzip.open("example.bed.gz", "r+") as fileopen:
output=fileopen.read()
output
print(output)
#this works but not in the desired manner
import pandas as pd
df=pd.read_csv("example.bed.gz", delimiter='\t',header=1 )
df.to_csv('exampleziptotxt.bed', index=False) gzipping之前的格式=‘chr8 8\t 59420123
格式从打开和阅读gzipping=b‘and 8\t 59420123\
我尝试过对utf-8进行解码,结果得到了一个字节冲突。
上面的脚本gzip是一个标签分隔的.bed文件,我想解压缩它,并在gzip之前以完全相同的格式获得原始的.bed文件(例如,只是倒转gzip)。如能就如何做到这一点提出任何建议,将不胜感激。
发布于 2020-09-18 19:41:08
import pandas as pd file
df=pd.read_csv("example.bed.gz", delimiter=',',header=0 )
df.to_csv('exampleziptotxt.bed', index=False) 我只需要将分隔符从"\t“调整为",”,它就会恢复原来的格式
https://stackoverflow.com/questions/63950239
复制相似问题