Exemplo n.º 1
0
static void
mapinit(char *mapfile)
{
	int nf;
	char *ln;
	char *fields[2];
	Biobuf *bp;
	Map *map;

	if (mapfile == nil)
		return;
	bp = Bopen(mapfile, OREAD);
	if (bp == nil)
		sysfatal("can't read %s", mapfile);
	devmap = nil;
	while ((ln = Brdline(bp, '\n')) != nil) {
		ln[Blinelen(bp)-1] = '\0';
		if (*ln == '\0' || *ln == '#')
			continue;
		nf = tokenize(ln, fields, nelem(fields));
		if (nf != 2)
			continue;
		if(testconfig(fields[0]) != 0) {
			print("bad `from' device %s in %s\n",
				fields[0], mapfile);
			continue;
		}
		map = malloc(sizeof *map);
		map->from = strdup(fields[0]);
		map->to =   strdup(fields[1]);
		map->fdev = iconfig(fields[0]);
		map->tdev = nil;
		if (access(map->to, AEXIST) < 0) {
			/*
			 * map->to isn't an existing file, so it had better be
			 * a config string for a device.
			 */
			if(testconfig(fields[1]) == 0)
				map->tdev = iconfig(fields[1]);
		}
		/* else map->to is the replacement file name */
		map->next = devmap;
		devmap = map;
	}
	Bterm(bp);
}
Exemplo n.º 2
0
int CVecScreenApp::Run(void)
{
    int status = BLAST_EXIT_SUCCESS;

    try {

        // Allow the fasta reader to complain on invalid sequence input
        SetDiagPostLevel(eDiag_Warning);

        const bool kIsProtein(false);
        /*** Process the command line arguments ***/
        const CArgs& args = GetArgs();
        const string kDbName(args[kArgDb].AsString());
        CRef<CBlastOptionsHandle> opts_hndl(CBlastOptionsFactory::Create(eVecScreen));

        /*** Initialize the scope ***/
        SDataLoaderConfig dlconfig(kDbName, kIsProtein);
        dlconfig.OptimizeForWholeLargeSequenceRetrieval();
        CBlastInputSourceConfig iconfig(dlconfig);
        iconfig.SetQueryLocalIdMode();
        CRef<CScope> scope = CBlastScopeSource(dlconfig).NewScope();

        /*** Initialize the input stream ***/
        CBlastFastaInputSource fasta(args[kArgQuery].AsInputFile(), iconfig);
        CBlastInput input(&fasta, 1);

        /*** Get the formatting options ***/
        const CVecscreenRun::CFormatter::TOutputFormat kFmt = 
            args[kArgOutputFormat].AsInteger();
        const bool kHtmlOutput = !args["text_output"].AsBoolean();
        
        /*** Process the input ***/
        while ( !input.End() ) {

            CRef<CBlastQueryVector> query_batch(input.GetNextSeqBatch(*scope));
            _ASSERT(query_batch->Size() == 1);
            CRef<IQueryFactory> queries(new CObjMgr_QueryFactory(*query_batch));
            CVecscreenRun vs(CRef<CSeq_loc>(const_cast<CSeq_loc*>(&*query_batch->GetQuerySeqLoc(0))),
                             query_batch->GetScope(0), kDbName);
            CVecscreenRun::CFormatter vs_format(vs, *scope, kFmt, kHtmlOutput);
            vs_format.FormatResults(args[kArgOutput].AsOutputFile(), opts_hndl);
        }

    } CATCH_ALL(status)
    return status;
}
Exemplo n.º 3
0
void
arginit(void)
{
	int verb;
	char *line;
	char word[Maxword+1], *cp;
	Filsys *fs;

	if(nvrcheck() == 0) {
		setconfig(conf.confdev);
		if (!conf.configfirst)
			return;
	}

	/* nvr was bad or invoker requested configuration step */
	setconfig(conf.confdev);
	for (;;) {
		print("config: ");
		if ((line = Brdline(&bin, '\n')) == nil)
			return;
		line[Blinelen(&bin)-1] = '\0';

		cp = getwrd(word, line);
		if (word[0] == '\0' || word[0] == '#')
			continue;
		if(strcmp(word, "end") == 0)
			return;
		if(strcmp(word, "halt") == 0)
			exit();
		if(strcmp(word, "queryjuke") == 0) {
			getwrd(word, cp);
			if(testconfig(word) == 0)
				querychanger(iconfig(word));
			continue;
		}

		if(strcmp(word, "allow") == 0) {
			wstatallow = 1;
			writeallow = 1;
			continue;
		}
		if(strcmp(word, "copyworm") == 0) {
			copyworm = 1;
			continue;
		}
		if(strcmp(word, "copydev") == 0) {
			cp = getwrd(word, cp);
			if(testconfig(word))
				continue;
			src = strdup(word);
			getwrd(word, cp);
			if(testconfig(word))
				continue;
			dest = strdup(word);
			copydev = 1;
			continue;
		}
		if(strcmp(word, "noauth") == 0) {
			noauth = !noauth;
			continue;
		}
		if(strcmp(word, "noattach") == 0) {
			noattach = !noattach;
			continue;
		}
		if(strcmp(word, "readonly") == 0) {
			readonly = 1;
			continue;
		}

		if(strcmp(word, "ream") == 0) {
			verb = FREAM;
			goto gfsname;
		}
		if(strcmp(word, "recover") == 0) {
			verb = FRECOVER;
			goto gfsname;
		}
		if(strcmp(word, "filsys") == 0) {
			verb = FEDIT;
			goto gfsname;
		}

		if(strcmp(word, "nvram") == 0) {
			getwrd(word, cp);
			if(testconfig(word))
				continue;
			/* if it fails, it will complain */
			nvrsetconfig(word);
			continue;
		}
		if(strcmp(word, "config") == 0) {
			getwrd(word, cp);
			if(!testconfig(word) && nvrsetconfig(word) == 0)
				f.newconf = 1;
			continue;
		}
		if(strcmp(word, "service") == 0) {
			getwrd(word, cp);
			strncpy(service, word, sizeof service);
			f.modconf = 1;
			continue;
		}
		if (strcmp(word, "resetparams") == 0) {
			resetparams++;
			continue;
		}

		/*
		 * continue to parse obsolete keywords so that old
		 * configurations can still work.
		 */
		if (strcmp(word, "ipauth") != 0 &&
		    astrcmp(word, "ip") != 0 &&
		    astrcmp(word, "ipgw") != 0 &&
		    astrcmp(word, "ipmask") != 0 &&
		    astrcmp(word, "ipsntp") != 0) {
			print("unknown config command\n");
			print("\ttype end to get out\n");
			continue;
		}

		getwrd(word, cp);
		f.modconf = 1;
		continue;

	gfsname:
		cp = getwrd(word, cp);
		for(fs=filsys; fs->name; fs++)
			if(strcmp(word, fs->name) == 0)
				break;
		if (fs->name == nil) {
			memset(fs, 0, sizeof *fs);
			fs->name = strdup(word);
		}
		switch(verb) {
		case FREAM:
			if(strcmp(fs->name, "main") == 0)
				wstatallow = 1;	/* only set, never reset */
			/* fallthrough */
		case FRECOVER:
			fs->flags |= verb;
			break;
		case FEDIT:
			f.modconf = 1;
			getwrd(word, cp);
			fs->flags |= verb;
			if(word[0] == 0)
				fs->conf = nil;
			else if(!testconfig(word))
				fs->conf = strdup(word);
			break;
		}
	}
}
Exemplo n.º 4
0
/* copy device from src to dest */
static int
dodevcopy(void)
{
	Device *from, *to;
	Iobuf *p;
	Off a;
	Devsize lim, tosize;

	/*
	 * convert config strings into Devices.
	 */
	from = iconfig(src);
	if(f.error || from == nil) {
		print("bad src device %s\n", src);
		return -1;
	}
	to = iconfig(dest);
	if(f.error || to == nil) {
		print("bad dest device %s\n", dest);
		return -1;
	}

	/*
	 * initialise devices, size them, more sanity checking.
	 */

	devinit(from);
	lim = devsize(from);
	if(lim == 0)
		panic("no blocks to copy on %Z", from);
	devinit(to);
	tosize = devsize(to);
	if(tosize == 0)
		panic("no blocks to copy on %Z", to);

	/* use smaller of the device sizes */
	if (tosize < lim)
		lim = tosize;

	print("copy %Z to %Z in 8 seconds\n", from, to);
	delay(8000);
	if (userabort("preparing to copy"))
		return -1;
	print("copying dev: %lld blocks from %Z to %Z\n", (Wideoff)lim,
		from, to);

	/*
	 * Copy all blocks, a block at a time.
	 */

	for (a = 0; a < lim; a++) {
		if (userabort("copy"))
			break;
		p = getbuf(from, a, Brd);
		/*
		 * if from is a real WORM device, we'll get errors trying to
		 * read unwritten blocks, but the unwritten blocks need not
		 * be contiguous.
		 */
		if (p == 0) {
			print("%lld not written yet; can't read\n", (Wideoff)a);
			continue;
		}
		if (to != 0 && devwrite(to, p->addr, p->iobuf) != 0) {
			print("out block %lld: write error; bailing",
				(Wideoff)a);
			break;
		}
		putbuf(p);
		if(a % 20000 == 0)
			print("block %lld %T\n", (Wideoff)a, time(nil));
	}

	/*
	 * wrap up: sync target
	 */
	print("copied %lld blocks from %Z to %Z\n", (Wideoff)a, from, to);
	sync("devcopy");
	return 0;
}
Exemplo n.º 5
0
void
sysinit(void)
{
	int error;
	char *cp, *ep;
	Device *d;
	Filsys *fs;
	Fspar *fsp;
	Iobuf *p;

	cons.chan = fs_chaninit(Devcon, 1, 0);

start:
	/*
	 * part 1 -- read the config file
	 */
	devnone = iconfig("n");

	cp = nvrgetconfig();
	print("config %s\n", cp);

	confdev = d = iconfig(cp);
	devinit(d);
	if(f.newconf) {
		p = getbuf(d, 0, Bmod);
		memset(p->iobuf, 0, RBUFSIZE);
		settag(p, Tconfig, 0);
	} else
		p = getbuf(d, 0, Brd|Bmod);
	if(!p || checktag(p, Tconfig, 0))
		panic("config io");

	mergeconf(p);

	if (resetparams) {
		for (fsp = fspar; fsp->name != nil; fsp++)
			fsp->declared = 0;
		resetparams = 0;
	}

	for (fsp = fspar; fsp->name != nil; fsp++) {
		/* supply defaults from this cwfs instance */
		if (fsp->declared == 0) {
			fsp->declared = fsp->actual;
			f.modconf = 1;
		}
		/* warn if declared value is not our compiled-in value */
		if (fsp->declared != fsp->actual)
			print("warning: config %s %ld != compiled-in %ld\n",
				fsp->name, fsp->declared, fsp->actual);
	}

	if(f.modconf) {
		memset(p->iobuf, 0, BUFSIZE);
		p->flags |= Bmod|Bimm;
		cp = p->iobuf;
		ep = p->iobuf + RBUFSIZE - 1;
		if(service[0])
			cp = seprint(cp, ep, "service %s\n", service);
		for(fs=filsys; fs->name; fs++)
			if(fs->conf && fs->conf[0] != '\0')
				cp = seprint(cp, ep, "filsys %s %s\n", fs->name,
					fs->conf);

		for (fsp = fspar; fsp->name != nil; fsp++)
			cp = seprint(cp, ep, "%s %ld\n",
				fsp->name, fsp->declared);

		putbuf(p);
		f.modconf = f.newconf = 0;
		print("config block written\n");
		goto start;
	}
	putbuf(p);

	print("service    %s\n", service);

loop:
	/*
	 * part 2 -- squeeze out the deleted filesystems
	 */
	for(fs=filsys; fs->name; fs++)
		if(fs->conf == nil || fs->conf[0] == '\0') {
			for(; fs->name; fs++)
				*fs = *(fs+1);
			goto loop;
		}
	if(filsys[0].name == nil)
		panic("no filsys");

	/*
	 * part 3 -- compile the device expression
	 */
	error = 0;
	for(fs=filsys; fs->name; fs++) {
		print("filsys %s %s\n", fs->name, fs->conf);
		fs->dev = iconfig(fs->conf);
		if(f.error) {
			error = 1;
			continue;
		}
	}
	if(error)
		panic("fs config");

	/*
	 * part 4 -- initialize the devices
	 */
	for(fs=filsys; fs->name; fs++) {
		delay(3000);
		print("sysinit: %s\n", fs->name);
		if(fs->flags & FREAM)
			devream(fs->dev, 1);
		if(fs->flags & FRECOVER)
			devrecover(fs->dev);
		devinit(fs->dev);
	}

	/*
	 * part 5 -- optionally copy devices or worms
	 */
	if (copyworm) {
		dowormcopy();		/* can return if user quits early */
		panic("copyworm bailed out!");
	}
	if (copydev)
		if (dodevcopy() < 0)
			panic("copydev failed!");
		else
			panic("copydev done.");
}
Exemplo n.º 6
0
int
testconfig(char *s)
{
	iconfig(s);
	return f.error;
}
Exemplo n.º 7
0
int CBlastDemoApplication::Run(void)
{
    // Get arguments
    const CArgs& args = GetArgs();

    EProgram program = ProgramNameToEnum(args["program"].AsString());

    bool db_is_aa = (program == eBlastp || program == eBlastx ||
                     program == eRPSBlast || program == eRPSTblastn);

    CRef<CBlastOptionsHandle> opts(CBlastOptionsFactory::Create(program, CBlastOptions::eRemote));

    ProcessCommandLineArgs(opts);

    opts->Validate();  // Can throw CBlastException::eInvalidOptions for invalid option.

    // This will dump the options to stderr.
    // opts->GetOptions().DebugDumpText(cerr, "opts", 1);

    CRef<CObjectManager> objmgr = CObjectManager::GetInstance();
    if (!objmgr) {
         throw std::runtime_error("Could not initialize object manager");
    }

    const bool is_protein = 
        !!Blast_QueryIsProtein(opts->GetOptions().GetProgramType());
    SDataLoaderConfig dlconfig(is_protein);
    CBlastInputSourceConfig iconfig(dlconfig, objects::eNa_strand_other, false, 
                              args["parse"].AsBoolean());
    CBlastFastaInputSource fasta_input(args["in"].AsInputFile(), iconfig);
    CScope scope(*objmgr);

    CBlastInput blast_input(&fasta_input);

    TSeqLocVector query_loc = blast_input.GetAllSeqLocs(scope);

    CRef<IQueryFactory> query_factory(new CObjMgr_QueryFactory(query_loc));

    const CSearchDatabase target_db(args["db"].AsString(),
        db_is_aa ? CSearchDatabase::eBlastDbIsProtein : CSearchDatabase::eBlastDbIsNucleotide);

    CRemoteBlast blaster(query_factory, opts, target_db);

// This will dump a lot of stuff to stderr.
//    blaster.SetVerbose();

    bool status = blaster.SubmitSync();

    if (status == false)
         throw std::runtime_error("No results returned by SubmitSync");

    cerr << "RID: " << blaster.GetRID() << '\n';

    CSearchResultSet results = *blaster.GetResultSet();

    CNcbiOstream& out = args["out"].AsOutputFile();

    for (unsigned int i = 0; i < results.GetNumResults(); i++) {
         CConstRef<CSeq_align_set> sas = results[i].GetSeqAlign();
         out << MSerial_AsnText << *sas;
    }

    return 0;
}