struct asObject *bigBedAsOrDefault(struct bbiFile *bbi) // Get asObject associated with bigBed - if none exists in file make it up from field counts. { struct asObject *as = bigBedAs(bbi); if (as == NULL) as = asParseText(bedAsDef(bbi->definedFieldCount, bbi->fieldCount)); return as; }
struct asObject *getAsObj(int columnCount) /* If the -as=table.as option was given, parse the autoSql file into an asObject. * Otherwise try to deduce autoSql from type; if no type info, just return NULL. */ { struct asObject *asObj = NULL; if (as != NULL) { asObj = asParseFile(as); if (asObj->next != NULL) errAbort("Can only handle .as files containing a single object."); if (typeBedN > 0) // abort if -type=bedN columns are not standard asCompareObjAgainstStandardBed(asObj, typeBedN, TRUE); } else if (bedDetail) asObj = bedDetailAsObj(); else if (typeBedN > 0) { char *asText = bedAsDef(typeBedN, columnCount); asObj = asParseText(asText); freeMem(asText); } return asObj; }
int main(int argc, char *argv[]) /* Process command line. */ { optionInit(&argc, argv, options); blockSize = optionInt("blockSize", blockSize); itemsPerSlot = optionInt("itemsPerSlot", itemsPerSlot); asFile = optionVal("as", asFile); doCompress = !optionExists("unc"); sizesIs2Bit = optionExists("sizesIs2Bit"); extraIndex = optionVal("extraIndex", NULL); tabSep = optionExists("tab"); udcDir = optionVal("udcDir", udcDefaultDir()); if (argc != 4) usage(); udcSetDefaultDir(udcDir); if (optionExists("type")) { // parse type char *btype = cloneString(optionVal("type", "")); char *plus = strchr(btype, '+'); if (plus) { *plus++ = 0; if (isdigit(*plus)) bedP = sqlUnsigned(plus); } if (!startsWith("bed", btype)) errAbort("type must begin with \"bed\""); btype +=3; bedN = sqlUnsigned(btype); if (bedN < 3) errAbort("Bed must be 3 or higher, found %d\n", bedN); if (bedN > 15) errAbort("Bed must be 15 or lower, found %d\n", bedN); } else { if (asText) errAbort("If you specify the .as file, you must specify the -type as well so that\n" "the number of standard BED columns is known."); } /* If the haven't set bedN and bedP from the type var in the command line, then we sniff it * out from file. */ char *bedFileName = argv[1]; if (bedN == 0) { /* Just read in single line and count fields. */ struct lineFile *lf = lineFileOpen(bedFileName, TRUE); char *line; if (!lineFileNextReal(lf, &line)) errAbort("%s is empty", lf->fileName); int fieldCount; if (tabSep) fieldCount = chopByChar(line, '\t', NULL, 0); // Do not use chopString, see GOTCHA else fieldCount = chopByWhite(line, NULL, 0); if (fieldCount > 256) errAbort("Too many columns in %s, you sure it's a bed file?", lf->fileName); lineFileClose(&lf); /* Set up so that it looks like we are straight up bed for that many fields, * or if more than or maximum defined fields, then for bed15+ */ bedN = fieldCount; if (bedN > bedKnownFields) { bedP = bedN - bedKnownFields; bedN = bedKnownFields; } } /* Make sure that fields are defined, from bed spec if nowhere else. */ if (asFile) readInGulp(asFile, &asText, NULL); else asText = bedAsDef(bedN, bedN + bedP); bedToBigBed(bedFileName, argv[2], argv[3]); optionFree(); if (verboseLevel() > 1) printVmPeak(); return 0; }