Skip to content
Snippets Groups Projects
Commit ebf9a72c authored by arq5x's avatar arq5x
Browse files

add a Context for Map tool.

parent a45f98c0
No related branches found
No related tags found
No related merge requests found
/*
* ContextMap.cpp
*
* Created on: Jan 6, 2014
* Author: arq5x
*/
#include "ContextMap.h"
ContextMap::ContextMap()
{
// map requires sorted input
setSortedInput(true);
setLeftJoin(true);
// default to BED score column
setColumn(5);
// default to "sum"
setColumnOperation("sum");
// default to "." as a NULL value
setNullValue('.');
}
ContextMap::~ContextMap()
{
}
bool ContextMap::parseCmdArgs(int argc, char **argv, int skipFirstArgs) {
_argc = argc;
_argv = argv;
_skipFirstArgs = skipFirstArgs;
if (_argc < 2) {
setShowHelp(true);
return false;
}
setProgram(_programNames[argv[0]]);
_argsProcessed.resize(_argc - _skipFirstArgs, false);
for (_i=_skipFirstArgs; _i < argc; _i++) {
if (isUsed(_i - _skipFirstArgs)) {
continue;
}
else if (strcmp(_argv[_i], "-o") == 0) {
if (!handle_o()) return false;
}
else if (strcmp(_argv[_i], "-c") == 0) {
if (!handle_c()) return false;
}
else if (strcmp(_argv[_i], "-null") == 0) {
if (!handle_null()) return false;
}
}
return ContextIntersect::parseCmdArgs(argc, argv, _skipFirstArgs);
}
bool ContextMap::isValidState()
{
if (!cmdArgsValid()) {
return false;
}
ContextIntersect::isValidState();
if (getDatabaseFileType() == FileRecordTypeChecker::BAM_FILE_TYPE) {
//throw Error
cerr << endl << "*****"
<< endl
<< "***** ERROR: BAM database file not currently supported for the map tool."
<< endl;
exit(1);
}
// TODO
// enforce any specific checks for Map.
return ContextIntersect::isValidState();
}
// for map, -c is the column upon which to operate
bool ContextMap::handle_c()
{
if ((_i+1) < _argc) {
setColumn(atoi(_argv[_i + 1]));
markUsed(_i - _skipFirstArgs);
_i++;
markUsed(_i - _skipFirstArgs);
}
return true;
}
// for map, -o is the operation to apply to the column (-c)
bool ContextMap::handle_o()
{
if ((_i+1) < _argc) {
setColumnOperation(_argv[_i + 1]);
markUsed(_i - _skipFirstArgs);
_i++;
markUsed(_i - _skipFirstArgs);
}
return true;
}
// for map, -null is a NULL vakue assigned
// when no overlaps are detected.
bool ContextMap::handle_null()
{
if ((_i+1) < _argc) {
setNullValue(_argv[_i + 1]);
markUsed(_i - _skipFirstArgs);
_i++;
markUsed(_i - _skipFirstArgs);
}
return true;
}
/*
* ContextMap.h
*
* Created on: Jan 7, 2014
* Author: arq5x
*/
#ifndef CONTEXTMAP_H_
#define CONTEXTMAP_H_
#include "ContextIntersect.h"
class ContextMap : public ContextIntersect {
public:
ContextMap();
virtual ~ContextMap();
virtual bool isValidState();
virtual bool parseCmdArgs(int argc, char **argv, int skipFirstArgs);
int getColumn() const { return _column; }
void setColumn(int column) { _column = column; }
const QuickString & getColumnOperation() const { return _columnOperation; }
void setColumnOperation(const QuickString & operation) { _columnOperation = operation; }
const QuickString & getNullValue() const { return _nullValue; }
void setNullValue(const QuickString & nullValue) { _nullValue = nullValue; }
virtual bool hasIntersectMethods() const { return true; }
private:
virtual bool handle_c();
virtual bool handle_o();
virtual bool handle_null();
};
#endif /* CONTEXTMAP_H_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment