diff --git a/modules/io/doc/structure_formats.rst b/modules/io/doc/structure_formats.rst index a8013384224ac6a359db2a5d95a4b2fa32aa7c45..42aca88269d1c5ed6c5d6f2ba940aa43c3c597bb 100644 --- a/modules/io/doc/structure_formats.rst +++ b/modules/io/doc/structure_formats.rst @@ -54,5 +54,5 @@ SDF - Structured Data File Chemical-data file format. *Recognized File Extensions* - .sdf + .sdf, .sdf.gz diff --git a/modules/io/src/mol/entity_io_sdf_handler.cc b/modules/io/src/mol/entity_io_sdf_handler.cc index a9dced835da7097a7a0804f979f4a24ab818fd15..a843d986c1ee676ef6c0265d24036a189ba970c1 100644 --- a/modules/io/src/mol/entity_io_sdf_handler.cc +++ b/modules/io/src/mol/entity_io_sdf_handler.cc @@ -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; } diff --git a/modules/io/src/mol/sdf_reader.cc b/modules/io/src/mol/sdf_reader.cc index 064c14f2958d5e8a245b37debc0e7903265cfc30..7f3a7f56030b7c3584bfd8b9f52c16bc0a90f4e0 100644 --- a/modules/io/src/mol/sdf_reader.cc +++ b/modules/io/src/mol/sdf_reader.cc @@ -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(); diff --git a/modules/io/src/mol/sdf_reader.hh b/modules/io/src/mol/sdf_reader.hh index e7a478b7a295e0c60c0957a171fd8c0633544591..04d05a2d6d2f2f9fd54c76b775f3224f22f71a8c 100644 --- a/modules/io/src/mol/sdf_reader.hh +++ b/modules/io/src/mol/sdf_reader.hh @@ -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_; }; }} diff --git a/modules/io/tests/CMakeLists.txt b/modules/io/tests/CMakeLists.txt index 0af1dfd5b2e4f11b4b77830a80793f0ecca13e27..fbfef7413858ee6fdf249e801ca721f10aeb500d 100644 --- a/modules/io/tests/CMakeLists.txt +++ b/modules/io/tests/CMakeLists.txt @@ -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 diff --git a/modules/io/tests/testfiles/sdf/6d5w_rank1_crlf.sdf.gz b/modules/io/tests/testfiles/sdf/6d5w_rank1_crlf.sdf.gz new file mode 100644 index 0000000000000000000000000000000000000000..658c3b9f089ef67229a54e18c766302083b22b16 Binary files /dev/null and b/modules/io/tests/testfiles/sdf/6d5w_rank1_crlf.sdf.gz differ