Esempio n. 1
0
static void fillInMissingLabels(struct sqlConnection *conn,
	struct column *colList, struct searchResult *srList)
/* Fill in missing columns by looking up name and description
 * if possible. */
{
struct column *nameColumn = findNamedColumn("name");
struct column *desColumn = findNamedColumn("description");
struct searchResult *sr;

for (sr = srList; sr != NULL; sr = sr->next)
    {
    if (sr->shortLabel == NULL)
        {
	if (nameColumn != NULL)
	    sr->shortLabel = nameColumn->cellVal(nameColumn, &sr->gp, conn);
	if (sr->shortLabel == NULL)
	    sr->shortLabel = cloneString(sr->gp.name);
	}
    if (sr->longLabel == NULL)
        {
	if (desColumn != NULL)
	    sr->longLabel = desColumn->cellVal(desColumn, &sr->gp, conn);
	else
	    sr->longLabel = cloneString("");
	}
    }
}
Esempio n. 2
0
	int check_expression()
	{
		if (! orderByAsc.empty()) {
			int colIndex = findNamedColumn(orderByAsc);
			if (colIndex == -1) {
				std:: cerr << "error: unknown column name '" << orderByAsc << "'" << std:: endl;
				return 1;
			}
		}
		else if (! orderByDesc.empty()) {
			int colIndex = findNamedColumn(orderByDesc);
			if (colIndex == -1) {
				std:: cerr << "error: unknown column name '" << orderByDesc << "'" << std:: endl;
				return 1;
			}
		}
		else {
			conditionsForColumn.resize(columnNames.size());
			for (size_t i = 0; i < conditions.size(); ++i) {
				const Condition &cond = conditions[i];
				int colIndex = findNamedColumn(cond.col);
				if (colIndex == -1) {
					std:: cerr << "error: unknown column name '" << cond.col << "'" << std:: endl;
					return 1;
				}
				conditionsForColumn[colIndex].push_back(std:: pair<Condition, int>(cond, -1));
			}
		}

		return 0;
	}
Esempio n. 3
0
void doAdvFilterListCol(struct sqlConnection *conn, struct column *colList,
	char *colName)
/* List a column for genes matching advanced filter. */
{
struct genePos *gp, *list = NULL, *newList = NULL, *gpNext = NULL;
struct column *col = findNamedColumn(colName);
makeTitle("Current Filters", NULL);

if (col == NULL)
    {
    warn("No name column");
    internalErr();
    }
hPrintf("<TT><PRE>");
if (gotAdvFilter())
    {
    list = advFilterResults(colList, conn);
    }
else
    {
    hPrintf("#No filters activated. List contains all genes.\n");
    list = knownPosAll(conn);
    }

/* Now lookup names and sort. */
for (gp = list; gp != NULL; gp = gpNext)
    {
    char *oldName = gp->name;
    gp->name = col->cellVal(col, gp, conn);
    gpNext = gp->next;
    if (gp->name == NULL)
	{
	warn("Unable to find cellVal for %s -- tables out of sync?",
		 oldName);
	}
    else
	{
	slAddHead(&newList,gp);
	}
    
    }
list = newList;
slSort(&list, genePosCmpName);

/* Display. */
for (gp = list; gp != NULL; gp = gp->next)
    {
    hPrintf("%s\n", gp->name);
    }
hPrintf("</PRE></TT>");
}
Esempio n. 4
0
struct column *colButtonPressed(struct column *colList, char *prefix)
/* See if a button named prefix.column is pressed for some
 * column, and if so return the column, else NULL. */
{
static char pattern[64];
char colName[64];
char *match;
safef(pattern, sizeof(pattern), "%s*", prefix);
match = cartFindFirstLike(cart, pattern);
if (match == NULL)
    return NULL;

/* Construct column name.  If variable is from an file upload
 * there __filename suffix attached that we need to remove. */
safef(colName, sizeof(colName), "%s", match + strlen(prefix));
if (endsWith(colName, "__filename"))
    {
    int newLen = strlen(colName) - strlen("__filename");
    colName[newLen] = 0;
    }
return findNamedColumn(colName);
}
Esempio n. 5
0
	int main_i(const std::vector<std::string> &argv)
	{
		int argc = argv.size();
		if (argc == 1 || (argc == 2 && argv[1] == "-h")) {
			std:: cout << "Picosel ver. 1.5 (C) 2009-2010 AIST" "\n"
				"Usage 1: picosel OPTION from inputfile select column where EXPRESSION" "\n"
				"Usage 2: picosel OPTION from inputfile select column order by column" "\n"
				"Option" "\n"
				"  -o outputfile: specify output file." "\n";
			return 0;
		}

		if (argc == 3 && argv[1] == "--text") {
			return convert_binary_file_to_text(argv[2]);
		}

		int r = analyze_commandline(argv);
		if (r != 0) {
			return r;
		}

		std:: ifstream input;
		input.open(fromFile.c_str(), std:: ios::in | std:: ios::binary);
		if (! input.is_open()) {
			std:: cerr << "error: can not open file '" << fromFile << "'" << std:: endl;
			return 1;
		}
		std:: istream *pInput = &input;

		r = get_column_names(pInput);
		if (r != 0) {
			return r;
		}
		
		int selectColIndex = findNamedColumn(selectCol);
		if (selectColIndex == -1) {
			std:: cerr << "error: unknown column name '" << selectCol << "'" << std:: endl;
			return 1;
		}

		r = check_expression();
		if (r != 0) {
			return r;
		}

		std:: ostream *pOutput = &std:: cout;
		std:: ofstream output;
		if (! outputFile.empty()) {
			output.open(outputFile.c_str(), binaryOutputFactor != 0 ? (std:: ios::out | std:: ios::binary) : std:: ios::out);
			if (! output.is_open()) {
				std:: cerr << "error: can not create file '" << outputFile << "'" << std:: endl;
				return 1;
			}
			pOutput = &output;
		}

		if (! orderByAsc.empty()) {
			int orderColIndex = findNamedColumn(orderByAsc);
			if (orderColIndex == -1) {
				std:: cerr << "error: unknown column name '" << orderByAsc << "'" << std:: endl;
				return 1;
			}
			r = do_sorting(pInput, pOutput, selectColIndex, orderColIndex, 1/* asc */, outputFile);
		}
		else if (! orderByDesc.empty()) {
			int orderColIndex = findNamedColumn(orderByDesc);
			if (orderColIndex == -1) {
				std:: cerr << "error: unknown column name '" << orderByDesc << "'" << std:: endl;
				return 1;
			}
			r = do_sorting(pInput, pOutput, selectColIndex, orderColIndex, -1/* desc */, outputFile);
		}
		else {
			r = do_selecting(pInput, pOutput, selectColIndex);
		}

		output.close();
		input.close();

		return r;
	}