Skip to content
Snippets Groups Projects
Commit d9795535 authored by juergen's avatar juergen
Browse files

adding prelim export to PIR format

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2153 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 9c96f24a
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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();
......
......@@ -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
......
//------------------------------------------------------------------------------
// 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;
}
}
}}
//------------------------------------------------------------------------------
// 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
......@@ -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);
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment