Esempio n. 1
0
Path
makeRelative(const Path &path_, const Path &root_) {
    Path path = makeAbsolute(path_);
    Path root = makeAbsolute(root_);

    boost::filesystem::path::const_iterator rootIter = root.begin();
    boost::filesystem::path::const_iterator pathIter = path.begin();

    // Skip past common prefix
    while (rootIter!=root.end() && pathIter!=path.end() && *rootIter==*pathIter) {
        ++rootIter;
        ++pathIter;
    }

    // Return value must back out of remaining A components
    Path retval;
    while (rootIter!=root.end()) {
        if (*rootIter++ != ".")
            retval /= "..";
    }

    // Append path components
    while (pathIter!=path.end())
        retval /= *pathIter++;
    return retval;
}
Esempio n. 2
0
/*!
    \overload
    A convenience function. See data(const QString& abs_name). The
    file name is given in \a abs_or_rel_name and the path is in \a
    context.
*/
const QMimeSource* Q3MimeSourceFactory::data(const QString& abs_or_rel_name, const QString& context) const
{
    const QMimeSource* r = data(makeAbsolute(abs_or_rel_name,context));
    if (!r && !d->path.isEmpty())
        r = data(abs_or_rel_name);
    return r;
}
Esempio n. 3
0
void Project::setFileName( const QString &fn, bool doClear )
{
    if ( fn == filename )
	return;

    if ( singleProjectMode() ) {
	QString qsa = QString( getenv( "HOME" ) ) + QString( "/.qsa" );
	if ( !QFile::exists( qsa ) ) {
	    QDir d;
	    d.mkdir( qsa );
	}
	if ( fn == singleProFileName )
	    return;
	singleProFileName = fn;
	static int counter = 0;
	QString str_counter = QString::number( counter++ );
	str_counter = "/.qsa/" + str_counter;
	LanguageInterface *iface = MetaDataBase::languageInterface( language() );
	filename = QString( getenv( "HOME" ) + str_counter + QString( "tmp_" ) +
			    QFileInfo( fn ).baseName() + "/" + QFileInfo( fn ).baseName() + ".pro" );
	removeTempProject();
	if ( iface && iface->supports( LanguageInterface::CompressProject ) ) {
	    filename = iface->uncompressProject( makeAbsolute( singleProFileName ),
						 QString( getenv( "HOME" ) +
							  str_counter + QString( "tmp_" ) +
							  QFileInfo( fn ).baseName() ) );
	    proName = makeAbsolute( singleProFileName );
	}
    } else {
	filename = fn;
	if ( !filename.endsWith( ".pro" ) )
	    filename += ".pro";
	proName = filename;
    }


    if ( proName.contains( '.' ) )
	proName = proName.left( proName.find( '.' ) );

    if ( !doClear )
	return;
    clear();
    if ( QFile::exists( filename ) )
	parse();
}
Esempio n. 4
0
/*!
 Sets the \a filename of the file. The name can have no path, a relative path, or an absolute path.
 If the file was opened before, it will be closed. All changes made to the file will be lost, then.
 */
void KDSaveFile::setFileName( const QString& filename )
{
    const QString fn = makeAbsolute( filename );
    if( fn == d->filename )
        return;
    close();
    delete d->tmpFile;
    d->filename = fn;
}
 bool AbstractFileManager::resolveRelativePath(const String& relativePath, const StringList& rootPaths, String& absolutePath) {
     StringList::const_iterator rootIt, rootEnd;
     for (rootIt = rootPaths.begin(), rootEnd = rootPaths.end(); rootIt != rootEnd; ++rootIt) {
         const String& rootPath = *rootIt;
         absolutePath = makeAbsolute(relativePath, rootPath);
         if (exists(absolutePath))
             return true;
     }
     
     return false;
 }
Esempio n. 6
0
File: File.cpp Progetto: werkt/kwd
int &
class_5d9200::sub_5d9620( int &res, const char *path )
{
  int var_108;
  char FileName[MAX_PATH];
  struct stat st;

  makeAbsolute(var_108, FileName, MAX_PATH, path);
  if( dk2_stat(FileName, &st) == -1 ) return res = -1;
  x10.virt14(FileName);
  if( x10.get08()[x10.get04() - 1] != '\\' &&
      x10.get08()[x10.get04() - 1] != '/' )
    x10.virt24("\\");
  return res = 0;
}
Esempio n. 7
0
	ProgramDescriptor(std::string const & rprogram, std::string const & rcall)
	: program(rprogram)
	{
		assert ( program.size() );
		assert ( program[0] != '/' );

		std::string call = makeAbsolute(rcall);

		if ( ! which(program,path) )
		{
			path = sdirname(call) + "/" + program;

			if ( ! libmaus2::util::GetFileSize::fileExists(path) )
			{
				libmaus2::exception::LibMausException lme;
				lme.getStream() << "call.damapper: unable to find program " << program << std::endl;
				lme.finish();
				throw lme;
			}
		}

		path = makeAbsolute(path);
		dir = dirname(path);
	}
Esempio n. 8
0
/*!
 Creates a new KDSaveFile instance working on \a filename with \a parent.
 */
KDSaveFile::KDSaveFile( const QString& filename, QObject* parent )
    : QIODevice( parent ),
      d( new Private( makeAbsolute( filename ), this ) )
{
}
Esempio n. 9
0
Path& Path::makeAbsolute()
{
	return makeAbsolute(current());
}
Esempio n. 10
0
void Project::loadConnections()
{
#ifndef QT_NO_SQL
    if ( dbFile.isEmpty() || !QFile::exists( makeAbsolute( dbFile ) ) )
	return;

    QFile f( makeAbsolute( dbFile ) );
    if ( f.open( IO_ReadOnly ) ) {
	QDomDocument doc;
	QString errMsg;
	int errLine;
	if ( doc.setContent( &f, &errMsg, &errLine ) ) {
	    QDomElement e;
	    e = doc.firstChild().toElement();

	    /* connections */
	    QDomNodeList connections = e.toElement().elementsByTagName( "connection" );
	    for ( uint i = 0; i <  connections.length(); i++ ) {
		QDomElement connection = connections.item(i).toElement();
		QDomElement connectionName = loadSingleProperty( connection, "name" );
		QDomElement connectionDriver = loadSingleProperty( connection, "driver" );
		QDomElement connectionDatabase = loadSingleProperty( connection,
								     "database" );
		QDomElement connectionUsername = loadSingleProperty( connection,
								     "username" );
		QDomElement connectionHostname = loadSingleProperty( connection,
								     "hostname" );
		QDomElement connectionPort = loadSingleProperty( connection,
								     "port" );

		DatabaseConnection *conn = new DatabaseConnection( this );
		conn->setName( connectionName.firstChild().firstChild().toText().data() );
		conn->setDriver( connectionDriver.firstChild().firstChild().toText().data() );
		conn->setDatabase( connectionDatabase.firstChild().firstChild().toText().data() );
		conn->setUsername( connectionUsername.firstChild().firstChild().toText().data() );
		conn->setHostname( connectionHostname.firstChild().firstChild().toText().data() );
		conn->setPort( QString( connectionPort.firstChild().firstChild().toText().data() ).toInt() );

		/* connection tables */
		QDomNodeList tables = connection.toElement().elementsByTagName( "table" );
		for ( uint j = 0; j <  tables.length(); j++ ) {
		    QDomElement table = tables.item(j).toElement();
		    QDomElement tableName = loadSingleProperty( table, "name" );
		    conn->addTable( tableName.firstChild().firstChild().toText().data() );

		    /* table fields */
		    QStringList fieldList;
		    QDomNodeList fields = table.toElement().elementsByTagName( "field" );
		    for ( uint k = 0; k <  fields.length(); k++ ) {
			QDomElement field = fields.item(k).toElement();
			QDomElement fieldName = loadSingleProperty( field, "name" );
			fieldList.append( fieldName.firstChild().firstChild().toText().data() );
		    }
		    conn->setFields( tableName.firstChild().firstChild().toText().data(),
					 fieldList );
		}

		dbConnections.append( conn );
	    }
	} else {
	    qDebug( QString("Parse error: ") + errMsg + QString(" in line %d"), errLine );
	}
	f.close();
    }
#endif
}
Esempio n. 11
0
void Project::saveConnections()
{
#ifndef QT_NO_SQL
    if ( dbFile.isEmpty() ) {
	QFileInfo fi( fileName() );
	setDatabaseDescription( fi.baseName() + ".db" );
    }

    QFile f( makeAbsolute( dbFile ) );

    if ( dbConnections.isEmpty() ) {
	if ( f.exists() )
	    f.remove();
	setDatabaseDescription( "" );
	modified = TRUE;
	return;
    }

    /* .db xml */
    if ( f.open( IO_WriteOnly | IO_Translate ) ) {
	QTextStream ts( &f );
	ts.setCodec( QTextCodec::codecForName( "UTF-8" ) );
	ts << "<!DOCTYPE DB><DB version=\"1.0\">" << endl;

	/* db connections */
	int indent = 0;
	for ( DatabaseConnection *conn = dbConnections.first(); conn; conn = dbConnections.next() ) {
	    ts << makeIndent( indent ) << "<connection>" << endl;
	    ++indent;
	    saveSingleProperty( ts, "name", conn->name(), indent );
	    saveSingleProperty( ts, "driver", conn->driver(), indent );
	    saveSingleProperty( ts, "database", conn->database(), indent );
	    saveSingleProperty( ts, "username", conn->username(), indent );
	    saveSingleProperty( ts, "hostname", conn->hostname(), indent );
	    saveSingleProperty( ts, "port", QString::number( conn->port() ), indent );

	    /* connection tables */
	    QStringList tables = conn->tables();
	    for ( QStringList::Iterator it = tables.begin();
		  it != tables.end(); ++it ) {
		ts << makeIndent( indent ) << "<table>" << endl;
		++indent;
		saveSingleProperty( ts, "name", (*it), indent );

		/* tables fields */
		QStringList fields = conn->fields( *it );
		for ( QStringList::Iterator it2 = fields.begin();
		      it2 != fields.end(); ++it2 ) {
		    ts << makeIndent( indent ) << "<field>" << endl;
		    ++indent;
		    saveSingleProperty( ts, "name", (*it2), indent );
		    --indent;
		    ts << makeIndent( indent ) << "</field>" << endl;
		}

		--indent;
		ts << makeIndent( indent ) << "</table>" << endl;
	    }

	    --indent;
	    ts << makeIndent( indent ) << "</connection>" << endl;
	}

	ts << "</DB>" << endl;
	f.close();
    }
#endif
}
Esempio n. 12
0
void Project::save( bool onlyProjectFile )
{
    bool anythingModified = FALSE;

    //  save sources and forms
    if ( !onlyProjectFile ) {

	saveConnections();

	for ( SourceFile *sf = sourcefiles.first(); sf; sf = sourcefiles.next() ) {
	    anythingModified = anythingModified || sf->isModified();
	    if ( !sf->save() )
		return;
	}

	for ( FormFile *ff = formfiles.first(); ff; ff = formfiles.next() ) {
	    anythingModified = anythingModified || ff->isModified();
	    if ( !ff->save() )
		return;
	}
    }

    if ( isDummy() || filename.isEmpty() )
	return;

    if ( !modified ) {
	if ( singleProjectMode() ) {
	    LanguageInterface *iface = MetaDataBase::languageInterface( language() );
	    if ( iface && iface->supports( LanguageInterface::CompressProject ) )
		iface->compressProject( makeAbsolute( filename ), singleProFileName, anythingModified );
	}
 	return;
    }

    QFile f( filename );
    QString original = "";

    // read the existing file
    bool hasPreviousContents = FALSE;
    if ( f.open( IO_ReadOnly ) ) {
	QTextStream ts( &f );
	original = ts.read();
	f.close();
        hasPreviousContents = TRUE;
	remove_contents( original, "{SOURCES+=" ); // ### compatibility with early 3.0 betas
	remove_contents( original, "DBFILE" );
	remove_contents( original, "LANGUAGE" );
	remove_contents( original, "TEMPLATE" );
	removePlatformSettings( original, "CONFIG" );
	removePlatformSettings( original, "DEFINES" );
	removePlatformSettings( original, "LIBS" );
	removePlatformSettings( original, "INCLUDEPATH" );
	removePlatformSettings( original, "SOURCES" );
	removePlatformSettings( original, "HEADERS" );
	remove_multiline_contents( original, "FORMS" );
	remove_multiline_contents( original, "INTERFACES" ); // compatibility
	remove_multiline_contents( original, "IMAGES" );
	for ( QStringList::Iterator it = csList.begin(); it != csList.end(); ++it )
	    remove_contents( original, *it );
    }

    if (!original.isEmpty()) {
	// Removes any new lines at the beginning of the file
	while (original.startsWith("\n"))
	    original.remove(0, 1);
    }

    // the contents of the saved file
    QString contents;

    // template
    contents += "TEMPLATE\t= " + templ + "\n";

    // language
    contents += "LANGUAGE\t= " + lang + "\n";
    contents += "\n";

    // config
    writePlatformSettings( contents, "CONFIG", cfg );
    LanguageInterface *iface = MetaDataBase::languageInterface( lang );
    if ( iface ) {
	QStringList sourceKeys;
	iface->sourceProjectKeys( sourceKeys );
	for ( QStringList::Iterator spit = sourceKeys.begin(); spit != sourceKeys.end(); ++spit )
	    remove_multiline_contents( contents, *spit );
    }

    // libs, defines, includes
    writePlatformSettings( contents, "LIBS", lbs );
    writePlatformSettings( contents, "DEFINES", defs );
    writePlatformSettings( contents, "INCLUDEPATH", inclPath );
    writePlatformSettings( contents, "SOURCES", sources );
    writePlatformSettings( contents, "HEADERS", headers );

    // unix
    if ( !hasPreviousContents ) {
 	contents +=
 	    "unix|os2 {\n"
 	    "  UI_DIR = .ui\n"
 	    "  MOC_DIR = .moc\n"
 	    "  OBJECTS_DIR = .obj\n"
 	    "}\n\n";
    }

    // sources
    if ( !sourcefiles.isEmpty() && iface ) {
	QMap<QString, QStringList> sourceToKey;
	for ( SourceFile *f = sourcefiles.first(); f; f = sourcefiles.next() ) {
	    QString key = iface->projectKeyForExtension( QFileInfo( f->fileName() ).extension() );
	    QStringList lst = sourceToKey[ key ];
	    lst << makeRelative( f->fileName() );
	    sourceToKey.replace( key, lst );
	}

	for ( QMap<QString, QStringList>::Iterator skit = sourceToKey.begin();
	      skit != sourceToKey.end(); ++skit ) {
	    QString part = skit.key() + "\t+= ";
	    QStringList lst = *skit;
	    for ( QStringList::Iterator sit = lst.begin(); sit != lst.end(); ++sit ) {
		part += *sit;
		part += ++sit != lst.end() ? " \\\n\t" : "";
		--sit;
	    }
	    part += "\n\n";
	    contents += part;
	}
    }

    // forms and interfaces
    if ( !formfiles.isEmpty() ) {
	contents += "FORMS\t= ";
	for ( QPtrListIterator<FormFile> fit = formfiles; fit.current(); ++fit ) {
	    contents += fit.current()->fileName() +
		 (fit != formfiles.last() ? " \\\n\t" : "");
	}
	contents += "\n\n";
    }

    // images
     if ( !pixCollection->isEmpty() ) {
	contents += "IMAGES\t= ";
	QValueList<PixmapCollection::Pixmap> pixmaps = pixCollection->pixmaps();
	for ( QValueList<PixmapCollection::Pixmap>::Iterator it = pixmaps.begin();
	      it != pixmaps.end(); ++it ) {
		  contents += makeRelative( (*it).absname );
		  contents += ++it != pixmaps.end() ? " \\\n\t" : "";
		  --it;
	}
	contents += "\n\n";
    }

    // database
    if ( !dbFile.isEmpty() )
	contents += "DBFILE\t= " + dbFile + "\n";

    // custom settings
    for ( QStringList::Iterator it = csList.begin(); it != csList.end(); ++it ) {
	QString val = *customSettings.find( *it );
	if ( !val.isEmpty() )
	    contents += *it + "\t= " + val + "\n";
    }

    if ( !f.open( IO_WriteOnly | IO_Translate ) ) {
	QMessageBox::warning( messageBoxParent(),
			      "Save Project Failed", "Couldn't write project file " + filename );
	return;
    }

    QTextStream os( &f );
    os << contents;
    if (hasPreviousContents)
        os << original;

    f.close();

    setModified( FALSE );

    if ( singleProjectMode() ) {
	LanguageInterface *iface = MetaDataBase::languageInterface( language() );
	if ( iface && iface->supports( LanguageInterface::CompressProject ) )
	    iface->compressProject( makeAbsolute( filename ), singleProFileName, TRUE );
    }
}
Esempio n. 13
0
boost::filesystem::path FilePath::makeAbsolute(const boost::filesystem::path &p) {
	UString ustring = p.string();

	return path(makeAbsolute(ustring).c_str());
}
Esempio n. 14
0
static int call_damapper(libmaus2::util::ArgParser const & arg, libmaus2::util::ArgInfo const & arginfo)
{
	unsigned int const damapper_arg_k = arg.uniqueArgPresent("k") ? arg.getUnsignedNumericArg<uint64_t>("k") : 20;
	         int const damapper_arg_t = arg.uniqueArgPresent("t") ? arg.getParsedArg<int>("t") : -1;
	         int const damapper_arg_M = arg.uniqueArgPresent("M") ? arg.getParsedArg<int>("M") : -1;
	double const damapper_arg_e = arg.uniqueArgPresent("e") ? arg.getParsedArg<double>("e") : std::numeric_limits<double>::min();
	         int const damapper_arg_s = arg.uniqueArgPresent("s") ? arg.getParsedArg<int>("s") : -1;
	double const damapper_arg_n = arg.uniqueArgPresent("n") ? arg.getParsedArg<double>("n") : std::numeric_limits<double>::min();
	         int const damapper_arg_B = arg.uniqueArgPresent("B") ? arg.getParsedArg<int>("B") : -1;
	         int const damapper_arg_T = arg.uniqueArgPresent("T") ? arg.getParsedArg<int>("T") : -1;
	         int const damapper_arg_b = arg.uniqueArgPresent("b") ? 1 :  0; // comp bias
	         int const damapper_arg_v = arg.uniqueArgPresent("v") ? 1 :  0; // verbose
	         int const damapper_arg_p = arg.uniqueArgPresent("p") ? 1 :  0; // repeat profile (not used)

	unsigned int const numthreads = damapper_arg_T < 0 ? 4 : damapper_arg_T;

	unsigned int const refblocksize = arg.uniqueArgPresent("refblocksize") ? arg.getUnsignedNumericArg<uint64_t>("refblocksize") : 250;
	unsigned int const readblocksize = arg.uniqueArgPresent("readblocksize") ? arg.getUnsignedNumericArg<uint64_t>("readblocksize") : 250;

	std::string const argindexdir = arg.uniqueArgPresent("I") ? arg["I"] :  std::string();
	std::string const argworkdir = arg.uniqueArgPresent("W") ? arg["W"] :  std::string();
	std::string const workdir = makeAbsolute(argworkdir.size() ? argworkdir : ".");

	mkdirP(workdir);

	unsigned int const fastacolwidth = 80;
	bool const reformatref = true;
	bool const reformatreads = true;

	std::string progname = arg.progname;
	ProgramDescriptor PD_fasta2DAM("fasta2DAM",progname);
	ProgramDescriptor PD_DBsplit("DBsplit",progname);
	ProgramDescriptor PD_HPC_damapper("HPC.damapper",progname);
	ProgramDescriptor PD_damapper("damapper",progname);
	ProgramDescriptor PD_lascat("lascat",progname);
	ProgramDescriptor PD_laschainsort("laschainsort",progname);
	ProgramDescriptor PD_lastobam("lastobam",progname);
	ProgramDescriptor PD_LAsort("LAsort",progname);
	ProgramDescriptor PD_LAcat("LAcat",progname);
	ProgramDescriptor PD_LAmerge("LAmerge",progname);

	std::vector<std::string> Vpathadd;
	Vpathadd.push_back(PD_LAsort.dir);
	Vpathadd.push_back(PD_LAcat.dir);
	Vpathadd.push_back(PD_LAmerge.dir);
	std::sort(Vpathadd.begin(),Vpathadd.end());
	Vpathadd.resize ( std::unique(Vpathadd.begin(),Vpathadd.end()) - Vpathadd.begin() );

	std::ostringstream npathstr;
	npathstr << getenv("PATH");
	for ( uint64_t i = 0; i < Vpathadd.size(); ++i )
		npathstr << ":" << Vpathadd[i];
	std::string const npath = npathstr.str();
	libmaus2::util::WriteableString Wnpath(npath);
	setenv("PATH",Wnpath.A.begin(),1 /* overwrite */);

	std::string const reffn = arg[0];

	if ( ! libmaus2::util::GetFileSize::fileExists(reffn) )
	{
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: reference file " << reffn << " does not exist" << std::endl;
		lme.finish();
		throw lme;
	}

	static char const * faend[] = { ".fasta",".fa",0 };

	std::string const refdir = sdirname(reffn);
	std::string const indexdir = makeAbsolute(argindexdir.size() ? argindexdir : refdir);
	std::string const reffile = sbasename(reffn);
	std::string const reffileclipped = libmaus2::util::OutputFileNameTools::endClip(reffile,&faend[0]);

	mkdirP(indexdir);

	std::string const refdam = indexdir + "/"  + reffileclipped + ".dam";
	std::string const refidx = indexdir + "/." + reffileclipped + ".idx";
	std::string const refhdr = indexdir + "/." + reffileclipped + ".hdr";
	std::string const refbps = indexdir + "/." + reffileclipped + ".bps";
	std::string const indexfasta = indexdir + "/"  + reffileclipped + ".dam.fasta";

	if (
		! libmaus2::util::GetFileSize::fileExists(refdam) || libmaus2::util::GetFileSize::isOlder(refdam,reffn) ||
		! libmaus2::util::GetFileSize::fileExists(refidx) || libmaus2::util::GetFileSize::isOlder(refidx,reffn) ||
		! libmaus2::util::GetFileSize::fileExists(refhdr) || libmaus2::util::GetFileSize::isOlder(refhdr,reffn) ||
		! libmaus2::util::GetFileSize::fileExists(refbps) || libmaus2::util::GetFileSize::isOlder(refbps,reffn) ||
		! libmaus2::util::GetFileSize::fileExists(indexfasta) || libmaus2::util::GetFileSize::isOlder(indexfasta,reffn)
	)
	{
		std::string const tmpbase = arginfo.getDefaultTmpFileName();
		std::string const reffastatmp  = indexdir + "/"  + tmpbase + ".fasta";
		std::string const refdamtmp    = indexdir + "/"  + tmpbase + ".dam";
		std::string const refdamidxtmp = indexdir + "/." + tmpbase + ".idx";
		std::string const refdamhdrtmp = indexdir + "/." + tmpbase + ".hdr";
		std::string const refdambpstmp = indexdir + "/." + tmpbase + ".bps";

		libmaus2::util::TempFileRemovalContainer::addTempFile(refdamtmp);
		libmaus2::util::TempFileRemovalContainer::addTempFile(refdamidxtmp);
		libmaus2::util::TempFileRemovalContainer::addTempFile(refdamhdrtmp);
		libmaus2::util::TempFileRemovalContainer::addTempFile(refdambpstmp);
		libmaus2::util::TempFileRemovalContainer::addTempFile(reffastatmp);

		if ( reformatref )
		{
			libmaus2::fastx::FastAReader FAreader(reffn);
			libmaus2::fastx::FastAReader::pattern_type pat;
			libmaus2::aio::OutputStreamInstance::unique_ptr_type OSI(new libmaus2::aio::OutputStreamInstance(reffastatmp));
			while ( FAreader.getNextPatternUnlocked(pat) )
				pat.printMultiLine(*OSI,fastacolwidth);
			OSI->flush();
			OSI.reset();
		}
		else
		{
			if ( symlink(reffn.c_str(),reffastatmp.c_str()) )
			{
				int const error = errno;

				libmaus2::exception::LibMausException lme;
				lme.getStream() << "call.damapper: symlink(" << reffn << "," << reffastatmp << "): " << strerror(error) << std::endl;
				lme.finish();
				throw lme;
			}
		}

		std::string const fasta2DAMcom = PD_fasta2DAM.path + " " + refdamtmp + " " + reffastatmp;

		int const fasta2DAMcomres = callsystem(fasta2DAMcom.c_str());

		if ( damapper_arg_v )
			std::cerr << "[V] " << fasta2DAMcom << std::endl;

		if ( fasta2DAMcomres != 0 )
		{
			libmaus2::exception::LibMausException lme;
			lme.getStream() << "call.damapper: " << fasta2DAMcom << " failed" << std::endl;
			lme.finish();
			throw lme;
		}

		std::ostringstream splitstr;
		splitstr << PD_DBsplit.path << " -s" << refblocksize << " -x" << damapper_arg_k << " " << refdamtmp;
		std::string const splitcom = splitstr.str();

		int const splitcomres = callsystem(splitcom.c_str());

		if ( damapper_arg_v )
			std::cerr << "[V] " << splitcom << std::endl;

		if ( splitcomres != 0 )
		{
			libmaus2::exception::LibMausException lme;
			lme.getStream() << "call.damapper: " << splitcomres << " failed" << std::endl;
			lme.finish();
			throw lme;
		}

		callrename(refdamtmp,refdam);
		callrename(refdamidxtmp,refidx);
		callrename(refdamhdrtmp,refhdr);
		callrename(refdambpstmp,refbps);
		callrename(reffastatmp,indexfasta);
	}

	std::string const tmpbase = arginfo.getDefaultTmpFileName();
	std::string const readsfastatmp = workdir + "/" + tmpbase + "_reads" + ".fasta";
	std::string const readsdamtmp = workdir + "/" + tmpbase + "_reads" + ".dam";
	std::string const readsidxtmp = workdir + "/." + tmpbase + "_reads" + ".idx";
	std::string const readsbpstmp = workdir + "/." + tmpbase + "_reads" + ".bps";
	std::string const readshdrtmp = workdir + "/." + tmpbase + "_reads" + ".hdr";
	std::string const readsdamtmpscript = workdir + "/" + tmpbase + "_reads" + ".dam.script";
	std::string const readslastmp = workdir + "/" + tmpbase + "_reads" + ".las";

	libmaus2::util::TempFileRemovalContainer::addTempFile(readsfastatmp);
	libmaus2::util::TempFileRemovalContainer::addTempFile(readsdamtmp);
	libmaus2::util::TempFileRemovalContainer::addTempFile(readsidxtmp);
	libmaus2::util::TempFileRemovalContainer::addTempFile(readsbpstmp);
	libmaus2::util::TempFileRemovalContainer::addTempFile(readshdrtmp);
	libmaus2::util::TempFileRemovalContainer::addTempFile(readsdamtmpscript);
	libmaus2::util::TempFileRemovalContainer::addTempFile(readslastmp);

	libmaus2::aio::OutputStreamInstance::unique_ptr_type OSI(new libmaus2::aio::OutputStreamInstance(readsfastatmp));
	if ( reformatreads )
	{
		libmaus2::fastx::StreamFastAReaderWrapper SFAR(std::cin);
		libmaus2::fastx::StreamFastAReaderWrapper::pattern_type pat;
		while ( SFAR.getNextPatternUnlocked(pat) )
			pat.printMultiLine(*OSI,fastacolwidth);

	}
	else
	{
		libmaus2::autoarray::AutoArray<char> A(4096,false);
		while ( std::cin )
		{
			std::cin.read(A.begin(),A.size());
			uint64_t const r = std::cin.gcount();
			OSI->write(A.begin(),r);
		}
	}
	OSI->flush();
	OSI.reset();

	std::string const fasta2DAMcom = PD_fasta2DAM.path + " " + readsdamtmp + " " + readsfastatmp;

	int const fasta2DAMcomres = callsystem(fasta2DAMcom.c_str());

	if ( damapper_arg_v )
		std::cerr << "[V] " << fasta2DAMcom << std::endl;

	if ( fasta2DAMcomres != 0 )
	{
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: " << fasta2DAMcom << " failed" << std::endl;
		lme.finish();
		throw lme;
	}

	std::ostringstream splitstr;
	splitstr << PD_DBsplit.path << " -s" << readblocksize << " -x" << damapper_arg_k << " " << readsdamtmp;
	std::string const splitcom = splitstr.str();

	int const splitcomres = callsystem(splitcom.c_str());

	if ( damapper_arg_v )
		std::cerr << "[V] " << splitcom << std::endl;

	if ( splitcomres != 0 )
	{
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: " << splitcomres << " failed" << std::endl;
		lme.finish();
		throw lme;
	}

	std::string const calldir = getCurrentDir();
	if ( chdir(workdir.c_str()) )
	{
		int const error = errno;
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: chdir(" << workdir << "): " << strerror(error) << std::endl;
		lme.finish();
		throw lme;
	}

	std::ostringstream HPC1str;
	HPC1str << PD_HPC_damapper.path;

	HPC1str << " -k" << damapper_arg_k;
	if ( damapper_arg_t != -1 )
		HPC1str << " -t" << damapper_arg_t;
	if ( damapper_arg_M != -1 )
		HPC1str << " -M" << damapper_arg_M;
	if ( damapper_arg_e != std::numeric_limits<double>::min() )
		HPC1str << " -e" << damapper_arg_e;
	if ( damapper_arg_s != -1 )
		HPC1str << " -s" << damapper_arg_s;
	if ( damapper_arg_n != std::numeric_limits<double>::min() )
		HPC1str << " -n" << damapper_arg_n;
	if ( damapper_arg_B != -1 )
		HPC1str << " -B" << damapper_arg_B;
	HPC1str << " -T" << numthreads;
	if ( damapper_arg_b )
		HPC1str << " -b";
	if ( damapper_arg_v )
		HPC1str << " -v";
	if ( damapper_arg_p )
		HPC1str << " -p";

	HPC1str << " -C -N " << refdam << " " << readsdamtmp << " >" << readsdamtmpscript;
	std::string const HPC1 = HPC1str.str();

	int const HPC1res = system(HPC1.c_str());

	if ( damapper_arg_v )
		std::cerr << "[V] " << HPC1 << std::endl;

	if ( HPC1res != 0 )
	{
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: " << HPC1 << " failed" << std::endl;
		lme.finish();
		throw lme;
	}

	std::vector<std::string> Voutput;
	std::vector<std::string> Vdamapper;
	libmaus2::aio::InputStreamInstance::unique_ptr_type HPCisi(new libmaus2::aio::InputStreamInstance(readsdamtmpscript));
	std::string const exp = "# Catenate jobs (2)";
	std::string const expdamapper = "# Damapper jobs (1)";
	std::string const expsub = "LAsort -a ";
	std::string const expcheck = "# Check all .las files (optional but recommended)";
	std::string const expchecksub = "LAcheck -vS ";

	bool activedamapper = false;
	bool activeoutput = false;
	bool activationfound = false;
	bool activationdamapperfound = false;

	while ( *HPCisi )
	{
		std::string line;
		std::getline(*HPCisi,line);

		// std::cerr << line << std::endl;

		if ( line.size() )
		{
			if ( line[0] == '#' )
			{
				activeoutput = false;
				activedamapper = false;

				if ( line == expcheck )
				{
					activeoutput = true;
					activationfound = true;
				}
				else if ( line == expdamapper )
				{
					activedamapper = true;
					activationdamapperfound = true;
				}
			}
			else if ( activeoutput )
			{
				if (
					line.size() >= expchecksub.size()
					&&
					line.substr(0,expchecksub.size()) == expchecksub
				)
				{
					line = line.substr(expchecksub.size());

					std::vector<std::string> tokens;
					uint64_t l = 0;
					while ( l < line.size() )
					{
						while ( l < line.size() && ::std::isspace(static_cast<unsigned char>(line[l])) )
							++l;

						uint64_t h = l;
						while ( h < line.size() && ! ::std::isspace(static_cast<unsigned char>(line[h])) )
							++h;

						if ( h > l )
						{
							tokens.push_back(line.substr(l,h-l));
							// std::cerr << "token " << tokens.back() << std::endl;
						}

						l = h;
					}

					if ( tokens.size() == 3 )
					{
						Voutput.push_back(tokens[2] + ".las");
					}
					else
					{
						libmaus2::exception::LibMausException lme;
						lme.getStream() << "call.damapper: cannot understand line " << line << std::endl;
						lme.finish();
						throw lme;
					}
				}
				else
				{
					libmaus2::exception::LibMausException lme;
					lme.getStream() << "call.damapper: cannot understand line " << line << std::endl;
					lme.finish();
					throw lme;
				}
			}
			else if ( activedamapper )
			{
				if ( startsWith(line,"damapper ") )
				{
					line = line.substr(std::string("damapper ").size());
					line = PD_damapper.path + " " + line;
					Vdamapper.push_back(line);
				}
				else
				{
					libmaus2::exception::LibMausException lme;
					lme.getStream() << "call.damapper: cannot understand line " << line << std::endl;
					lme.finish();
					throw lme;
				}
			}
		}
	}
	HPCisi.reset();

	if ( ! activationfound )
	{
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: activation line for cat jobs not found" << std::endl;
		lme.finish();
		throw lme;
	}
	if ( ! activationdamapperfound )
	{
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: activation line for damapper not found" << std::endl;
		lme.finish();
		throw lme;
	}

	for ( uint64_t i = 0; i < Voutput.size(); ++i )
		libmaus2::util::TempFileRemovalContainer::addTempFile(Voutput[i]);

	/* call damapper */
	for ( uint64_t i = 0; i < Vdamapper.size(); ++i )
	{
		int const damapperret = callsystem(Vdamapper[i].c_str());

		if ( damapper_arg_v )
			std::cerr << "[V] " << Vdamapper[i] << std::endl;

		if ( damapperret != 0 )
		{
			libmaus2::exception::LibMausException lme;
			lme.getStream() << "call.damapper: damapper call failed" << std::endl;
			lme.finish();
			throw lme;
		}
	}

	/* concatenate all output .las files */
	std::ostringstream catostr;
	catostr << PD_laschainsort.path << " -sba " << readslastmp;
	for ( uint64_t i = 0; i < Voutput.size(); ++i )
	{
		catostr << " " << Voutput[i];
	}
	std::string const catcom = catostr.str();

	if ( damapper_arg_v )
		std::cerr << "[V] " << catcom << std::endl;

	if ( system(catcom.c_str()) != 0 )
	{
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: laschainsort call " << catcom << " failed" << std::endl;
		lme.finish();
		throw lme;
	}

	for ( uint64_t i = 0; i < Voutput.size(); ++i )
		::remove(Voutput[i].c_str());

	/* convert .las file to BAM */
	std::ostringstream lastobamstr;
	lastobamstr << PD_lastobam.path << " -t" << numthreads << " -snone " << refdam << " " << indexfasta << " " << readsdamtmp << " " << readsfastatmp << " " << readslastmp;
	std::string const lastobamcom = lastobamstr.str();

	if ( damapper_arg_v )
		std::cerr << "[V] " << lastobamcom << std::endl;

	if ( system(lastobamcom.c_str()) != 0 )
	{
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: lastobam call " << lastobamcom << " failed" << std::endl;
		lme.finish();
		throw lme;
	}

	if ( chdir(calldir.c_str()) )
	{
		int const error = errno;
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: chdir(" << calldir << "): " << strerror(error) << std::endl;
		lme.finish();
		throw lme;
	}


	return EXIT_SUCCESS;
}