title: How to recover a gzipped .bed file in its original format
body: <pre><code>   import gzip#compresses the .bed example file
     input_file = open(&quot;example.bed&quot;,&quot;rb&quot;)
     data = input_file.read()
     #convert_data = bytearray(data)
     with gzip.open(&quot;example.bed.gz&quot;, &quot;wb&quot;) as filez:
          filez.write(data)
     filez.close()
  
     #failed attempts
     with gzip.open(&quot;example.bed.gz&quot;, &quot;r+&quot;) as fileopen:
     output=fileopen.read()
     output
     print(output)
     
     #this works but not in the desired manner
     import pandas as pd
     df=pd.read_csv(&quot;example.bed.gz&quot;, delimiter='\t',header=1 )
     df.to_csv('exampleziptotxt.bed', index=False) 
                                           
  </code></pre>
  <p>format before gzipping='chr8\t59420123<br />
  format from opening and reading gzipping=b'chr8\t59420123\</p>
  <p>I have tried decoding to utf-8 only to get a bytes conflict</p>
  <p>The above script gzips a tab delimited .bed file, I would like to unzip it and get the original .bed file in the exact same format prior to gzipping (e.g. just reversing the gzipping). Any advice on how to accomplish this would be appreciated.</p>