How To Convert Pdb.Gz To Pdb Directly In In Java
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..
• 4,073 views
•
link
2 answers
You can use GZIPInputStream to read gzipped files in Java.
More info here: http://www.javamex.com/tutorials/compression/gzip.shtml
• 1 views
•
link
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);
}
• 1 views
•
link
Log in to answer this question.