Example #1
0
void bamMethods(struct track *track)
/* Methods for BAM alignment files. */
{
knetUdcInstall();

boolean isBamWig = cartUsualBooleanClosestToHome(cart, track->tdb, FALSE,
			 BAMWIG_MODE, (trackDbSettingClosestToHome(track->tdb, BAMWIG_MODE) != NULL)); 
if (isBamWig)
    {
    bamWigMethods(track, track->tdb, 0, NULL);
    return;
    }

track->canPack = TRUE;
boolean isPaired = cartUsualBooleanClosestToHome(cart, track->tdb, FALSE,
			 BAM_PAIR_ENDS_BY_NAME,
			 (trackDbSettingClosestToHome(track->tdb, BAM_PAIR_ENDS_BY_NAME) != NULL));
char *tdbShowNames = trackDbSetting(track->tdb, BAM_SHOW_NAMES);
boolean showNames = cartUsualBooleanClosestToHome(cart, track->tdb, FALSE,
						  BAM_SHOW_NAMES, SETTING_IS_ON(tdbShowNames));
char *colorMode = cartOrTdbString(cart, track->tdb, BAM_COLOR_MODE, BAM_COLOR_MODE_DEFAULT);
char *userTag = cartOrTdbString(cart, track->tdb, BAM_COLOR_TAG, BAM_COLOR_TAG_DEFAULT);
if (sameString(colorMode, BAM_COLOR_MODE_TAG) && userTag != NULL)
    {
    if (! (isalpha(userTag[0]) && isalnum(userTag[1]) && userTag[2] == '\0'))
	{
	warn("%s: BAM tag '%s' is not valid -- must be a letter followed by a letter or number.",
	     track->tdb->shortLabel, htmlEncode(userTag));
	cartRemoveVariableClosestToHome(cart, track->tdb, FALSE, BAM_COLOR_TAG);
	}
    }
addBamBaseAndIndelSettings(track->tdb);

if (isPaired)
    {
    linkedFeaturesSeriesMethods(track);
    track->loadItems = bamPairedLoadItems;
    track->drawItems = bamLinkedFeaturesSeriesDraw;
    track->drawItemAt = bamPairedDrawAt;
    }
else
    {
    linkedFeaturesMethods(track);
    track->loadItems = bamLoadItems;
    track->drawItems = bamLinkedFeaturesDraw;
    track->drawItemAt = bamDrawAt;
    }
if (!showNames)
    {
    track->drawName = TRUE; // ironic, but this is how to suppress item labels in pack mode.
    track->drawLeftLabels = maybeDrawLeftLabels;
    }

track->nextItemButtonable = track->nextExonButtonable = FALSE;
track->nextPrevItem = NULL;
track->nextPrevExon = NULL;
if (sameString(colorMode, BAM_COLOR_MODE_GRAY))
    track->colorShades = shadesOfGray;
}
Example #2
0
void doVcfTabixDetails(struct trackDb *tdb, char *item)
/* Show details of an alignment from a VCF file compressed and indexed by tabix. */
{
knetUdcInstall();
if (udcCacheTimeout() < 300)
    udcSetCacheTimeout(300);
struct sqlConnection *conn = hAllocConnTrack(database, tdb);
char *fileOrUrl = bbiNameFromSettingOrTableChrom(tdb, conn, tdb->table, seqName);
hFreeConn(&conn);
doVcfDetailsCore(tdb, fileOrUrl, TRUE);
}
Example #3
0
void vcfTabixMethods(struct track *track)
/* Methods for VCF + tabix files. */
{
knetUdcInstall();
pgSnpMethods(track);
track->mapItem = indelTweakMapItem;
// Disinherit next/prev flag and methods since we don't support next/prev:
track->nextExonButtonable = FALSE;
track->nextPrevExon = NULL;
track->nextPrevItem = NULL;
track->loadItems = vcfTabixLoadItems;
track->canPack = TRUE;
}
Example #4
0
int main(int argc, char *argv[])
/* Process command line. */
{
optionInit(&argc, argv, options);

if (argc != 2 && !optionExists("settings"))
    usage();

struct trackHubCheckOptions *checkOptions = NULL;
AllocVar(checkOptions);

checkOptions->specHost = (optionExists("test") ? "genome-test.soe.ucsc.edu" : "genome.ucsc.edu");
checkOptions->specHost = optionVal("specHost", checkOptions->specHost);

checkOptions->printMeta = optionExists("printMeta");
checkOptions->checkFiles = !optionExists("noTracks");
checkOptions->checkSettings = optionExists("checkSettings");

struct trackHubSettingSpec *setting = NULL;
AllocVar(setting);
setting->level = optionVal("level", "all");
if (trackHubSettingLevel(setting) < 0)
    {
    fprintf(stderr, "ERROR: Unrecognized support level %s\n\n", setting->level);
    usage();
    }
checkOptions->level = setting->level;

char *version = NULL;
if (optionExists("version"))
    version = optionVal("version", NULL);
checkOptions->version = version;

char *extraFile = optionVal("extra", NULL);
if (extraFile != NULL)
    addExtras(extraFile, checkOptions);

cacheTime = optionInt("cacheTime", cacheTime);
udcSetCacheTimeout(cacheTime);
// UDC cache dir: first check for hg.conf setting, then override with command line option if given.
setUdcCacheDir();
udcSetDefaultDir(optionVal("udcDir", udcDefaultDir()));

knetUdcInstall();  // make the htslib library use udc

if (optionExists("settings"))
    {
    showSettings(checkOptions);
    return 0;
    }

struct dyString *errors = newDyString(1024);
if (trackHubCheck(argv[1], checkOptions, errors))
    {
    // uniquify and count errors
    struct slName *errs = slNameListFromString(errors->string, '\n');
    slUniqify(&errs, slNameCmp, slNameFree);
    int errCount = slCount(errs);
    printf("Found %d problem%s:\n", errCount, errCount == 1 ? "" : "s");
    printf("%s\n", slNameListToString(errs, '\n'));
    return 1;
    }
return 0;
}
Example #5
0
void doBamDetails(struct trackDb *tdb, char *item)
/* Show details of an alignment from a BAM file. */
{
if (item == NULL)
    errAbort("doBamDetails: NULL item name");
int start = cartInt(cart, "o");
if (!tdb || !trackDbSetting(tdb, "bamSkipPrintQualScore"))
   skipQualityScore = FALSE;
else
   skipQualityScore = TRUE;
// TODO: libify tdb settings table_pairEndsByName, stripPrefix and pairSearchRange

knetUdcInstall();
if (udcCacheTimeout() < 300)
    udcSetCacheTimeout(300);

if (sameString(item, "zoom in"))
    printf("Zoom in to a region with fewer items to enable 'detail page' links for individual items.<BR>");

char varName[1024];
safef(varName, sizeof(varName), "%s_pairEndsByName", tdb->track);
boolean isPaired = cartUsualBoolean(cart, varName,
				    (trackDbSetting(tdb, "pairEndsByName") != NULL));
char position[512];
safef(position, sizeof(position), "%s:%d-%d", seqName, winStart, winEnd);
struct hash *pairHash = isPaired ? hashNew(0) : NULL;
struct bamTrackData btd = {start, item, pairHash};
char *fileName = hReplaceGbdb(trackDbSetting(tdb, "bigDataUrl"));
if (fileName == NULL)
    {
    if (isCustomTrack(tdb->table))
	{
	errAbort("bamLoadItemsCore: can't find bigDataUrl for custom track %s", tdb->track);
	}
    else
	{
	struct sqlConnection *conn = hAllocConnTrack(database, tdb);
	fileName = hReplaceGbdb(bamFileNameFromTable(conn, tdb->table, seqName));
	hFreeConn(&conn);
	}
    }

char *indexName = hReplaceGbdb(trackDbSetting(tdb, "bigDataIndex"));
char *cacheDir =  cfgOption("cramRef");
char *refUrl = trackDbSetting(tdb, "refUrl");
bamAndIndexFetchPlus(fileName, indexName, position, oneBam, &btd, NULL, refUrl, cacheDir);
if (isPaired)
    {
    char *setting = trackDbSettingOrDefault(tdb, "pairSearchRange", "20000");
    int pairSearchRange = atoi(setting);
    if (pairSearchRange > 0 && hashNumEntries(pairHash) > 0)
	{
	// Repeat the search for item in a larger window:
	struct hash *newPairHash = hashNew(0);
	btd.pairHash = newPairHash;
	safef(position, sizeof(position), "%s:%d-%d", seqName,
	      max(0, winStart-pairSearchRange), winEnd+pairSearchRange);
	bamFetch(fileName, position, oneBam, &btd, NULL);
	}
    struct hashEl *hel;
    struct hashCookie cookie = hashFirst(btd.pairHash);
    while ((hel = hashNext(&cookie)) != NULL)
	{
	bam1_t *bam = hel->val;
	const bam1_core_t *core = &bam->core;
	if (! (core->flag & BAM_FMUNMAP))
	    printf("<B>Note: </B>unable to find paired end for %s "
		   "within +-%d bases of viewing window %s<BR>\n",
		   item, pairSearchRange, addCommasToPos(database, cartString(cart, "position")));
	else
	    printf("<B>Paired read name:</B> %s<BR>\n", item);
	singleBamDetails(bam);
	}
    }
}
Example #6
0
int main(int argc, char *argv[])
{
optionInit(&argc, argv, optionSpecs);
if (argc < 2 || argc > 3)
    usage();
pushCarefulMemHandler(LIMIT_2or6GB);
char *db = argv[1];
char *test = NULL;
boolean doAllTests = (argc == 2);
if (!doAllTests)
    {
    if (sameString(argv[2], pgSnpDbToTabOut) ||
	sameString(argv[2], pgSnpKgDbToTabOutShort) ||
	sameString(argv[2], pgSnpKgDbToTabOutLong) ||
	sameString(argv[2], pgSnpKgDbToGpFx) ||
	sameString(argv[2], snpConsDbToTabOutShort) ||
	sameString(argv[2], snpConsDbToTabOutLong) ||
	sameString(argv[2], vcfEx1) ||
	sameString(argv[2], vcfEx2) ||
	sameString(argv[2], bigBedToTabOut) ||
	sameString(argv[2], snpBigWigToTabOut) ||
	sameString(argv[2], vepOut) ||
	sameString(argv[2], gpFx))
	test = cloneString(argv[2]);
    else
	{
	warn("Unrecognized test name '%s'\n", argv[2]);
	usage();
	}
    }

if (udcCacheTimeout() < 300)
    udcSetCacheTimeout(300);
udcSetDefaultDir("./udcCache");

struct annoAssembly *assembly = getAnnoAssembly(db);

// First test: some rows of a pgSnp table
struct streamerInfo pgSnpInfo = { NULL, assembly, db, "pgNA12878", arWords, pgSnpAsObj() };
if (doAllTests || sameString(test, pgSnpDbToTabOut))
    dbToTabOut(&pgSnpInfo, "stdout", "chr1", 705881, 752721, FALSE);

// Second test: some rows of a pgSnp table integrated with knownGene
struct streamerInfo kgInfo = { NULL, assembly, db, "knownGene", arWords,
			       asParseFile("../knownGene.as") };
pgSnpInfo.next = &kgInfo;
if (doAllTests || sameString(test, pgSnpKgDbToTabOutShort))
    dbToTabOut(&pgSnpInfo, "stdout", "chr1", 705881, 752721, FALSE);

// Third test: all rows of a pgSnp table integrated with knownGene
if (doAllTests || sameString(test, pgSnpKgDbToTabOutLong))
    dbToTabOut(&pgSnpInfo, "stdout", NULL, 0, 0, FALSE);

// Fourth test: some rows of snp135 integrated with phyloP scores
if (doAllTests || sameString(test, snpConsDbToTabOutShort) ||
    sameString(test, snpConsDbToTabOutLong))
    {
    struct streamerInfo snp135Info = { NULL, assembly, db, "snp135", arWords,
				       asParseFile("../snp132Ext.as") };
    struct streamerInfo phyloPInfo = { NULL, assembly, db, "phyloP46wayPlacental", arWig, NULL };
    snp135Info.next = &phyloPInfo;
    if (sameString(test, snpConsDbToTabOutShort))
	dbToTabOut(&snp135Info, "stdout", "chr1", 737224, 738475, FALSE);
    else
	dbToTabOut(&snp135Info, "stdout", NULL, 0, 0, FALSE);
    }

// Fifth test: VCF with genotypes
if (doAllTests || sameString(test, vcfEx1))
    {
#if (defined USE_TABIX && defined KNETFILE_HOOKS)
    knetUdcInstall();
#endif//def USE_TABIX && KNETFILE_HOOKS
    struct streamerInfo vcfEx1 = { NULL, assembly, NULL,
			   "http://genome.ucsc.edu/goldenPath/help/examples/vcfExample.vcf.gz",
				   arWords, vcfAsObj() };
    dbToTabOut(&vcfEx1, "stdout", NULL, 0, 0, FALSE);
    }

if (doAllTests || sameString(test, vcfEx2))
    {
    struct streamerInfo vcfEx2 = { NULL, assembly, NULL,
			   "http://genome.ucsc.edu/goldenPath/help/examples/vcfExampleTwo.vcf",
				   arWords, vcfAsObj() };
    dbToTabOut(&vcfEx2, "stdout", NULL, 0, 0, FALSE);
    }

if (doAllTests || sameString(test, pgSnpKgDbToGpFx))
    {
    struct streamerInfo pg2SnpInfo = { NULL, assembly, NULL,
				       "input/annoGrator/pgForTestingGpFx.pgSnp.tab",
				       arWords, pgSnpAsObj() };
    pg2SnpInfo.next = &kgInfo;

    dbToTabOut(&pg2SnpInfo, "stdout", NULL, 0, 0, TRUE);

    /*
    FIXME
    // 3base insertion CDS - chr3:124,646,699-124,646,718
    dbToTabOut(&pg2SnpInfo, "stdout", "chr3",124646699,124646718, TRUE);
    */
    }

if (doAllTests || sameString(test, bigBedToTabOut))
    {
    struct streamerInfo bigBedInfo = { NULL, assembly, NULL,
			   "http://genome.ucsc.edu/goldenPath/help/examples/bigBedExample.bb",
				       arWords, NULL };
    dbToTabOut(&bigBedInfo, "stdout", "chr21", 34716800, 34733700, FALSE);
    }

if (doAllTests || sameString(test, snpBigWigToTabOut))
    {
    struct streamerInfo snp135Info = { NULL, assembly, db, "snp135", arWords,
				       asParseFile("../snp132Ext.as") };
    struct streamerInfo bigWigInfo = { NULL, assembly, NULL,
			   "http://genome.ucsc.edu/goldenPath/help/examples/bigWigExample.bw",
				       arWig, NULL };
    snp135Info.next = &bigWigInfo;
    dbToTabOut(&snp135Info, "stdout", "chr21", 34716800, 34733700, FALSE);
    }

if (doAllTests || sameString(test, vepOut))
    {
    struct streamerInfo vepSamplePgSnp = { NULL, assembly, NULL,
					   "input/annoGrator/vepSample.pgSnp.tab",
					   arWords, asParseFile("../pgSnp.as") };
    struct streamerInfo kgInfo = { NULL, assembly, db, "ensGene", arWords,
				   asParseFile("../genePredExt.as") };
    struct streamerInfo snpInfo = { NULL, assembly, db, "snp135", arWords,
				    asParseFile("../snp132Ext.as") };
    vepSamplePgSnp.next = &kgInfo;
    kgInfo.next = &snpInfo;
    // Instead of dbToTabOut, we need to make a VEP config data structure and
    // use it to create an annoFormatVep.
    struct streamerInfo *primaryInfo = &vepSamplePgSnp;
    struct annoStreamer *primary = NULL;
    struct annoGrator *gratorList = NULL;
    sourcesFromInfoList(primaryInfo, TRUE, &primary, &gratorList);
    struct annoStreamer *gpVarSource = (struct annoStreamer *)gratorList;
    struct annoStreamer *snpSource = gpVarSource->next;
    struct annoFormatter *vepOut = annoFormatVepNew("stdout", FALSE, primary, "vepSamplePgSnp",
						    gpVarSource, "UCSC Genes ...",
						    snpSource, "just dbSNP 135");
    struct annoGratorQuery *query = annoGratorQueryNew(assembly, primary, gratorList, vepOut);
    annoGratorQuerySetRegion(query, "chr1", 876900, 886920);
    annoGratorQueryExecute(query);
    annoGratorQuerySetRegion(query, "chr5", 135530, 145535);
    annoGratorQueryExecute(query);
    annoGratorQueryFree(&query);
    }

if (doAllTests || sameString(test, gpFx))
    {
    struct streamerInfo variants = { NULL, assembly, NULL,
					   "input/annoGrator/moreVariants.pgSnp.tab",
					   arWords, asParseFile("../pgSnp.as") };
    struct streamerInfo kgInfo = { NULL, assembly, db, "knownGene", arWords,
				   asParseFile("../knownGene.as") };
    struct streamerInfo snpInfo = { NULL, assembly, db, "snp137", arWords,
				    asParseFile("../snp132Ext.as") };
    struct asObject *dbNsfpSeqChangeAs =
	bigBedAsFromFileName("/gbdb/hg19/dbNsfp/dbNsfpSeqChange.bb");
    struct streamerInfo dbNsfpSeqChange =
	{ NULL, assembly, NULL, "/gbdb/hg19/dbNsfp/dbNsfpSeqChange.bb",
	  arWords, dbNsfpSeqChangeAs };
    struct asObject *dbNsfpSiftAs = bigBedAsFromFileName("/gbdb/hg19/dbNsfp/dbNsfpSift.bb");
    struct streamerInfo dbNsfpSift = { NULL, assembly, NULL, "/gbdb/hg19/dbNsfp/dbNsfpSift.bb",
				       arWords, dbNsfpSiftAs };
    variants.next = &kgInfo;
    kgInfo.next = &snpInfo;
    snpInfo.next = &dbNsfpSeqChange;
    dbNsfpSeqChange.next = &dbNsfpSift;
    // Instead of dbToTabOut, we need to make a VEP config data structure and
    // use it to create an annoFormatVep.
    struct streamerInfo *primaryInfo = &variants;
    struct annoStreamer *primary = NULL;
    struct annoGrator *gratorList = NULL;
    sourcesFromInfoList(primaryInfo, TRUE, &primary, &gratorList);
    struct annoStreamer *gpVarSource = (struct annoStreamer *)gratorList;
    struct annoStreamer *snpSource = gpVarSource->next;
    struct annoStreamer *dbNsfpSource = snpSource->next->next;
    struct annoFormatter *vepOut = annoFormatVepNew("stdout", FALSE, primary, "some more variants",
						    gpVarSource, "UCSC Genes of course",
						    snpSource, "now snp137.");
    annoFormatVepAddExtraItem(vepOut, dbNsfpSource, "SIFT", "SIFT score from dbNSFP", "");
    struct annoGratorQuery *query = annoGratorQueryNew(assembly, primary, gratorList, vepOut);
    annoGratorQuerySetRegion(query, "chr19", 45405960, 45419476);
    annoGratorQueryExecute(query);
    annoGratorQueryFree(&query);
    }

return 0;
}