diff --git a/modules/bindings/pymod/clustalw.py b/modules/bindings/pymod/clustalw.py
index 3625ede812497c0ce96f022b849e7ff0de1fd5b2..38678cc7809872d91c79142b5968060134a24dec 100644
--- a/modules/bindings/pymod/clustalw.py
+++ b/modules/bindings/pymod/clustalw.py
@@ -16,7 +16,19 @@ def ClustalW(seq1, seq2, clustalw=None):
out)
ps=subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
ps.stdout.readlines()
- aln=io.LoadAlignment(out)
- temp_dir.Cleanup()
+ taln=io.LoadAlignment(out)
+ aln=seq.CreateAlignment()
+ if (seq1.HasAttachedView() and seq2.HasAttachedView()):
+ seq00=taln.GetSequence(0).Copy()
+ seq00.AttachView(seq1.GetAttachedView().Copy())
+ seq01=taln.GetSequence(1).Copy()
+ seq01.AttachView(seq2.GetAttachedView().Copy())
+ aln.AddSequence(seq00)
+ aln.AddSequence(seq01)
+ else:
+ aln=taln.Copy()
+
+ #~ temp_dir.Cleanup()
+
return aln
-
\ No newline at end of file
+
diff --git a/modules/io/src/io_manager.cc b/modules/io/src/io_manager.cc
index b03169d8c84e49f80a7af74c23cf2780d20928b3..0bde4d10a2e1c05caeb7cd0876b00e9e6dbee501 100644
--- a/modules/io/src/io_manager.cc
+++ b/modules/io/src/io_manager.cc
@@ -22,6 +22,7 @@
#include <ost/io/mol/entity_io_sdf_handler.hh>
#include <ost/io/mol/entity_io_mae_handler.hh>
#include <ost/io/seq/fasta_io_handler.hh>
+#include <ost/io/seq/pir_io_handler.hh>
#include <ost/io/seq/promod_io_handler.hh>
#include <ost/io/mol/surface_io_msms_handler.hh>
#include <ost/io/seq/clustal_io_handler.hh>
@@ -46,6 +47,7 @@ IOManager::IOManager()
RegisterFactory(EntityIOHandlerFactoryBaseP(new EntityIOSDFHandlerFactory));
RegisterFactory(EntityIOHandlerFactoryBaseP(new EntityIOMAEHandlerFactory));
RegisterFactory(SequenceIOHandlerFactoryBasePtr(new FastaIOHandlerFactory));
+ RegisterFactory(SequenceIOHandlerFactoryBasePtr(new PirIOHandlerFactory));
RegisterFactory(SequenceIOHandlerFactoryBasePtr(new ClustalIOHandlerFactory));
RegisterFactory(SequenceIOHandlerFactoryBasePtr(new PromodIOHandlerFactory));
RegisterFactory(SurfaceIOHandlerFactoryBasePtr(new SurfaceIOMSMSHandlerFactory));
@@ -142,9 +144,9 @@ MapIOHandlerPtr IOManager::FindMapImportHandlerFile(const boost::filesystem::pat
}
throw IOUnknownFormatException("Unsupported type in FindMapImportHandle.");
}else{
- String match_suf_string=loc.string();
- std::transform(match_suf_string.begin(),match_suf_string.end(),match_suf_string.begin(),tolower);
- for(MapIOFList::const_iterator it=map_io_list_.begin(); it!=map_io_list_.end();++it) {
+ String match_suf_string=loc.string();
+ std::transform(match_suf_string.begin(),match_suf_string.end(),match_suf_string.begin(),tolower);
+ for(MapIOFList::const_iterator it=map_io_list_.begin(); it!=map_io_list_.end();++it) {
if((*it)->MatchSuffix(match_suf_string)) {
return (*it)->Create();
}
@@ -209,8 +211,8 @@ MapIOHandlerPtr IOManager::FindMapExportHandlerFile(const boost::filesystem::pat
if (pos == String::npos){
throw IOUnknownFormatException("No file suffix given for " + filename+", please indicate file type.");
}
- String match_suf_string=loc.string();
- std::transform(match_suf_string.begin(),match_suf_string.end(),match_suf_string.begin(),tolower);
+ String match_suf_string=loc.string();
+ std::transform(match_suf_string.begin(),match_suf_string.end(),match_suf_string.begin(),tolower);
for(MapIOFList::const_iterator it=map_io_list_.begin(); it!=map_io_list_.end();++it) {
if((*it)->MatchSuffix(match_suf_string)) {
return(*it)->Create();
diff --git a/modules/io/src/seq/CMakeLists.txt b/modules/io/src/seq/CMakeLists.txt
index d588b4e70ccc74938734fe13ad52111d62da3aa3..9dd14b52abbaf97d83967c2660e48e4438dfce76 100644
--- a/modules/io/src/seq/CMakeLists.txt
+++ b/modules/io/src/seq/CMakeLists.txt
@@ -3,6 +3,7 @@ clustal_io_handler.cc
load.cc
save.cc
fasta_io_handler.cc
+pir_io_handler.cc
promod_io_handler.cc
PARENT_SCOPE
)
@@ -10,6 +11,7 @@ PARENT_SCOPE
set(OST_IO_SEQ_HEADERS
sequence_io_handler.hh
fasta_io_handler.hh
+pir_io_handler.hh
promod_io_handler.hh
clustal_io_handler.hh
load.hh
diff --git a/modules/io/src/seq/pir_io_handler.cc b/modules/io/src/seq/pir_io_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..47a9bede8bc32f4fd7ebcd632def22bd43dbcb57
--- /dev/null
+++ b/modules/io/src/seq/pir_io_handler.cc
@@ -0,0 +1,131 @@
+//------------------------------------------------------------------------------
+// This file is part of the OpenStructure project <www.openstructure.org>
+//
+// Copyright (C) 2008-2010 by the OpenStructure authors
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License as published by the Free
+// Software Foundation; either version 3.0 of the License, or (at your option)
+// any later version.
+// This library is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+// details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//------------------------------------------------------------------------------
+#include "pir_io_handler.hh"
+#include <ost/message.hh>
+#include <boost/filesystem/fstream.hpp>
+#include <boost/filesystem/convenience.hpp>
+#include <boost/algorithm/string.hpp>
+#include <boost/format.hpp>
+
+#include <ost/io/io_exception.hh>
+#include <ost/seq/invalid_sequence.hh>
+/*
+ Author: Juergen Haas
+ */
+
+using boost::format;
+
+namespace ost { namespace io {
+
+void PirIOHandler::Import(seq::SequenceList& aln,
+ const boost::filesystem::path& loc)
+{
+ if (!boost::filesystem::exists(loc)) {
+ throw IOException("File does not exist");
+ }
+
+ boost::filesystem::ifstream infile(loc);
+ this->Import(aln, infile);
+}
+
+void PirIOHandler::Export(const seq::ConstSequenceList& msa,
+ const boost::filesystem::path& loc) const {
+ boost::filesystem::ofstream outfile(loc);
+ this->Export(msa, outfile);
+}
+
+
+
+
+bool PirIOHandler::ProvidesImport(const boost::filesystem::path& loc,
+ const String& format) {
+ if (format=="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,".pir")) {
+ return true;
+ }
+ } else if(format=="pir") {
+ return true;
+ }
+ return false;
+}
+
+bool PirIOHandler::ProvidesExport(const boost::filesystem::path& loc,
+ const String& format) {
+ return PirIOHandler::ProvidesImport(loc, format);
+}
+
+void PirIOHandler::Import(seq::SequenceList& aln,
+ std::istream& instream)
+{
+ const char* error_msg="Bad Pir file: Expected '>', but '%1%' found.";
+
+ String line;
+ std::getline(instream, line);
+ int seq_count=0;
+ //not yet supported
+ throw IOException("Import of PIR format is not yet supported!");
+ while (!instream.eof()) {
+ // parse header information. cut after first "|"
+ if (line.find_first_not_of("\n\t ")==String::npos) {
+ std::getline(instream, line);
+ continue;
+ }
+ if (line.length()==0 || line[0]!='>') {
+ String error=str(format(error_msg) % line);
+ throw IOException(error);
+ }
+ String identifier=line.substr(1);
+ String sequence_str;
+ while (std::getline(instream, line) && line.size()>0 && line[0]!='>') {
+ if (line.find_first_not_of("\n\t ")==String::npos) {
+ continue;
+ }
+ sequence_str+=line;
+ }
+ if (sequence_str.length()>0) {
+ try {
+ seq::SequenceHandle seq=seq::CreateSequence(identifier, sequence_str);
+ aln.AddSequence(seq);
+ seq_count+=1;
+ } catch (seq::InvalidSequence& e) {
+ throw e;
+ }
+ } else {
+ throw IOException("Bad Pir file: Sequence is empty.");
+ }
+ }
+ if (seq_count==0) {
+ throw IOException("Bad Pir file: File is empty");
+ }
+
+}
+
+void PirIOHandler::Export(const seq::ConstSequenceList& seqs,
+ std::ostream& ostream) const
+{
+ for (int i=0; i<seqs.GetCount(); ++i) {
+ ostream << ">P1;" << seqs[i].GetName() << std::endl;
+ ostream << "title" << std::endl;
+ ostream << seqs[i].GetString() <<"*" << std::endl;
+ }
+}
+
+}}
diff --git a/modules/io/src/seq/pir_io_handler.hh b/modules/io/src/seq/pir_io_handler.hh
new file mode 100644
index 0000000000000000000000000000000000000000..18058ef022e6569e5138bc493509f8f65856ffdb
--- /dev/null
+++ b/modules/io/src/seq/pir_io_handler.hh
@@ -0,0 +1,56 @@
+//------------------------------------------------------------------------------
+// This file is part of the OpenStructure project <www.openstructure.org>
+//
+// Copyright (C) 2008-2010 by the OpenStructure authors
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License as published by the Free
+// Software Foundation; either version 3.0 of the License, or (at your option)
+// any later version.
+// This library is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+// details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//------------------------------------------------------------------------------
+#ifndef OST_IO_PIR_HANDLER_HH
+#define OST_IO_PIR_HANDLER_HH
+/*
+ Author: Juergen Haas
+ */
+#include <ost/io/module_config.hh>
+#include "sequence_io_handler.hh"
+
+namespace ost { namespace io {
+
+class DLLEXPORT_OST_IO PirIOHandler : public SequenceIOHandler {
+public:
+ virtual void Import(seq::SequenceList& aln,
+ const boost::filesystem::path& loc);
+
+ virtual void Export(const seq::ConstSequenceList& aln,
+ const boost::filesystem::path& loc) const;
+
+ virtual void Import(seq::SequenceList& aln,
+ std::istream& instream);
+
+ virtual void Export(const seq::ConstSequenceList& aln,
+ std::ostream& ostream) const;
+
+ static bool ProvidesImport(const boost::filesystem::path& loc,
+ const String& format="auto");
+ static bool ProvidesExport(const boost::filesystem::path& loc,
+ const String& format="auto");
+ static String GetFormatName() { return String("Pir"); }
+ static String GetFormatDescription() { return String(" Protein Information Resource (PIR) Sequence format"); }
+
+private:
+};
+
+typedef SequenceIOHandlerFactory<PirIOHandler> PirIOHandlerFactory;
+}}
+
+#endif
diff --git a/modules/io/src/seq/save.cc b/modules/io/src/seq/save.cc
index 06ca395f6cf95066340f580f9046b3a8a28565a4..38956b9fe6637e264d3173f9dec244d886a7b01d 100644
--- a/modules/io/src/seq/save.cc
+++ b/modules/io/src/seq/save.cc
@@ -67,7 +67,7 @@ SequenceListToString(const seq::ConstSequenceList& seq_list,
SequenceIOHandlerPtr ali_io=m.FindAlignmentExportHandler("", format);
if (!ali_io) {
- throw IOException("Can't sequences to format '"+format+"'.");
+ throw IOException("Can't export sequences to format '"+format+"'.");
}
std::stringstream sstream;
ali_io->Export(seq_list, sstream);
diff --git a/modules/seq/base/pymod/__init__.py b/modules/seq/base/pymod/__init__.py
index 1a2d44904ac7c6368fabbb0303ebc4d2ce3dd680..6b92feb561d921cbf76caba2939286e5b5ca2c9f 100644
--- a/modules/seq/base/pymod/__init__.py
+++ b/modules/seq/base/pymod/__init__.py
@@ -17,6 +17,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#------------------------------------------------------------------------------
from _seq import *
+from ost import mol
def ViewsFromAlignment(multi_seq_ali, ent_a, ent_b, include_atoms=True):
seq_a=multi_seq_ali.GetSequence(0)
@@ -66,8 +67,8 @@ def ViewsFromSequences(seq_a, seq_b, ent_a=None, ent_b=None,
#~ print seq_ent_a
#~ print s1
- print seq_ent_a
- print s1
+ #~ print seq_ent_a
+ #~ print s1
off_a = seq_ent_a.index(s1)
off_b = seq_ent_b.index(s2)