Something went wrong on our end
-
Studer Gabriel authored
The reason are potentially huge fasta files for which debugging is super hard when you're just told: something is wrong...
Studer Gabriel authoredThe reason are potentially huge fasta files for which debugging is super hard when you're just told: something is wrong...
fasta_io_handler.cc 4.43 KiB
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2020 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 "fasta_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: Marco Biasini
*/
using boost::format;
namespace ost { namespace io {
void FastaIOHandler::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 FastaIOHandler::Export(const seq::ConstSequenceList& msa,
const boost::filesystem::path& loc) const {
boost::filesystem::ofstream outfile(loc);
this->Export(msa, outfile);
}
bool FastaIOHandler::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,".fasta") || detail::FilenameEndsWith(match_suf_string,".fa") ||
detail::FilenameEndsWith(match_suf_string,".fna") || detail::FilenameEndsWith(match_suf_string,".fsa") ||
detail::FilenameEndsWith(match_suf_string,".fas") ) {
return true;
}
} else if(format=="fasta") {
return true;
}
return false;
}