struct dnaSeq *dnaLoadSingle(char *fileName, int *retStart, int *retEnd, int *retParentSize) /* Return sequence if it's a nib file or 2bit part, NULL otherwise. */ { struct dnaSeq *seq = NULL; unsigned start = 0, end = 0; int parentSize = 0; if (nibIsFile(fileName)) { /* Save offset out of fileName for auto-lifting */ char filePath[PATH_LEN]; char name[PATH_LEN]; nibParseName(0, fileName, filePath, name, &start, &end); if (end != 0) /* It's just a range. */ { FILE *f; int size; nibOpenVerify(filePath, &f, &size); parentSize = size; } seq = nibLoadAllMasked(NIB_MASK_MIXED, fileName); if (end == 0) parentSize = end = seq->size; freez(&seq->name); seq->name = cloneString(name); } else if (twoBitIsRange(fileName)) { /* Save offset out of fileName for auto-lifting */ char *rangeSpec = cloneString(fileName); int start, end; char *file, *seqName; twoBitParseRange(rangeSpec, &file, &seqName, &start, &end); /* Load sequence. */ { struct twoBitFile *tbf = twoBitOpen(file); parentSize = twoBitSeqSize(tbf, seqName); seq = twoBitReadSeqFrag(tbf, seqName, start, end); twoBitClose(&tbf); } if (end == 0) end = seq->size; freez(&rangeSpec); } if (retStart != NULL) *retStart = start; if (retEnd != NULL) *retEnd = end; if (retParentSize != NULL) *retParentSize = parentSize; return seq; }
void twoBitInfo(char *inName, char *outName) /* twoBitInfo - get information about sequences in a .2bit file. */ { struct twoBitFile *tbf; FILE *outFile; char *seqName = NULL; twoBitParseRange(inName, &inName, &seqName, NULL, NULL); tbf = twoBitOpen(inName); outFile = mustOpen(outName, "w"); if (seqName != NULL) { char *seqArray[1023]; int i; int seqCount = chopString(seqName, ",", seqArray, ArraySize(seqArray)); for (i = 0 ; i < seqCount ; i++) { if (optionExists("maskBed")) twoBitOutMaskBeds(tbf, seqArray[i], outFile); else if (optionExists("nBed")) twoBitOutNBeds(tbf, seqArray[i], outFile); else if(optionExists("noNs")) fprintf(outFile, "%s\t%d\n", seqArray[i], twoBitSeqSizeNoNs(tbf, seqArray[i])); else fprintf(outFile, "%s\t%d\n", seqArray[i], twoBitSeqSize(tbf, seqArray[i])); } } else { struct twoBitIndex *index; for (index = tbf->indexList; index != NULL; index = index->next) { if (optionExists("maskBed")) twoBitOutMaskBeds(tbf, index->name, outFile); else if (optionExists("nBed")) twoBitOutNBeds(tbf, index->name, outFile); else if(optionExists("noNs")) fprintf(outFile, "%s\t%d\n", index->name, twoBitSeqSizeNoNs(tbf, index->name)); else fprintf(outFile, "%s\t%d\n", index->name, twoBitSeqSize(tbf, index->name)); } } twoBitClose(&tbf); carefulClose(&outFile); }