Exemplo n.º 1
0
static __host__ __device__ Tout _pixDist_CN(Tin &pix1, Tin &pix2)
{
    return Tout(SQR(pix1.x - pix2.x) + SQR(pix1.y - pix2.y) + SQR(pix1.z - pix2.z) + SQR(pix1.w - pix2.w));
}};
Exemplo n.º 2
0
int bamvalidateTemplate(::libmaus2::util::ArgInfo const & arginfo)
{
	libmaus2::timing::RealTimeClock rtc; rtc.start();
	bool const verbose = arginfo.getValue("verbose",getDefaultVerbose());
	bool const basequalhist = arginfo.getValue("basequalhist",getDefaultBaseQualHist());

	libmaus2::bambam::BamAlignmentDecoderWrapper::unique_ptr_type decwrapper(
		libmaus2::bambam::BamMultiAlignmentDecoderFactory::construct(
			arginfo,false // put rank
		)
	);
	::libmaus2::bambam::BamAlignmentDecoder * ppdec = &(decwrapper->getDecoder());
	::libmaus2::bambam::BamAlignmentDecoder & dec = *ppdec;
	::libmaus2::bambam::BamHeader const & header = dec.getHeader();
	::libmaus2::bambam::BamAlignment const & algn = dec.getAlignment();

	// add PG line to header
	std::string const upheadtext = ::libmaus2::bambam::ProgramHeaderLineSet::addProgramLine(
		header.text,
		"bamvalidate", // ID
		"bamvalidate", // PN
		arginfo.commandline, // CL
		::libmaus2::bambam::ProgramHeaderLineSet(header.text).getLastIdInChain(), // PP
		std::string(PACKAGE_VERSION) // VN
	);
	// construct new header
	::libmaus2::bambam::BamHeader uphead(upheadtext);

	/*
	 * start index/md5 callbacks and alignment writer
	 */
	std::string md5filename;
	std::string indexfilename;

	std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > cbs;
	::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Pmd5cb;
	libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Pindex;
	libmaus2::bambam::BamBlockWriterBase::unique_ptr_type Pout;

	if ( passthrough )
	{
		std::string const tmpfilenamebase = arginfo.getValue<std::string>("tmpfile",arginfo.getDefaultTmpFileName());
		std::string const tmpfileindex = tmpfilenamebase + "_index";
		::libmaus2::util::TempFileRemovalContainer::addTempFile(tmpfileindex);

		if ( arginfo.getValue<unsigned int>("md5",getDefaultMD5()) )
		{
			if ( arginfo.hasArg("md5filename") &&  arginfo.getUnparsedValue("md5filename","") != "" )
				md5filename = arginfo.getUnparsedValue("md5filename","");
			else
				std::cerr << "[V] no filename for md5 given, not creating hash" << std::endl;

			if ( md5filename.size() )
			{
				::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Tmd5cb(new ::libmaus2::lz::BgzfDeflateOutputCallbackMD5);
				Pmd5cb = UNIQUE_PTR_MOVE(Tmd5cb);
				cbs.push_back(Pmd5cb.get());
			}
		}
		if ( arginfo.getValue<unsigned int>("index",getDefaultIndex()) )
		{
			if ( arginfo.hasArg("indexfilename") &&  arginfo.getUnparsedValue("indexfilename","") != "" )
				indexfilename = arginfo.getUnparsedValue("indexfilename","");
			else
				std::cerr << "[V] no filename for index given, not creating index" << std::endl;

			if ( indexfilename.size() )
			{
				libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Tindex(new libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex(tmpfileindex));
				Pindex = UNIQUE_PTR_MOVE(Tindex);
				cbs.push_back(Pindex.get());
			}
		}
		std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > * Pcbs = 0;
		if ( cbs.size() )
			Pcbs = &cbs;


		libmaus2::bambam::BamBlockWriterBase::unique_ptr_type Tout (
			libmaus2::bambam::BamBlockWriterBaseFactory::construct(uphead, arginfo, Pcbs)
		);
		Pout = UNIQUE_PTR_MOVE(Tout);
	}

	libmaus2::autoarray::AutoArray<char> lastvalidname(256); // max valid read name is 255 bytes
	uint64_t alsok = 0;

	::libmaus2::autoarray::AutoArray<char> qual;
	libmaus2::autoarray::AutoArray<uint64_t> H(static_cast<uint64_t>(std::numeric_limits<uint8_t>::max())+1);
	std::fill(H.begin(),H.end(),0ull);

	try
	{
		while ( dec.readAlignment() )
		{
			if ( passthrough )
				Pout->writeAlignment(algn);

			if ( basequalhist )
			{
				uint64_t const l = algn.getLseq();
				uint8_t const * Qc = libmaus2::bambam::BamAlignmentDecoderBase::getQual(algn.D.begin());
				uint8_t const * const Qe = Qc + l;

				while ( Qc != Qe )
					H[*(Qc++)]++;
			}

			uint64_t const lname = algn.getLReadName();
			char const * name = algn.getName();
			std::copy(name,name+lname+1,lastvalidname.begin());

			alsok += 1;
		}
	}
	catch(std::exception const & ex)
	{
		std::cerr << "[E] name of last valid alignment was " << lastvalidname.begin() << std::endl;
		std::cerr << "[E] read " << alsok << " valid alignments" << std::endl;
		throw;
	}

	Pout.reset();

	if ( Pmd5cb )
	{
		Pmd5cb->saveDigestAsFile(md5filename);
	}
	if ( Pindex )
	{
		Pindex->flush(std::string(indexfilename));
	}

	if ( verbose )
		std::cerr << "[V] checked " << alsok << " alignments in " << rtc.formatTime(rtc.getElapsedSeconds())
			<< " (" << alsok / rtc.getElapsedSeconds() << " al/s)" << std::endl;

	if ( basequalhist )
	{
		uint64_t const s = std::accumulate(H.begin(),H.end(),0ull);

		uint64_t a = 0;
		uint64_t minq = std::numeric_limits<uint64_t>::max();
		uint64_t maxq = 0;

		for ( uint64_t i = 0; i < H.size(); ++i )
			if ( H[i] )
			{
				minq = std::min(minq,i);
				maxq = std::max(maxq,i);

				a += H[i];

				std::cerr
					<< "[H]\t" << i << "\t";

				if ( ( static_cast<uint64_t>(i+33) < static_cast<uint64_t>(std::numeric_limits<char>::max()) && isprint(i+33)) )
					std::cerr << static_cast<char>(i+33);

				std::cerr << "\t"
					<< H[i] << "\t"
					<< (H[i] / static_cast<double>(s)) << "\t"
					<< (a / static_cast<double>(s))
					<< std::endl;
			}

		if ( s )
		{
			std::cerr << "[H]\tmin\t" << minq << "\t";
			if ( ( static_cast<uint64_t>(minq+33) < static_cast<uint64_t>(std::numeric_limits<char>::max()) && isprint(minq+33)) )
				std::cerr << static_cast<char>(minq+33);
			std::cerr << std::endl;
			std::cerr << "[H]\tmax\t" << maxq << "\t";
			if ( ( static_cast<uint64_t>(maxq+33) < static_cast<uint64_t>(std::numeric_limits<char>::max()) && isprint(maxq+33)) )
				std::cerr << static_cast<char>(maxq+33);
			std::cerr << std::endl;
		}
	}

	return EXIT_SUCCESS;
}
Exemplo n.º 3
0
static __host__ __device__ Tout _pixDist_CN(Tin &pix1, Tin &pix2)
{
    return Tout(SQR(pix1.x - pix2.x));
}};
Exemplo n.º 4
0
/*
 *	mail [ -ehpPqrtw ] [-x debuglevel] [ -f file ] [ -F user(s) ]
 *	mail -T file persons
 *	mail [ -tw ] [ -m messagetype ] persons
 *	rmail [ -tw ] persons
 */
int
main(int argc, char **argv)
{
    register int i;
    char *cptr, *p;
    static char pn[] = "main";
    extern char **environ;
    int env_var_idx, next_slot_idx;
    int tmpfd = -1;

    (void)&argc;
    (void)&argv;
    setlocale(LC_CTYPE, "");
    mb_cur_max = MB_CUR_MAX;
    /* fix here for bug #1086130 - security hole	*/
    /* skip over the LD_* env variable		*/
    env_var_idx = 0;
    next_slot_idx = 0;
    while (environ[env_var_idx] != NULL) {
        environ[next_slot_idx] = environ[env_var_idx];
        if (strncmp(environ[env_var_idx], "LD_", 3)) {
            next_slot_idx++;
        }
        env_var_idx++;
    }
    environ[next_slot_idx] = NULL;

    line = smalloc(linesize = LSIZE);
    *line = '\0';

#ifdef SIGCONT
    {
        struct sigaction nsig;
        nsig.sa_handler = SIG_DFL;
        sigemptyset(&nsig.sa_mask);
        nsig.sa_flags = SA_RESTART;
        sigaction(SIGCONT, &nsig, (struct sigaction *)0);
    }
#endif

    /*
     *	Strip off path name of this command for use in messages
     */
    if ((program = strrchr(argv[0], '/')) != NULL) {
        program++;
    } else {
        program = argv[0];
    }

    /* Close all file descriptors except stdin, stdout & stderr */
    for (i = 3; close(i) == 0; i++);

    /*
     *	Get group id for mail, exit if none exists
     */
    if ((grpptr = getgrnam("mail")) == NULL) {
        errmsg(E_GROUP, "");
        exit(1);
    } else {
        mailgrp = grpptr->gr_gid;
    }

    /*
     *	Save the *id for later use.
     */
    my_uid = getuid();
    my_gid = getgid();
    my_euid = geteuid();
    my_egid = getegid();

    /*
     *	What command (rmail or mail)?
     */
    if (strcmp(program, "rmail") == SAME) {
        ismail = FALSE;
    }

    /*
     *	Parse the command line and adjust argc and argv
     *	to compensate for any options
     */
    i = parse(argc, argv);
    argv += (i - 1);
    argc -= (i - 1);

    /* block a potential security hole */
    if (flgT && (my_euid != 0)) {
        setgid(my_gid);
        Tout(pn, "Setgid unset\n");
    }

    if (debug == 0) {
        /* If not set as an invocation option, check for system-wide */
        /* global flag */
        char *xp = xgetenv("DEBUG");
        if (xp != (char *)NULL) {
            debug = atoi(xp);
            if (debug < 0) {
                /* Keep trace file even if successful */
                keepdbgfile = -1;
                debug = -debug;
            }
        }
    }
    if (debug > 0) {
        strcpy(dbgfname, "/tmp/MLDBGXXXXXX");
        if ((tmpfd = mkstemp(dbgfname)) == -1) {
            fprintf(stderr, "%s: can't open debugging file '%s'\n",
                    program, dbgfname);
            exit(13);
        }
        if ((dbgfp = fdopen(tmpfd, "w")) == (FILE *)NULL) {
            fprintf(stderr, "%s: can't open debugging file '%s'\n",
                    program, dbgfname);
            close(tmpfd);
            exit(13);
        }
        setbuf(dbgfp, NULL);
        fprintf(dbgfp, "main(): debugging level == %d\n", debug);
        fprintf(dbgfp, "main(): trace file ='%s': kept %s\n", dbgfname,
                ((keepdbgfile < 0) ?
                 "on success or failure." : "only on failure."));
    }

    if (!ismail && (goerr > 0 || !i)) {
        Dout(pn, 11, "!ismail, goerr=%d, i=%d\n", goerr, i);
        if (goerr > 0) {
            errmsg(E_SYNTAX, "Usage: rmail [-wt] person(s)");
        }
        if (!i) {
            errmsg(E_SYNTAX, "At least one user must be specified");
        }
        Dout(pn, 11, "exiting!\n");
        done(0);
    }

    umsave = umask(7);
    uname(&utsn);
    if ((p = xgetenv("CLUSTER")) != (char *)NULL) {
        /*
         * We are not who we appear...
         */
        thissys = p;
    } else {
        thissys = utsn.nodename;
    }
    Dout(pn, 11, "thissys = '%s', uname = '%s'\n", thissys, utsn.nodename);

    failsafe = xgetenv("FAILSAFE");
    if (failsafe)
        Dout(pn, 11, "failsafe processing enabled to %s\n", failsafe);

    /*
     *	Use environment variables
     */
    home = getenv("HOME");
    if (!home || !*home) {
        home = ".";
    }

    pwd = getpwuid(my_uid);
    if (pwd)
        cpy(&my_name, &my_namesize, pwd->pw_name);
    else
        cpy(&my_name, &my_namesize, "");

    /* If root, use LOGNAME if set */
    if (my_uid == 0) {
        /* If root, use LOGNAME if set */
        if (((cptr = getenv("LOGNAME")) != NULL) &&
                (strlen(cptr) != 0)) {
            cpy(&my_name, &my_namesize, cptr);
        }
    }
    Dout(pn, 11, "my_name = '%s'\n", my_name);

    /*
     *	Catch signals for cleanup
     */
    if (setjmp(sjbuf)) {
        done(0);
    }

    setsig(SIGINT, delete);
    setsig(SIGQUIT, delete);
    setsig(SIGTRAP, delete);
#ifdef	SIGIOT
    setsig(SIGIOT, delete);
#endif
#ifdef	SIGEMT
    setsig(SIGEMT, delete);
#endif
    setsig(SIGBUS, delete);
    setsig(SIGSEGV, delete);
    setsig(SIGPIPE, delete);
    setsig(SIGALRM, delete);

    setsig(SIGHUP, sig_done);
    setsig(SIGTERM, sig_done);

    cksaved(my_name);

    /*
     *	Rmail is always invoked to send mail
     */
    Dout(pn, 11, "ismail=%d, argc=%d\n", ismail, argc);
    if (ismail && (argc == 1)) {
        sending = FALSE;
        printmail();

    } else {
        sending = TRUE;
        sendmail(argc, argv);
    }
    done(0);
    /*NOTREACHED*/
    return 0;
}