int call_align ( int argc, char ** argv ) { time_t start_t, stop_t, time_bef, time_aft; time ( &start_t ); initenv ( argc, argv ); overlaplen = getMinOverlap ( graphfile ); printf ( "K = %d\n", overlaplen ); time ( &time_bef ); ctg_short = overlaplen + 2; printf ( "contig len cutoff: %d\n", ctg_short ); prlContig2nodes ( graphfile, ctg_short ); time ( &time_aft ); printf ( "time spent on De bruijn graph construction: %ds\n\n", ( int ) ( time_aft - time_bef ) ); //map long read to edge one by one time ( &time_bef ); prlLongRead2Ctg ( shortrdsfile, graphfile ); time ( &time_aft ); printf ( "time spent on mapping long reads: %ds\n\n", ( int ) ( time_aft - time_bef ) ); //map read to edge one by one time ( &time_bef ); prlRead2Ctg ( shortrdsfile, graphfile ); time ( &time_aft ); printf ( "time spent on mapping reads: %ds\n\n", ( int ) ( time_aft - time_bef ) ); free_Sets ( KmerSets, thrd_num ); time ( &stop_t ); printf ( "overall time for alignment: %dm\n\n", ( int ) ( stop_t - start_t ) / 60 ); return 0; }
int do_initenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { extern char * env_name_spec; printf ("Clear Environment to %s...\n", env_name_spec); return (initenv() ? 1 : 0); }
int call_scaffold (int argc, char **argv) { time_t start_t, stop_t, time_bef, time_aft; time (&start_t); initenv (argc, argv); loadPEgrads (graphfile); time (&time_bef); loadUpdatedEdges (graphfile); time (&time_aft); printf ("time spent on loading edges %ds\n", (int) (time_aft - time_bef)); if (!SCAFF) { time (&time_bef); PE2Links (graphfile); time (&time_aft); printf ("time spent on loading pair end info %ds\n\n", (int) (time_aft - time_bef)); time (&time_bef); Links2Scaf (graphfile); time (&time_aft); printf ("time spent on creating scaffolds %ds\n\n", (int) (time_aft - time_bef)); time(&time_bef); transcriptome(graphfile); time(&time_aft); printf("time spent on creating transcriptome %ds\n",(int)(time_aft-time_bef)); // scaffolding (100, graphfile); } prlReadsCloseGap (graphfile); // locateReadOnScaf(graphfile); ScafStat (100, graphfile); if(read_trace) { getReadOnScaf(graphfile); if(RPKM) //Must add '-R' parameter RPKMStat(graphfile); RPKMStat(graphfile); } free_pe_mem (); if (index_array) { free ((void *) index_array); } freeContig_array (); destroyPreArcMem (); destroyConnectMem (); deleteCntLookupTable (); time (&stop_t); printf ("time elapsed: %dm\n", (int) (stop_t - start_t) / 60); return 0; }
main(int argc, char **argv) { char *aa0; char libstr[MAX_FN]; char qname[MAX_FN]; int sq0off; int i, n0; FILE *fp; struct pstruct pst, *ppst; /* stuff from initfa.c/h_init() */ memcpy(qascii,aascii,sizeof(qascii)); /* initialize a pam matrix */ ppst = &pst; strncpy(ppst->pamfile,"BL50",MAX_FN); standard_pam(ppst->pamfile,ppst,0,0); /* this is always protein by default */ ppst->nsq = naa; ppst->nsqx = naax; for (i=0; i<=ppst->nsqx; i++) { ppst->sq[i] = aa[i]; ppst->hsq[i] = haa[i]; ppst->sqx[i]=aax[i]; /* sq = aa */ ppst->hsqx[i]=haax[i]; /* hsq = haa */ } ppst->sq[ppst->nsqx+1] = ppst->sqx[ppst->nsqx+1] = '\0'; if ((aa0 = calloc(MAXTST,sizeof(char)))==NULL) { fprintf(stderr,"Cannot allocate aa0\n"); exit(1); } initenv(argc, argv, &pst, qname); alloc_pam(pst.nsq+1,pst.nsq+1, &pst); initpam2(&pst); n0 = getseq (qname, qascii, aa0, MAXTST, libstr,&sq0off); if (!pst.pam_pssm) { fprintf(stderr," ** ERROR ** No -P PSSM provided\n"); } else { ppst->pam2p[0] = alloc_pam2p(n0,pst.nsq); ppst->pam2p[1] = alloc_pam2p(n0,pst.nsq); if ((fp = fopen(pst.pgpfile,"rb"))!=NULL) { read_pssm(aa0, n0, pst.nsq, pst.pamscale,fp,ppst); } } }
int call_align ( int argc, char ** argv ) { time_t start_t, stop_t, time_bef, time_aft; time ( &start_t ); fprintf ( stderr, "\n********************\n" ); fprintf ( stderr, "Map\n" ); fprintf ( stderr, "********************\n\n" ); initenv ( argc, argv ); overlaplen = getMinOverlap ( graphfile ); #ifdef MER127 if ( smallKmer > 12 && smallKmer < 128 && smallKmer % 2 == 1 ) { deltaKmer = overlaplen - smallKmer; overlaplen = smallKmer; } #else if ( smallKmer > 12 && smallKmer < 64 && smallKmer % 2 == 1 ) { deltaKmer = overlaplen - smallKmer; overlaplen = smallKmer; } #endif fprintf ( stderr, "Kmer size: %d.\n", overlaplen ); time ( &time_bef ); ctg_short = overlaplen + 2; fprintf ( stderr, "Contig length cutoff: %d.\n", ctg_short ); prlContig2nodes ( graphfile, ctg_short ); time ( &time_aft ); fprintf ( stderr, "Time spent on graph construction: %ds.\n\n", ( int ) ( time_aft - time_bef ) ); //map long read (asm_flags=4) to edge one by one time ( &time_bef ); prlLongRead2Ctg ( shortrdsfile, graphfile ); time ( &time_aft ); fprintf ( stderr, "Time spent on aligning long reads: %ds.\n\n", ( int ) ( time_aft - time_bef ) ); //map read to edge one by one time ( &time_bef ); prlRead2Ctg ( shortrdsfile, graphfile ); time ( &time_aft ); fprintf ( stderr, "Time spent on aligning reads: %ds.\n\n", ( int ) ( time_aft - time_bef ) ); free_Sets ( KmerSets, thrd_num ); time ( &stop_t ); fprintf ( stderr, "Overall time spent on alignment: %dm.\n\n", ( int ) ( stop_t - start_t ) / 60 ); return 0; }
extern int main(int argc, char *argv[], char *envp[]) { char *dashsee[2], *dollarzero, *null[1]; int c; initprint(); dashsee[0] = dashsee[1] = NULL; dollarzero = argv[0]; rc_pid = getpid(); dashell = (*argv[0] == '-'); /* Unix tradition */ while ((c = rc_getopt(argc, argv, "c:deiIlnopsvx")) != -1) switch (c) { case 'c': dashsee[0] = rc_optarg; goto quitopts; case 'd': dashdee = TRUE; break; case 'e': dashee = TRUE; break; case 'I': dashEYE = TRUE; interactive = FALSE; break; case 'i': dasheye = interactive = TRUE; break; case 'l': dashell = TRUE; break; case 'n': dashen = TRUE; break; case 'o': dashoh = TRUE; break; case 'p': dashpee = TRUE; break; case 's': dashess = TRUE; break; case 'v': dashvee = TRUE; break; case 'x': dashex = TRUE; break; case '?': exit(1); } quitopts: argv += rc_optind; /* use isatty() iff neither -i nor -I is set, and iff the input is not from a script or -c flags */ if (!dasheye && !dashEYE && dashsee[0] == NULL && (dashess || *argv == NULL)) interactive = isatty(0); if (!dashoh) { checkfd(0, rFrom); checkfd(1, rCreate); checkfd(2, rCreate); } initsignal(); inithash(); initparse(); assigndefault("ifs", " ", "\t", "\n", (void *)0); #ifdef DEFAULTPATH assigndefault("path", DEFAULTPATH, (void *)0); #endif assigndefault("pid", nprint("%d", rc_pid), (void *)0); assigndefault("prompt", "; ", "", (void *)0); assigndefault("version", VERSION, "$Release: @(#)" PACKAGE " " VERSION " " RELDATE " $", (void *)0); initenv(envp); initinput(); null[0] = NULL; starassign(dollarzero, null, FALSE); /* assign $0 to $* */ inithandler(); if (dashell) { char *rcrc; int fd; rcrc = concat(varlookup("home"), word("/.rcrc", NULL))->w; fd = rc_open(rcrc, rFrom); if (fd == -1) { if (errno != ENOENT) uerror(rcrc); } else { bool push_interactive; pushfd(fd); push_interactive = interactive; interactive = FALSE; doit(TRUE); interactive = push_interactive; close(fd); } } if (dashsee[0] != NULL || dashess) { /* input from -c or -s? */ if (*argv != NULL) starassign(dollarzero, argv, FALSE); if (dashess) pushfd(0); else pushstring(dashsee, TRUE); } else if (*argv != NULL) { /* else from a file? */ b_dot(--argv); rc_exit(getstatus()); } else { /* else stdin */ pushfd(0); } dasheye = FALSE; doit(TRUE); rc_exit(getstatus()); return 0; /* Never really reached. */ }
void main(int argc, char **argv) { Word *w; char *s, *temp; char *files[256], **f = files, **ff; int sflag = 0; int i; int tfd = -1; Biobuf tb; Bufblock *buf; Bufblock *whatif; /* * start with a copy of the current environment variables * instead of sharing them */ Binit(&bout, 1, OWRITE); buf = newbuf(); whatif = 0; USED(argc); for(argv++; *argv && (**argv == '-'); argv++) { bufcpy(buf, argv[0], strlen(argv[0])); insert(buf, ' '); switch(argv[0][1]) { case 'a': aflag = 1; break; case 'd': if(*(s = &argv[0][2])) while(*s) switch(*s++) { case 'p': debug |= D_PARSE; break; case 'g': debug |= D_GRAPH; break; case 'e': debug |= D_EXEC; break; } else debug = 0xFFFF; break; case 'e': explain = &argv[0][2]; break; case 'f': if(*++argv == 0) badusage(); *f++ = *argv; bufcpy(buf, argv[0], strlen(argv[0])); insert(buf, ' '); break; case 'i': iflag = 1; break; case 'k': kflag = 1; break; case 'n': nflag = 1; break; case 's': sflag = 1; break; case 't': tflag = 1; break; case 'u': uflag = 1; break; case 'w': if(whatif == 0) whatif = newbuf(); else insert(whatif, ' '); if(argv[0][2]) bufcpy(whatif, &argv[0][2], strlen(&argv[0][2])); else { if(*++argv == 0) badusage(); bufcpy(whatif, &argv[0][0], strlen(&argv[0][0])); } break; default: badusage(); } } #ifdef PROF { extern etext(); monitor(main, etext, buf, sizeof buf, 300); } #endif if(aflag) iflag = 1; usage(); syminit(); initenv(); usage(); /* assignment args become null strings */ temp = 0; for(i = 0; argv[i]; i++) if(utfrune(argv[i], '=')){ bufcpy(buf, argv[i], strlen(argv[i])); insert(buf, ' '); if(tfd < 0){ temp = maketmp(); if(temp == 0) { perror("temp file"); Exit(); } close(create(temp, OWRITE, 0600)); if((tfd = open(temp, 2)) < 0){ perror(temp); Exit(); } Binit(&tb, tfd, OWRITE); } Bprint(&tb, "%s\n", argv[i]); *argv[i] = 0; } if(tfd >= 0){ Bflush(&tb); LSEEK(tfd, 0L, 0); parse("command line args", tfd, 1); remove(temp); } if (buf->current != buf->start) { buf->current--; insert(buf, 0); } symlook("MKFLAGS", S_VAR, (void *) stow(buf->start)); buf->current = buf->start; for(i = 0; argv[i]; i++){ if(*argv[i] == 0) continue; if(i) insert(buf, ' '); bufcpy(buf, argv[i], strlen(argv[i])); } insert(buf, 0); symlook("MKARGS", S_VAR, (void *) stow(buf->start)); freebuf(buf); if(f == files){ if(access(MKFILE, 4) == 0) parse(MKFILE, open(MKFILE, 0), 0); } else for(ff = files; ff < f; ff++) parse(*ff, open(*ff, 0), 0); if(DEBUG(D_PARSE)){ dumpw("default targets", target1); dumpr("rules", rules); dumpr("metarules", metarules); dumpv("variables"); } if(whatif){ insert(whatif, 0); timeinit(whatif->start); freebuf(whatif); } execinit(); /* skip assignment args */ while(*argv && (**argv == 0)) argv++; catchnotes(); if(*argv == 0){ if(target1) for(w = target1; w; w = w->next) mk(w->s); else { fprint(2, "mk: nothing to mk\n"); Exit(); } } else { if(sflag){ for(; *argv; argv++) if(**argv) mk(*argv); } else { Word *head, *tail, *t; /* fake a new rule with all the args as prereqs */ tail = 0; t = 0; for(; *argv; argv++) if(**argv){ if(tail == 0) tail = t = newword(*argv); else { t->next = newword(*argv); t = t->next; } } if(tail->next == 0) mk(tail->s); else { head = newword("command line arguments"); addrules(head, tail, strdup(""), VIR, mkinline, 0); mk(head->s); } } } if(uflag) prusage(); exits(0); }
main(int argc, char **argv) { int i, j, k, l, m, n, centro[200], len_chroseq[100]; int maxi; int num_seq; char **chrname, **repnames; int num_chro; int *counts, maxc; SEGMENT *segment; int num_segment; int *repeats, num_repeats; char name[1000], temp[1000], c; double id; FILE *fp; readpar(); initenv(argc, argv); /* Input chromsomal information */ chrname = alloc_name(100, 100); fp = ckopen(lenfile, "r"); num_chro = read_chro_centro(chrname, len_chroseq, centro, fp); fclose(fp); nchro = findgenname(chriname, chrname, num_chro); /* input segments */ segment = (SEGMENT *) ckalloc(60000 * sizeof(SEGMENT)); fp = stdin; num_segment = input_segment(segment, chrname, num_chro, fp); /* sort the segments */ /* qsort((void *) segment, num_segment, sizeof(SEGMENT), (void *) segcompar); */ /* Define repeats from sub-repeats */ repeats = (int *) ckalloc(num_segment * sizeof(int)); num_repeats = 0; counts = (int *) ckalloc(10000 * num_segment * sizeof(int)); n = m = 0; j = 0; for(i = 0; i < num_segment; i ++) { if(i == num_segment - 1 || segment[i + 1].pos[0] > segment[i].pos[1] + min_length || segment[i + 1].chro != segment[i].chro) { repeats[num_repeats ++] = i; if(segment[i].chro == nchro) j ++; } if(segment[i].pos[1] - segment[i].pos[0] < min_length) continue; counts[segment[i].eq_pos[0]] ++; if(segment[i].eq_pos[0] > n) n = segment[i].eq_pos[0]; } m += n; k = maxc = 0; for(i = 0; i < m; i ++) { if(counts[i] > 1) k ++; if(counts[i] > maxc) { maxi = i; maxc = counts[i]; } } printf("m %d k %d\n", m, k); printf("%d repeats (%s %d) %d subrepeats %d max_multip subrepeats index %d.\n", num_repeats, chriname, j, k, maxc, maxi); free((void *) counts); chrname = free_name(chrname, 100); free((void *) repeats); free((void *) segment); }
int call_pregraph ( int argc, char ** argv ) { time_t start_t, stop_t, time_bef, time_aft; time ( &start_t ); initenv ( argc, argv ); if ( overlaplen % 2 == 0 ) { overlaplen++; printf ( "K should be an odd number\n" ); } if ( overlaplen < 13 ) { overlaplen = 13; printf ( "K should not be less than 13\n" ); } else if ( overlaplen > 31 ) { overlaplen = 31; printf ( "K should not be greater than 31\n" ); } time ( &time_bef ); prlRead2HashTable ( shortrdsfile, graphfile ); time ( &time_aft ); printf ( "time spent on pre-graph construction: %ds\n\n", ( int ) ( time_aft - time_bef ) ); printf ( "deLowKmer %d, deLowEdge %d\n", deLowKmer, deLowEdge ); //analyzeTips(hash_table, graphfile); if ( !deLowKmer && cutTips ) { time ( &time_bef ); removeSingleTips(); removeMinorTips(); time ( &time_aft ); printf ( "time spent on cutTipe: %ds\n\n", ( int ) ( time_aft - time_bef ) ); } else { time ( &time_bef ); removeMinorTips(); time ( &time_aft ); printf ( "time spent on cutTipe: %ds\n\n", ( int ) ( time_aft - time_bef ) ); } initKmerSetSize = 0; //combine each linear part to an edge time ( &time_bef ); kmer2edges ( graphfile ); time ( &time_aft ); printf ( "time spent on making edges: %ds\n\n", ( int ) ( time_aft - time_bef ) ); //map read to edge one by one time ( &time_bef ); prlRead2edge ( shortrdsfile, graphfile ); time ( &time_aft ); printf ( "time spent on mapping reads: %ds\n\n", ( int ) ( time_aft - time_bef ) ); output_vertex ( graphfile ); free_Sets ( KmerSets, thrd_num ); free_Sets ( KmerSetsPatch, thrd_num ); time ( &stop_t ); printf ( "overall time for lightgraph: %dm\n\n", ( int ) ( stop_t - start_t ) / 60 ); return 0; }
/*ARGSUSED*/ int main (int argc, char **argv) { #ifndef USE_PAM const char *env; #endif /* !USE_PAM */ char **envp = environ; TERMIO termio; int err = 0; #ifdef USE_TERMIO ioctl (0, TCGETA, &termio); termio.c_iflag |= (ICRNL | IXON); termio.c_oflag |= (OPOST | ONLCR); termio.c_cflag |= (CREAD); termio.c_lflag |= (ISIG | ICANON | ECHO | ECHOE | ECHOK); ioctl (0, TCSETAF, &termio); #endif #ifdef USE_TERMIOS tcgetattr (0, &termio); termio.c_iflag |= (ICRNL | IXON); termio.c_oflag |= (CREAD); termio.c_lflag |= (ECHO | ECHOE | ECHOK | ICANON | ISIG); tcsetattr (0, TCSANOW, &termio); #endif Prog = Basename (argv[0]); (void) setlocale (LC_ALL, ""); (void) bindtextdomain (PACKAGE, LOCALEDIR); (void) textdomain (PACKAGE); #ifdef USE_SYSLOG OPENLOG ("sulogin"); #endif initenv (); if (argc > 1) { close (0); close (1); close (2); if (open (argv[1], O_RDWR) >= 0) { dup (0); dup (0); } else { #ifdef USE_SYSLOG SYSLOG (LOG_WARN, "cannot open %s\n", argv[1]); closelog (); #endif exit (1); } } if (access (PASSWD_FILE, F_OK) == -1) { /* must be a password file! */ (void) puts (_("No password file")); #ifdef USE_SYSLOG SYSLOG (LOG_WARN, "No password file\n"); closelog (); #endif exit (1); } #if !defined(DEBUG) && defined(SULOGIN_ONLY_INIT) if (getppid () != 1) { /* parent must be INIT */ #ifdef USE_SYSLOG SYSLOG (LOG_WARN, "Pid == %d, not 1\n", getppid ()); closelog (); #endif exit (1); } #endif if ((isatty (0) == 0) || (isatty (1) == 0) || (isatty (2) == 0)) { #ifdef USE_SYSLOG closelog (); #endif exit (1); /* must be a terminal */ } /* If we were init, we need to start a new session */ if (getppid() == 1) { setsid(); if (ioctl(0, TIOCSCTTY, 1) != 0) { (void) fputs (_("TIOCSCTTY failed"), stderr); } } while (NULL != *envp) { /* add inherited environment, */ addenv (*envp, NULL); /* some variables change later */ envp++; } #ifndef USE_PAM env = getdef_str ("ENV_TZ"); if (NULL != env) { addenv (('/' == *env) ? tz (env) : env, NULL); } env = getdef_str ("ENV_HZ"); if (NULL != env) { addenv (env, NULL); /* set the default $HZ, if one */ } #endif /* !USE_PAM */ (void) strcpy (name, "root"); /* KLUDGE!!! */ (void) signal (SIGALRM, catch_signals); /* exit if the timer expires */ (void) alarm (ALARM); /* only wait so long ... */ while (true) { /* repeatedly get login/password pairs */ char *cp; pw_entry (name, &pwent); /* get entry from password file */ if (pwent.pw_name == (char *) 0) { /* * Fail secure */ (void) puts (_("No password entry for 'root'")); #ifdef USE_SYSLOG SYSLOG (LOG_WARN, "No password entry for 'root'\n"); closelog (); #endif exit (1); } /* * Here we prompt for the root password, or if no password * is given we just exit. */ /* get a password for root */ cp = getpass (_( "\n" "Type control-d to proceed with normal startup,\n" "(or give root password for system maintenance):")); /* * XXX - can't enter single user mode if root password is * empty. I think this doesn't happen very often :-). But * it will work with standard getpass() (no NULL on EOF). * --marekm */ if ((NULL == cp) || ('\0' == *cp)) { #ifdef USE_SYSLOG SYSLOG (LOG_INFO, "Normal startup\n"); closelog (); #endif (void) puts (""); #ifdef TELINIT execl (PATH_TELINIT, "telinit", RUNLEVEL, (char *) 0); #endif exit (0); } else { STRFCPY (pass, cp); strzero (cp); } if (valid (pass, &pwent)) { /* check encrypted passwords ... */ break; /* ... encrypted passwords matched */ } #ifdef USE_SYSLOG SYSLOG (LOG_WARN, "Incorrect root password\n"); #endif sleep (2); (void) puts (_("Login incorrect")); } strzero (pass); (void) alarm (0); (void) signal (SIGALRM, SIG_DFL); environ = newenvp; /* make new environment active */ (void) puts (_("Entering System Maintenance Mode")); #ifdef USE_SYSLOG SYSLOG (LOG_INFO, "System Maintenance Mode\n"); #endif #ifdef USE_SYSLOG closelog (); #endif /* exec the shell finally. */ err = shell (pwent.pw_shell, (char *) 0, environ); return ((err == ENOENT) ? E_CMD_NOTFOUND : E_CMD_NOEXEC); }
/* * login - create a new login session for a user * * login is typically called by getty as the second step of a * new user session. getty is responsible for setting the line * characteristics to a reasonable set of values and getting * the name of the user to be logged in. login may also be * called to create a new user session on a pty for a variety * of reasons, such as X servers or network logins. * * the flags which login supports are * * -p - preserve the environment * -r - perform autologin protocol for rlogin * -f - do not perform authentication, user is preauthenticated * -h - the name of the remote host */ int main (int argc, char **argv) { const char *tmptty; char tty[BUFSIZ]; #ifdef RLOGIN char term[128] = ""; #endif /* RLOGIN */ #if defined(HAVE_STRFTIME) && !defined(USE_PAM) char ptime[80]; #endif unsigned int delay; unsigned int retries; bool failed; bool subroot = false; #ifndef USE_PAM bool is_console; #endif int err; const char *cp; char *tmp; char fromhost[512]; struct passwd *pwd = NULL; char **envp = environ; const char *failent_user; /*@null@*/struct utmp *utent; #ifdef USE_PAM int retcode; pid_t child; char *pam_user = NULL; #else struct spwd *spwd = NULL; #endif /* * Some quick initialization. */ sanitize_env (); (void) setlocale (LC_ALL, ""); (void) bindtextdomain (PACKAGE, LOCALEDIR); (void) textdomain (PACKAGE); initenv (); amroot = (getuid () == 0); Prog = Basename (argv[0]); if (geteuid() != 0) { fprintf (stderr, _("%s: Cannot possibly work without effective root\n"), Prog); exit (1); } process_flags (argc, argv); if ((isatty (0) == 0) || (isatty (1) == 0) || (isatty (2) == 0)) { exit (1); /* must be a terminal */ } utent = get_current_utmp (); /* * Be picky if run by normal users (possible if installed setuid * root), but not if run by root. This way it still allows logins * even if your getty is broken, or if something corrupts utmp, * but users must "exec login" which will use the existing utmp * entry (will not overwrite remote hostname). --marekm */ if (!amroot && (NULL == utent)) { (void) puts (_("No utmp entry. You must exec \"login\" from the lowest level \"sh\"")); exit (1); } /* NOTE: utent might be NULL afterwards */ tmptty = ttyname (0); if (NULL == tmptty) { tmptty = "UNKNOWN"; } STRFCPY (tty, tmptty); #ifndef USE_PAM is_console = console (tty); #endif if (rflg || hflg) { /* * Add remote hostname to the environment. I think * (not sure) I saw it once on Irix. --marekm */ addenv ("REMOTEHOST", hostname); } if (fflg) { preauth_flag = true; } if (hflg) { reason = PW_RLOGIN; } #ifdef RLOGIN if (rflg) { assert (NULL == username); username = xmalloc (USER_NAME_MAX_LENGTH + 1); username[USER_NAME_MAX_LENGTH] = '\0'; if (do_rlogin (hostname, username, USER_NAME_MAX_LENGTH, term, sizeof term)) { preauth_flag = true; } else { free (username); username = NULL; } } #endif /* RLOGIN */ OPENLOG ("login"); setup_tty (); #ifndef USE_PAM (void) umask (getdef_num ("UMASK", GETDEF_DEFAULT_UMASK)); { /* * Use the ULIMIT in the login.defs file, and if * there isn't one, use the default value. The * user may have one for themselves, but otherwise, * just take what you get. */ long limit = getdef_long ("ULIMIT", -1L); if (limit != -1) { set_filesize_limit (limit); } } #endif /* * The entire environment will be preserved if the -p flag * is used. */ if (pflg) { while (NULL != *envp) { /* add inherited environment, */ addenv (*envp, NULL); /* some variables change later */ envp++; } } #ifdef RLOGIN if (term[0] != '\0') { addenv ("TERM", term); } else #endif /* RLOGIN */ { /* preserve TERM from getty */ if (!pflg) { tmp = getenv ("TERM"); if (NULL != tmp) { addenv ("TERM", tmp); } } } init_env (); if (optind < argc) { /* now set command line variables */ set_env (argc - optind, &argv[optind]); } if (rflg || hflg) { cp = hostname; #ifdef HAVE_STRUCT_UTMP_UT_HOST } else if ((NULL != utent) && ('\0' != utent->ut_host[0])) { cp = utent->ut_host; #endif /* HAVE_STRUCT_UTMP_UT_HOST */ } else { cp = ""; } if ('\0' != *cp) { snprintf (fromhost, sizeof fromhost, " on '%.100s' from '%.200s'", tty, cp); } else { snprintf (fromhost, sizeof fromhost, " on '%.100s'", tty); } top: /* only allow ALARM sec. for login */ (void) signal (SIGALRM, alarm_handler); timeout = getdef_unum ("LOGIN_TIMEOUT", ALARM); if (timeout > 0) { (void) alarm (timeout); } environ = newenvp; /* make new environment active */ delay = getdef_unum ("FAIL_DELAY", 1); retries = getdef_unum ("LOGIN_RETRIES", RETRIES); #ifdef USE_PAM retcode = pam_start ("login", username, &conv, &pamh); if (retcode != PAM_SUCCESS) { fprintf (stderr, _("login: PAM Failure, aborting: %s\n"), pam_strerror (pamh, retcode)); SYSLOG ((LOG_ERR, "Couldn't initialize PAM: %s", pam_strerror (pamh, retcode))); exit (99); } /* * hostname & tty are either set to NULL or their correct values, * depending on how much we know. We also set PAM's fail delay to * ours. * * PAM_RHOST and PAM_TTY are used for authentication, only use * information coming from login or from the caller (e.g. no utmp) */ retcode = pam_set_item (pamh, PAM_RHOST, hostname); PAM_FAIL_CHECK; retcode = pam_set_item (pamh, PAM_TTY, tty); PAM_FAIL_CHECK; #ifdef HAS_PAM_FAIL_DELAY retcode = pam_fail_delay (pamh, 1000000 * delay); PAM_FAIL_CHECK; #endif /* if fflg, then the user has already been authenticated */ if (!fflg) { unsigned int failcount = 0; char hostn[256]; char loginprompt[256]; /* That's one hell of a prompt :) */ /* Make the login prompt look like we want it */ if (gethostname (hostn, sizeof (hostn)) == 0) { snprintf (loginprompt, sizeof (loginprompt), _("%s login: "******"login: "******"TOO MANY LOGIN TRIES (%u)%s FOR '%s'", failcount, fromhost, failent_user)); fprintf(stderr, _("Maximum number of tries exceeded (%u)\n"), failcount); PAM_END; exit(0); } else if (retcode == PAM_ABORT) { /* Serious problems, quit now */ (void) fputs (_("login: abort requested by PAM\n"), stderr); SYSLOG ((LOG_ERR,"PAM_ABORT returned from pam_authenticate()")); PAM_END; exit(99); } else if (retcode != PAM_SUCCESS) { SYSLOG ((LOG_NOTICE,"FAILED LOGIN (%u)%s FOR '%s', %s", failcount, fromhost, failent_user, pam_strerror (pamh, retcode))); failed = true; } if (!failed) { break; } #ifdef WITH_AUDIT audit_fd = audit_open (); audit_log_acct_message (audit_fd, AUDIT_USER_LOGIN, NULL, /* Prog. name */ "login", failent_user, AUDIT_NO_ID, hostname, NULL, /* addr */ tty, 0); /* result */ close (audit_fd); #endif /* WITH_AUDIT */ (void) puts (""); (void) puts (_("Login incorrect")); if (failcount >= retries) { SYSLOG ((LOG_NOTICE, "TOO MANY LOGIN TRIES (%u)%s FOR '%s'", failcount, fromhost, failent_user)); fprintf(stderr, _("Maximum number of tries exceeded (%u)\n"), failcount); PAM_END; exit(0); } /* * Let's give it another go around. * Even if a username was given on the command * line, prompt again for the username. */ retcode = pam_set_item (pamh, PAM_USER, NULL); PAM_FAIL_CHECK; } /* We don't get here unless they were authenticated above */ (void) alarm (0); } /* Check the account validity */ retcode = pam_acct_mgmt (pamh, 0); if (retcode == PAM_NEW_AUTHTOK_REQD) { retcode = pam_chauthtok (pamh, PAM_CHANGE_EXPIRED_AUTHTOK); } PAM_FAIL_CHECK; /* Open the PAM session */ get_pam_user (&pam_user); retcode = pam_open_session (pamh, hushed (pam_user) ? PAM_SILENT : 0); PAM_FAIL_CHECK; /* Grab the user information out of the password file for future usage * First get the username that we are actually using, though. * * From now on, we will discard changes of the user (PAM_USER) by * PAM APIs. */ get_pam_user (&pam_user); if (NULL != username) { free (username); } username = pam_user; failent_user = get_failent_user (username); pwd = xgetpwnam (username); if (NULL == pwd) { SYSLOG ((LOG_ERR, "cannot find user %s", failent_user)); exit (1); } /* This set up the process credential (group) and initialize the * supplementary group access list. * This has to be done before pam_setcred */ if (setup_groups (pwd) != 0) { exit (1); } retcode = pam_setcred (pamh, PAM_ESTABLISH_CRED); PAM_FAIL_CHECK; /* NOTE: If pam_setcred changes PAM_USER, this will not be taken * into account. */ #else /* ! USE_PAM */ while (true) { /* repeatedly get login/password pairs */ /* user_passwd is always a pointer to this constant string * or a passwd or shadow password that will be memzero by * pw_free / spw_free. * Do not free() user_passwd. */ const char *user_passwd = "!"; /* Do some cleanup to avoid keeping entries we do not need * anymore. */ if (NULL != pwd) { pw_free (pwd); pwd = NULL; } if (NULL != spwd) { spw_free (spwd); spwd = NULL; } failed = false; /* haven't failed authentication yet */ if (NULL == username) { /* need to get a login id */ if (subroot) { closelog (); exit (1); } preauth_flag = false; username = xmalloc (USER_NAME_MAX_LENGTH + 1); username[USER_NAME_MAX_LENGTH] = '\0'; login_prompt (_("\n%s login: "******"!", * the account is locked and the user cannot * login, even if they have been * "pre-authenticated." */ if ( ('!' == user_passwd[0]) || ('*' == user_passwd[0])) { failed = true; } } if (strcmp (user_passwd, SHADOW_PASSWD_STRING) == 0) { spwd = xgetspnam (username); if (NULL != spwd) { user_passwd = spwd->sp_pwdp; } else { /* The user exists in passwd, but not in * shadow. SHADOW_PASSWD_STRING indicates * that the password shall be in shadow. */ SYSLOG ((LOG_WARN, "no shadow password for '%s'%s", username, fromhost)); } } /* * The -r and -f flags provide a name which has already * been authenticated by some server. */ if (preauth_flag) { goto auth_ok; } if (pw_auth (user_passwd, username, reason, (char *) 0) == 0) { goto auth_ok; } SYSLOG ((LOG_WARN, "invalid password for '%s' %s", failent_user, fromhost)); failed = true; auth_ok: /* * This is the point where all authenticated users wind up. * If you reach this far, your password has been * authenticated and so on. */ if ( !failed && (NULL != pwd) && (0 == pwd->pw_uid) && !is_console) { SYSLOG ((LOG_CRIT, "ILLEGAL ROOT LOGIN %s", fromhost)); failed = true; } if ( !failed && !login_access (username, ('\0' != *hostname) ? hostname : tty)) { SYSLOG ((LOG_WARN, "LOGIN '%s' REFUSED %s", username, fromhost)); failed = true; } if ( (NULL != pwd) && getdef_bool ("FAILLOG_ENAB") && !failcheck (pwd->pw_uid, &faillog, failed)) { SYSLOG ((LOG_CRIT, "exceeded failure limit for '%s' %s", username, fromhost)); failed = true; } if (!failed) { break; } /* don't log non-existent users */ if ((NULL != pwd) && getdef_bool ("FAILLOG_ENAB")) { failure (pwd->pw_uid, tty, &faillog); } if (getdef_str ("FTMP_FILE") != NULL) { #ifdef USE_UTMPX struct utmpx *failent = prepare_utmpx (failent_user, tty, /* FIXME: or fromhost? */hostname, utent); #else /* !USE_UTMPX */ struct utmp *failent = prepare_utmp (failent_user, tty, hostname, utent); #endif /* !USE_UTMPX */ failtmp (failent_user, failent); free (failent); } retries--; if (retries <= 0) { SYSLOG ((LOG_CRIT, "REPEATED login failures%s", fromhost)); } /* * If this was a passwordless account and we get here, login * was denied (securetty, faillog, etc.). There was no * password prompt, so do it now (will always fail - the bad * guys won't see that the passwordless account exists at * all). --marekm */ if (user_passwd[0] == '\0') { pw_auth ("!", username, reason, (char *) 0); } /* * Authentication of this user failed. * The username must be confirmed in the next try. */ free (username); username = NULL; /* * Wait a while (a la SVR4 /usr/bin/login) before attempting * to login the user again. If the earlier alarm occurs * before the sleep() below completes, login will exit. */ if (delay > 0) { (void) sleep (delay); } (void) puts (_("Login incorrect")); /* allow only one attempt with -r or -f */ if (rflg || fflg || (retries <= 0)) { closelog (); exit (1); } } /* while (true) */ #endif /* ! USE_PAM */ assert (NULL != username); assert (NULL != pwd); (void) alarm (0); /* turn off alarm clock */ #ifndef USE_PAM /* PAM does this */ /* * porttime checks moved here, after the user has been * authenticated. now prints a message, as suggested * by Ivan Nejgebauer <*****@*****.**>. --marekm */ if ( getdef_bool ("PORTTIME_CHECKS_ENAB") && !isttytime (username, tty, time ((time_t *) 0))) { SYSLOG ((LOG_WARN, "invalid login time for '%s'%s", username, fromhost)); closelog (); bad_time_notify (); exit (1); } check_nologin (pwd->pw_uid == 0); #endif if (getenv ("IFS")) { /* don't export user IFS ... */ addenv ("IFS= \t\n", NULL); /* ... instead, set a safe IFS */ } if (pwd->pw_shell[0] == '*') { /* subsystem root */ pwd->pw_shell++; /* skip the '*' */ subsystem (pwd); /* figure out what to execute */ subroot = true; /* say I was here again */ endpwent (); /* close all of the file which were */ endgrent (); /* open in the original rooted file */ endspent (); /* system. they will be re-opened */ #ifdef SHADOWGRP endsgent (); /* in the new rooted file system */ #endif goto top; /* go do all this all over again */ } #ifdef WITH_AUDIT audit_fd = audit_open (); audit_log_acct_message (audit_fd, AUDIT_USER_LOGIN, NULL, /* Prog. name */ "login", username, AUDIT_NO_ID, hostname, NULL, /* addr */ tty, 1); /* result */ close (audit_fd); #endif /* WITH_AUDIT */ #ifndef USE_PAM /* pam_lastlog handles this */ if (getdef_bool ("LASTLOG_ENAB")) { /* give last login and log this one */ dolastlog (&ll, pwd, tty, hostname); } #endif #ifndef USE_PAM /* PAM handles this as well */ /* * Have to do this while we still have root privileges, otherwise we * don't have access to /etc/shadow. */ if (NULL != spwd) { /* check for age of password */ if (expire (pwd, spwd)) { /* The user updated her password, get the new * entries. * Use the x variants because we need to keep the * entry for a long time, and there might be other * getxxyy in between. */ pw_free (pwd); pwd = xgetpwnam (username); if (NULL == pwd) { SYSLOG ((LOG_ERR, "cannot find user %s after update of expired password", username)); exit (1); } spw_free (spwd); spwd = xgetspnam (username); } } setup_limits (pwd); /* nice, ulimit etc. */ #endif /* ! USE_PAM */ chown_tty (pwd); #ifdef USE_PAM /* * We must fork before setuid() because we need to call * pam_close_session() as root. */ (void) signal (SIGINT, SIG_IGN); child = fork (); if (child < 0) { /* error in fork() */ fprintf (stderr, _("%s: failure forking: %s"), Prog, strerror (errno)); PAM_END; exit (0); } else if (child != 0) { /* * parent - wait for child to finish, then cleanup * session */ wait (NULL); PAM_END; exit (0); } /* child */ #endif /* If we were init, we need to start a new session */ if (getppid() == 1) { setsid(); if (ioctl(0, TIOCSCTTY, 1) != 0) { fprintf (stderr, _("TIOCSCTTY failed on %s"), tty); } } /* * The utmp entry needs to be updated to indicate the new status * of the session, the new PID and SID. */ update_utmp (username, tty, hostname, utent); /* The pwd and spwd entries for the user have been copied. * * Close all the files so that unauthorized access won't occur. */ endpwent (); /* stop access to password file */ endgrent (); /* stop access to group file */ endspent (); /* stop access to shadow passwd file */ #ifdef SHADOWGRP endsgent (); /* stop access to shadow group file */ #endif /* Drop root privileges */ #ifndef USE_PAM if (setup_uid_gid (pwd, is_console)) #else /* The group privileges were already dropped. * See setup_groups() above. */ if (change_uid (pwd)) #endif { exit (1); } setup_env (pwd); /* set env vars, cd to the home dir */ #ifdef USE_PAM { const char *const *env; env = (const char *const *) pam_getenvlist (pamh); while ((NULL != env) && (NULL != *env)) { addenv (*env, NULL); env++; } } #endif (void) setlocale (LC_ALL, ""); (void) bindtextdomain (PACKAGE, LOCALEDIR); (void) textdomain (PACKAGE); if (!hushed (username)) { addenv ("HUSHLOGIN=FALSE", NULL); /* * pam_unix, pam_mail and pam_lastlog should take care of * this */ #ifndef USE_PAM motd (); /* print the message of the day */ if ( getdef_bool ("FAILLOG_ENAB") && (0 != faillog.fail_cnt)) { failprint (&faillog); /* Reset the lockout times if logged in */ if ( (0 != faillog.fail_max) && (faillog.fail_cnt >= faillog.fail_max)) { (void) puts (_("Warning: login re-enabled after temporary lockout.")); SYSLOG ((LOG_WARN, "login '%s' re-enabled after temporary lockout (%d failures)", username, (int) faillog.fail_cnt)); } } if ( getdef_bool ("LASTLOG_ENAB") && (ll.ll_time != 0)) { time_t ll_time = ll.ll_time; #ifdef HAVE_STRFTIME (void) strftime (ptime, sizeof (ptime), "%a %b %e %H:%M:%S %z %Y", localtime (&ll_time)); printf (_("Last login: %s on %s"), ptime, ll.ll_line); #else printf (_("Last login: %.19s on %s"), ctime (&ll_time), ll.ll_line); #endif #ifdef HAVE_LL_HOST /* __linux__ || SUN4 */ if ('\0' != ll.ll_host[0]) { printf (_(" from %.*s"), (int) sizeof ll.ll_host, ll.ll_host); } #endif printf (".\n"); } agecheck (spwd); mailcheck (); /* report on the status of mail */ #endif /* !USE_PAM */ } else { addenv ("HUSHLOGIN=TRUE", NULL); } ttytype (tty); (void) signal (SIGQUIT, SIG_DFL); /* default quit signal */ (void) signal (SIGTERM, SIG_DFL); /* default terminate signal */ (void) signal (SIGALRM, SIG_DFL); /* default alarm signal */ (void) signal (SIGHUP, SIG_DFL); /* added this. --marekm */ (void) signal (SIGINT, SIG_DFL); /* default interrupt signal */ if (0 == pwd->pw_uid) { SYSLOG ((LOG_NOTICE, "ROOT LOGIN %s", fromhost)); } else if (getdef_bool ("LOG_OK_LOGINS")) { SYSLOG ((LOG_INFO, "'%s' logged in %s", username, fromhost)); } closelog (); tmp = getdef_str ("FAKE_SHELL"); if (NULL != tmp) { err = shell (tmp, pwd->pw_shell, newenvp); /* fake shell */ } else { /* exec the shell finally */ err = shell (pwd->pw_shell, (char *) 0, newenvp); } return ((err == ENOENT) ? E_CMD_NOTFOUND : E_CMD_NOEXEC); }
/************************************************* Function: call_heavygraph Description: The main function for contig step . its processes are as below: 1. Solve repeat 2. Merge bubble(clean bubble is optional for multikmer) 3. Remove weak edge and low coverage edge 4. Cut tips 5. Iterate multikmer(optional) Input: @see display_contig_usage () Output: The files below: 1. *.contig 2. *.ContigIndex 3. *.update.edge 4. *.Arc 5. *.read [optional] 6. *.preGraphBasic [optional] Return: None. *************************************************/ int call_heavygraph ( int argc, char ** argv ) { time_t start_t, stop_t, time_bef, time_aft; time ( &start_t ); boolean ret; fprintf ( stderr, "\n********************\n" ); fprintf ( stderr, "Contig\n" ); fprintf ( stderr, "********************\n\n" ); initenv ( argc, argv ); loadVertex ( graphfile ); loadEdge ( graphfile ); if ( repeatSolve ) { ret = loadPathBin ( graphfile ); } swapedge(); sortedge(); freshArc(); if ( repeatSolve ) { time ( &time_bef ); // ret = loadPathBin (graphfile); if ( ret ) { solveReps (); } else { fprintf ( stderr, "Repeat solving can't be done...\n" ); } time ( &time_aft ); fprintf ( stderr, "Time spent on solving repeat: %ds.\n", ( int ) ( time_aft - time_bef ) ); } //edgecvg_bar(edge_array,num_ed,graphfile,100); if ( !iter && M > 0 ) { time ( &time_bef ); bubblePinch ( 0.90, graphfile, M, 0, 1 ); time ( &time_aft ); fprintf ( stderr, "Time spent on pinching bubbles: %ds.\n", ( int ) ( time_aft - time_bef ) ); } if ( iter && cleanBubble && M > 0 ) { time ( &time_bef ); clean = 1; long long oldpinCounter = 0; long long min = 10; int times = 0; while ( min >= 10 ) { times++; if ( times >= 4 ) { break; } bubblePinch ( 0.90, graphfile, M, 1, 0 ); min = pinCounter; fprintf ( stderr, "%lld clean bubbles merged.\n", pinCounter ); } time ( &time_aft ); fprintf ( stderr, "Time spent on pinching clean bubbles: %ds.\n", ( int ) ( time_aft - time_bef ) ); clean = 0; } if ( deLowEdge ) { removeWeakEdges ( 2 * overlaplen, 1 ); removeLowCovEdges ( 2 * overlaplen, deLowEdge, !iter ); } cutTipsInGraph ( 0, 0, !iter ); if ( iter ) { Iterate ( shortrdsfile, graphfile, maxk, M ); //keepReadFile, if ( M > 0 ) { time ( &time_bef ); bubblePinch ( 0.90, graphfile, M, 1, 0 ); time ( &time_aft ); fprintf ( stderr, "Time spent on pinching bubbles: %ds.\n", ( int ) ( time_aft - time_bef ) ); } freshpreGraphBasic ( iter, maxk, graphfile ); } //output_graph(graphfile); output_contig ( edge_array, num_ed, graphfile, overlaplen + 1 ); output_updated_edges ( graphfile ); output_heavyArcs ( graphfile ); if ( vt_array ) { free ( ( void * ) vt_array ); vt_array = NULL; } if ( edge_array ) { free_edge_array ( edge_array, num_ed_limit ); edge_array = NULL; } destroyArcMem (); time ( &stop_t ); fprintf ( stderr, "\nTime spent on constructing contig: %dm.\n\n", ( int ) ( stop_t - start_t ) / 60 ); return 0; }
main(int argc, char **argv) { int i, j, k, l, m, n; int dist[20]; int reads; int num_vertex, num_class, num_edge; int *len_seq, num_seq, num_remain; int **num_pa; char **src_seq, **src_name; char temp[100]; ALIGN **eq_class, *align; EDGE **edge, *edge1, *edge2, *bal_edge1, *bal_edge2; PATH *path; int num_path; NODES **vertex, *begin, *node, *node_next, **start_node; LIST **list; READINTERVAL *readinterval; POSITION *position; FILE *fp, *fp1; readpar(); random1(&idum); initenv(argc, argv); printf("%d %d %d\n", sizeof(POSITION), sizeof(NODES), sizeof(LIST)); /* Input the length of the genome (required) */ len_seq = (int *) ckalloc(2 * MAX_NUM * sizeof(int)); src_name = alloc_name(MAX_NUM, 100); fp = ckopen(lenfile, "r"); num_seq = readlen(fp, len_seq, src_name); fclose(fp); src_seq = (char **) ckalloc(2 * num_seq * sizeof(char *)); l = 0; printf("Genome length: "); for(i = 0; i < num_seq; i ++) { l += len_seq[i]; printf("%d ", len_seq[i]); } printf("\n"); printf("Total length: %d\n", l); /* Make reverse complements of input sequences rev(i) --> i + num_seq */ for(i = 0; i < num_seq; i ++) { len_seq[i + num_seq] = len_seq[i]; src_seq[i] = (char *) ckalloc(len_seq[i] * sizeof(char)); src_seq[i + num_seq] = (char *) ckalloc(len_seq[i] * sizeof(char)); for(j = 0; j < len_seq[i]; j ++) { src_seq[num_seq + i][j] = rev(src_seq[i][len_seq[i] - j - 1]); } } /* Input equivalent readintervales between reads -- see the format of the equivalent readinterval files */ printf("Read equivalent readintervales...\n"); eq_class = (ALIGN **) ckalloc(2 * num_seq * sizeof(ALIGN *)); fp = ckopen(inpfile, "r"); num_class = readclass(eq_class, num_seq, fp); fclose(fp); printf("# equivalent readintervales input: %d\n", num_class); /* for(i = 0; i < 2 * num_seq; i ++) { align = eq_class[i]; while(align) { printf("See: \n"); output_align(align, src_name, src_seq, len_seq, num_seq); getchar(); align = align -> next; } } */ /* Initialize the nodes: each position in each read is assigned as a new node. An array of "list" is set up for each read */ list = (LIST **) ckalloc(2 * num_seq * sizeof(LIST *)); for(i = 0; i < 2 * num_seq; i ++) { list[i] = (LIST *) ckalloc(len_seq[i] * sizeof(LIST)); } printf("intitialize nodes...\n"); initialize(list, len_seq, num_seq); printf("done.\n"); n = countnode(list, len_seq, 2 * num_seq); printf("# of nodes before merge: %d\n", n); /* Glue together two nodes if their corresponding positions are defined as equivalent in a pairwise alignment */ printf("Merge...\n"); merge(num_seq, len_seq, eq_class, num_class, list); printf("done.\n"); for(i = 0; i < num_seq; i ++) { while(eq_class[i]) { eq_class[i] = free_align(eq_class[i]); } } free((void **) eq_class); /* Compute the width of each node */ for(i = 0; i < 2 * num_seq; i ++) { for(j = 0; j < len_seq[i]; j ++) { if(!list[i][j].node -> visit) { list[i][j].node -> num_path = countthickness(list[i][j].node); list[i][j].node -> visit = 1; } } } cleannode(list, len_seq, 2 * num_seq); n = countnode(list, len_seq, 2 * num_seq); printf("# of nodes after merge: %d\n", n); /* Add edges to the graph */ edge = (EDGE **) ckalloc(n * sizeof(EDGE *)); num_edge = graph(num_seq, len_seq, list, edge); printf("# edges: %d\n", num_edge); start_node = (NODES **) ckalloc(num_seq * sizeof(NODES *)); for(i = 0; i < num_seq; i ++) { if(len_seq[i] > 0) { start_node[i] = list[i][0].node; } else { start_node[i] = (NODES *) NULL; } } for(i = 0; i < 2 * num_seq; i ++) { free((void *) list[i]); } free((void **) list); vertex = (NODES **) ckalloc(2 * num_edge * sizeof(NODES *)); num_vertex = count_vertex(edge, num_edge, vertex); free((void **) edge); num_pa = (int **) ckalloc(MAX_BRA * sizeof(int *)); for(i = 0; i < MAX_BRA; i ++) { num_pa[i] = (int *) ckalloc(MAX_BRA * sizeof(int)); } num_edge = count_edge_simp(vertex, num_vertex, num_pa); printf("%d vertices %d edges (%d source %d sinks) remained.\n", num_vertex, num_edge, num_pa[0][1], num_pa[1][0]); /* Assign the complementary edges of each edge */ for(i = 0; i < num_vertex; i ++) { for(j = 0; j < vertex[i] -> num_nextedge; j ++) { edge1 = vertex[i] -> nextedge[j]; edge1 -> bal_edge = find_bal_edge(edge1, len_seq, num_seq, i); } } /* Remove bulges in the graph */ printf("Shave...\n"); num_vertex = shave_graph(vertex, num_vertex); printf("done.\n"); /* Remove cycles shorter than some threshold in the graph */ /* printf("Shaving graph...\n"); num_vertex = rem_cycle(vertex, num_vertex); printf("done.\n%d vertices remained.\n", num_vertex); */ /* remove short edges */ /* printf("Remove shortedges...\n"); num_vertex = rem_short_edge(vertex, num_vertex, len_seq); printf("done.\n%d vertices remained.\n", num_vertex); fflush(stdout); */ num_edge = count_edge_simp(vertex, num_vertex, num_pa); printf("%d vertices %d edges (%d source %d sinks) remained.\n", num_vertex, num_edge, num_pa[0][1], num_pa[1][0]); fflush(stdout); /* Allocate the spaces for paths */ printf("Allocating paths...\n"); for(i = 0; i < num_vertex; i ++) { vertex[i] -> num_path = 0; } /* Build sequence paths */ printf("Define paths...\n"); m = 0; for(i = 0; i < num_vertex; i ++) { for(j = 0; j < vertex[i] -> num_nextedge; j ++) { m += vertex[i] -> nextedge[j] -> multip; } } path = (PATH *) ckalloc(2 * num_seq * sizeof(PATH)); for(i = 0; i < 2 * num_seq; i ++) { path[i].edge = (EDGE **) ckalloc(m * sizeof(EDGE *)); } num_path = readpath(start_node, path, num_seq); free((void **) start_node); num_edge = count_edge_simp(vertex, num_vertex, num_pa); m = l = 0; for(i = 0; i < num_vertex; i ++) { for(j = 0; j < vertex[i] -> num_nextedge; j ++) { l += vertex[i] -> nextedge[j] -> length; if(vertex[i] -> nextedge[j] -> length > m) { m = vertex[i] -> nextedge[j] -> length; } } } printf("%d vertics %d edges (%d source %d sinks) remained: total length %d (maximal %d).\n", num_vertex, num_edge, num_pa[0][1], num_pa[1][0], l, m); fflush(stdout); /* Make consensus of edges */ initial_edge(vertex, num_vertex, src_seq, num_seq); printf("edge initialed\n"); /* Output sequence path */ n = 0; for(i = 0; i < num_vertex; i ++) { vertex[i] -> visit = i; for(j = 0; j < vertex[i] -> num_nextedge; j ++) { vertex[i] -> nextedge[j] -> start_cover = n; n ++; } } for(m = 0; m < num_seq; m ++) { printf("len_path %d\n", path[m].len_path); printf("Sequence%d: ", m + 1); for(i = 0; i < path[m].len_path; i ++) { printf("%d -- %d(%d,%d) --> ", path[m].edge[i] -> begin -> visit, path[m].edge[i] -> start_cover, path[m].edge[i] -> multip, path[m].edge[i] -> length); if(i % 5 == 4) { printf("\n"); } } if(path[m].len_path > 0) { printf("%d\n", path[m].edge[i - 1] -> end -> visit); } else { printf("\n"); } fflush(stdout); } /* Output graph & contigs */ sprintf(temp, "%s.edge", seqfile); fp = ckopen(temp, "w"); sprintf(temp, "%s.graph", seqfile); fp1 = ckopen(temp, "w"); write_graph(vertex, num_vertex, fp, fp1); fclose(fp); fclose(fp1); /* Output read intervals in each edge */ sprintf(temp, "%s.intv", seqfile); fp = ckopen(temp, "w"); write_interval(vertex, num_vertex, fp); fclose(fp); /* Output graphviz format graph */ sprintf(temp, "%s", outfile); fp = ckopen(temp, "w"); output_graph(vertex, num_vertex, fp); fclose(fp); for(i = 0; i < MAX_BRA; i ++) { free((void *) num_pa[i]); } free((void **) num_pa); for(i = 0; i < 2 * num_seq; i ++) { if(path[i].len_path > 0) { free((void **) path[i].edge); } } free((void *) path); free_graph(vertex, num_vertex); for(i = 0; i < 2 * num_seq; i ++) { free((void *) src_seq[i]); } free((void **) src_seq); free_name(src_name, MAX_NUM); free((void *) len_seq); }
main(int argc, char **argv) { int i, j, k, l, m, n; char **src_seq, **src_name; int *len_seq, num_seq; char temp[100]; ALIGN **align, *aln, *aln0; FILE *fp; readpar(); random1(&idum); initenv(argc, argv); /* Input the length of the reads (required) */ len_seq = (int *) ckalloc(2 * sizeof(int)); src_seq = (char **) ckalloc(2 * sizeof(char *)); src_name = (char **) ckalloc(1 * sizeof(char *)); src_name[0] = (char *) ckalloc(100 * sizeof(char)); fp = ckopen(seqfile, "r"); num_seq = readseq1by1(src_seq, src_name, len_seq, fp); fclose(fp); printf("Genome length: %d\n", len_seq[0]); /* Make reverse complements of input sequences rev(i) --> i + num_seq */ len_seq[1] = len_seq[0]; src_seq[1] = (char *) ckalloc(len_seq[0] * sizeof(char)); for(j = 0; j < len_seq[0]; j ++) { src_seq[1][j] = rev(src_seq[0][len_seq[0] - j - 1]); } /* read in pairwise alignments by Reputer */ align = (ALIGN **) ckalloc(2 * sizeof(ALIGN *)); fp = ckopen(inpfile, "r"); n = readph(align, src_seq, len_seq, fp, min_leg, min_id); fclose(fp); printf("# alignments input: %d.\n", n); /* Write alignments */ fp = ckopen(outfile, "w"); for(m = 0; m < 2; m ++) { n = size_align(align[m]); fwrite(&n, sizeof(int), 1, fp); aln = align[m]; while(aln) { fwrite(&(aln -> reads[1]), sizeof(int), 1, fp); fwrite(&(aln -> mis_match), sizeof(int), 1, fp); fwrite(&(aln -> length), sizeof(int), 1, fp); fwrite(aln -> pos[0], sizeof(int), aln -> length, fp); fwrite(aln -> pos[1], sizeof(int), aln -> length, fp); aln0 = aln -> next; free((void *) aln -> pos[0]); free((void *) aln -> pos[1]); free((void *) aln); aln = aln0; } } fclose(fp); printf("Done...\n"); free((void **) align); for(i = 0; i < 2 * num_seq; i ++) { free((void *) src_seq[i]); } for(i = 0; i < num_seq; i ++) { free((void *) src_name[i]); } free((void **) src_seq); free((void **) src_name); free((void *) len_seq); }
/* * su - switch user id * * su changes the user's ids to the values for the specified user. if * no new user name is specified, "root" or UID 0 is used by default. * * Any additional arguments are passed to the user's shell. In * particular, the argument "-c" will cause the next argument to be * interpreted as a command by the common shell programs. */ int main (int argc, char **argv) { const char *cp; const char *tty = NULL; /* Name of tty SU is run from */ bool doshell = false; bool fakelogin = false; bool amroot = false; uid_t my_uid; struct passwd *pw = NULL; char **envp = environ; char *shellstr = NULL; char *command = NULL; #ifdef USE_PAM char **envcp; int ret; #else /* !USE_PAM */ int err = 0; RETSIGTYPE (*oldsig) (int); int is_console = 0; struct spwd *spwd = 0; #ifdef SU_ACCESS char *oldpass; #endif #endif /* !USE_PAM */ (void) setlocale (LC_ALL, ""); (void) bindtextdomain (PACKAGE, LOCALEDIR); (void) textdomain (PACKAGE); change_environment = true; /* * Get the program name. The program name is used as a prefix to * most error messages. */ Prog = Basename (argv[0]); OPENLOG ("su"); /* * Process the command line arguments. */ { /* * Parse the command line options. */ int option_index = 0; int c; static struct option long_options[] = { {"command", required_argument, NULL, 'c'}, {"help", no_argument, NULL, 'h'}, {"login", no_argument, NULL, 'l'}, {"preserve-environment", no_argument, NULL, 'p'}, {"shell", required_argument, NULL, 's'}, {NULL, 0, NULL, '\0'} }; while ((c = getopt_long (argc, argv, "c:hlmps:", long_options, &option_index)) != -1) { switch (c) { case 'c': command = optarg; break; case 'h': usage (E_SUCCESS); break; case 'l': fakelogin = true; break; case 'm': case 'p': /* This will only have an effect if the target * user do not have a restricted shell, or if * su is called by root. */ change_environment = false; break; case 's': shellstr = optarg; break; default: usage (E_USAGE); /* NOT REACHED */ } } if ((optind < argc) && (strcmp (argv[optind], "-") == 0)) { fakelogin = true; optind++; if ( (optind < argc) && (strcmp (argv[optind], "--") == 0)) { optind++; } } } initenv (); my_uid = getuid (); amroot = (my_uid == 0); /* * Get the tty name. Entries will be logged indicating that the user * tried to change to the named new user from the current terminal. */ tty = ttyname (0); if ((isatty (0) != 0) && (NULL != tty)) { #ifndef USE_PAM is_console = console (tty); #endif } else { /* * Be more paranoid, like su from SimplePAMApps. --marekm */ if (!amroot) { fprintf (stderr, _("%s: must be run from a terminal\n"), Prog); exit (1); } tty = "???"; } /* * The next argument must be either a user ID, or some flag to a * subshell. Pretty sticky since you can't have an argument which * doesn't start with a "-" unless you specify the new user name. * Any remaining arguments will be passed to the user's login shell. */ if ((optind < argc) && ('-' != argv[optind][0])) { STRFCPY (name, argv[optind++]); /* use this login id */ if ((optind < argc) && (strcmp (argv[optind], "--") == 0)) { optind++; } } if ('\0' == name[0]) { /* use default user */ struct passwd *root_pw = getpwnam ("root"); if ((NULL != root_pw) && (0 == root_pw->pw_uid)) { (void) strcpy (name, "root"); } else { root_pw = getpwuid (0); if (NULL == root_pw) { SYSLOG ((LOG_CRIT, "There is no UID 0 user.")); su_failure (tty); } (void) strcpy (name, root_pw->pw_name); } } doshell = (argc == optind); /* any arguments remaining? */ if (NULL != command) { doshell = false; } /* * Get the user's real name. The current UID is used to determine * who has executed su. That user ID must exist. */ pw = get_my_pwent (); if (NULL == pw) { fprintf (stderr, _("%s: Cannot determine your user name.\n"), Prog); SYSLOG ((LOG_WARN, "Cannot determine the user name of the caller (UID %lu)", (unsigned long) my_uid)); su_failure (tty); } STRFCPY (oldname, pw->pw_name); #ifndef USE_PAM #ifdef SU_ACCESS /* * Sort out the password of user calling su, in case needed later * -- chris */ spwd = getspnam (oldname); /* !USE_PAM, no need for xgetspnam */ if (NULL != spwd) { pw->pw_passwd = spwd->sp_pwdp; } oldpass = xstrdup (pw->pw_passwd); #endif /* SU_ACCESS */ #else /* USE_PAM */ ret = pam_start ("su", name, &conv, &pamh); if (PAM_SUCCESS != ret) { SYSLOG ((LOG_ERR, "pam_start: error %d", ret); fprintf (stderr, _("%s: pam_start: error %d\n"), Prog, ret)); exit (1); }