How To Convert Pdb.Gz To Pdb Directly In In Java
2
1
Entering edit mode
11.9 years ago
import java.util.Map; 
import javax.swing.text.Position; 
import org.biojava.bio.structure.*; 
import org.biojava.bio.structure.io.PDBFileReader; 
public class PDBFile {
    public PDBFile()     {
         Parser parserObj = new Parser();     String PDBID = parserObj.passPDBID();
      {     
         PDBFileReader pdbreader = new PDBFileReader();
         pdbreader.setAlignSeqRes(true);
         pdbreader.setAutoFetch(true);

     try{
        Structure struc = pdbreader.getStructureById(PDBID);
         }  catch (Exception e)    {
  e.printStackTrace();
}   }  } }

This code directly downloads a pdb file from the protein data bank, but the file obtained is in pdb.gz , in a zip file. how do i extract the pdb file using java or biojava? is there any method that would directly download the pdb file alone and not in pdb.gz format? please help..

biojava java pdb • 3.5k views
ADD COMMENT
1
Entering edit mode
11.9 years ago
Nikolay Vyahhi ★ 1.3k

You can use GZIPInputStream to read gzipped files in Java.

More info here: http://www.javamex.com/tutorials/compression/gzip.shtml

ADD COMMENT
0
Entering edit mode
11.9 years ago
Reyhaneh ▴ 530

I use C# and I do the same thing. You need to download the files and then unzip them. the code i use in c# is:

void DecompressFiles(string pdbCode, string chain)
         {
            //location of where zip pdb files are saved.
             var file = Path.Combine(Program.current_pdbFilesLocation, pdbCode + ".gz");
             using (FileStream fInStream = new FileStream(file, FileMode.Open, FileAccess.Read))
             {
                 using (GZipStream zipStream = new GZipStream(fInStream, CompressionMode.Decompress))
                 {
                     var newname = file.Replace(".gz", "-"+chain.ToUpper()+".pdb");

                     using (FileStream fOutStream = new FileStream(newname, FileMode.Create, FileAccess.Write))
                     {
                         byte[] tempBytes = new byte[4096];
                         int i;
                         while ((i = zipStream.Read(tempBytes, 0, tempBytes.Length)) != 0)
                         {
                             fOutStream.Write(tempBytes, 0, i);
                         }
                     }
                 }
             }
             // delete the zip file
             File.Delete(file);
         }
ADD COMMENT

Login before adding your answer.

Traffic: 1564 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6