Skip to content
Snippets Groups Projects
Verified Commit 425e394d authored by Xavier Robin's avatar Xavier Robin
Browse files

feat: SCHWED-5481 read gzipped SDF

parent 8c83d3e7
No related branches found
Tags 1.8.0
No related merge requests found
......@@ -54,5 +54,5 @@ SDF - Structured Data File
Chemical-data file format.
*Recognized File Extensions*
.sdf
.sdf, .sdf.gz
......@@ -69,7 +69,7 @@ bool sdf_handler_is_responsible_for(const boost::filesystem::path& loc,
if(type=="auto") {
String match_suf_string=loc.string();
std::transform(match_suf_string.begin(),match_suf_string.end(),match_suf_string.begin(),tolower);
if(detail::FilenameEndsWith(match_suf_string,".sdf")) {
if(detail::FilenameEndsWith(match_suf_string,".sdf") || detail::FilenameEndsWith(match_suf_string,".sdf.gz")) {
return true;
}
......
......@@ -21,7 +21,9 @@
*/
#include <boost/algorithm/string.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/format.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/lexical_cast.hpp>
#include <ost/mol/bond_handle.hh>
#include <ost/conop/conop.hh>
......@@ -58,7 +60,7 @@ void SDFReader::Import(mol::EntityHandle& ent)
{
String line;
mol::XCSEditor editor=ent.EditXCS(mol::BUFFERED_EDIT);
while (std::getline(instream_,line)) {
while (std::getline(in_,line)) {
++line_num;
// std::getline removes EOL character but may leave a DOS CR (\r) in Unix
......@@ -87,7 +89,7 @@ void SDFReader::Import(mol::EntityHandle& ent)
throw IOException(str(format(msg) % line_num));
}
String data_value="";
while(std::getline(instream_,line) && !boost::iequals(line, "")) {
while(std::getline(in_,line) && !boost::iequals(line, "")) {
data_value.append(line);
}
curr_chain_.SetStringProp(data_header, data_value);
......@@ -103,6 +105,10 @@ void SDFReader::Import(mol::EntityHandle& ent)
void SDFReader::ClearState(const boost::filesystem::path& loc)
{
if (boost::iequals(".gz", boost::filesystem::extension(loc))) {
in_.push(boost::iostreams::gzip_decompressor());
}
in_.push(instream_);
if(!infile_) throw IOException("could not open "+loc.string());
curr_chain_=mol::ChainHandle();
curr_residue_=mol::ResidueHandle();
......
......@@ -22,6 +22,7 @@
#ifndef OST_IO_SDF_READER_HH
#define OST_IO_SDF_READER_HH
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/filesystem/fstream.hpp>
#include <ost/mol/chain_handle.hh>
#include <ost/mol/residue_handle.hh>
......@@ -61,6 +62,7 @@ private:
int line_num;
boost::filesystem::ifstream infile_;
std::istream& instream_;
boost::iostreams::filtering_stream<boost::iostreams::input> in_;
};
}}
......
......@@ -2,6 +2,7 @@ set(OST_IO_UNIT_TESTS
test_io_pdb.py
test_io_mmcif.py
test_io_omf.py
test_io_sdf.py
test_clustal.cc
test_io_pdb.cc
test_io_crd.cc
......
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment