示例#1
0
int main()
{
    int i;
    int sum=0;
    char arglist[100][256];
    char* buf=NULL;

//  signal(SIGTTIN,SIG_IGN);   //忽略终端STOP信号
//  signal(SIGTTOU,SIG_IGN);
//  signal(SIGTSTP,SIG_IGN);
//  signal(SIGHUP,SIG_IGN);

    buf=(char*)malloc(sizeof(char)*256);
    while(1)
    {
        memset(buf,0,256);
        print_shell();
        input_command(buf);
        if(strcmp(buf,"exit")==0||strcmp(buf,"logout")==0)
        break;
        for(i=0;i<100;i++)
        arglist[i][0]='\0';
        sum=0;
        explain_command(buf,&sum,arglist);
        do_command(sum,arglist);


    }

    if(buf!=NULL)
    free(buf);
    exit(0);

}
示例#2
0
static SRM_binning option_assign(int argc, char **argv)
	{ SRM_binning args;
	  int c,option_index;
	  static struct option long_options[] =
			{ {"multiplicity", required_argument ,0,0},
			  {"binOut",required_argument,0,2},
			  {"inb",required_argument,0,3},
			  {"perm",no_argument,0,4},
			  {0,0,0,0} 
			};
	  char *insert=NULL;

	  args.multple = 2.0;
	  args.quantile = 0.95;
	  args.bin_size = 100;
	  args.win_size = 200;
	  args.output_file = NULL;
	  args.binout_file = NULL;
	  args.inbin_file = NULL;
	  args.outlier_file=NULL;
	  args.autoselect_lambda = 0;
	  args.FP = 1;
	  args.B = 10;
	  args.fdr = 0;
	  args.lambda = 2;
	  args.paired = 0;
	  args.tumor_file = NULL;
	  args.normal_file = NULL;
	  args.insert = 220;
	  args.sd = 20;
	  args.tumor_freq = 0.5;
	  args.resampling = 1;
	
	  args.in_tmor = NULL;
	  args.in_nml = NULL;
	  args.output = NULL;
	  args.inbin = NULL;
	  args.outbin = NULL;
	  args.outlier = NULL;

	  while((c=getopt_long(argc,argv,"2q:b:w:o:R:hf:p:B:l:",long_options,&option_index))!=-1){
		switch(c){
			case 0:
				args.multple = atoi(optarg);
				if(args.multple<1.0) { fprintf(stderr,"Error,multiplicity must be larger than or equal to 1.0\n"); exit(1);}
				break;
			case 2:
				args.binout_file = strdup(optarg);
				break;
			case 3: 
				args.inbin_file = strdup(optarg);
				break;
			case 4: args.resampling = 0;
				break;
			case 'l': 
				args.lambda = atof(optarg);
				if(args.lambda<=0.0) { fprintf(stderr,"Parameter misspecification: Lambda must be positive number.\n"); exit(1);}
				break;
                        case 'f':
                                args.FP = atof(optarg);
                                args.autoselect_lambda = 1;
                                if(args.FP<=0.0) {fprintf(stderr,"Expected number of type I error must be postive\n");exit(1);}
                                break;

			case 'I':
				insert = strdup(optarg);
				args.paired = 1;
				break;
			case 'q':
				args.quantile = atof(optarg);
				if(args.quantile<=0.0 || args.quantile>1.0)  { fprintf(stderr,"Quantile should be between 0 and 1.\n"); exit(1);}
				break;
			case 'b':
				args.bin_size = atoi(optarg);
				if(args.bin_size<1) {fprintf(stderr,"Bin size should be at least 1.\n");exit(1);}
				break;
			case 'w':
				args.win_size = atoi(optarg);
				if(args.win_size<1) {fprintf(stderr,"The window size must be positive.\n");exit(1);}
				break;
			case '2':
				args.paired = 1;
				break;
			case 'o':
				args.output_file = strdup(optarg);
				break;
			case 'R':
				args.outlier_file = strdup(optarg);
                        case 'p':
                                args.tumor_freq = atof(optarg);
                                if(args.tumor_freq<0.0||args.tumor_freq>=1.0){fprintf(stderr,"The probabilty of a read being a tumor read must be between 0 and 1\n");exit(1);}
                                args.fdr = 1;
                                break;
                        case 'B':
                                args.B = atoi(optarg);
                                if(args.B<=0) {fprintf(stderr,"The option -B must be a positve number\n");exit(1);}
                                break;
			case 'h': 
				explain_command(argv);
				exit(0);
			case '?': /* getopt_long already printed an error message. */
				exit(1);
				break;
			default:
				abort (); 
			}
		}

        if (argc - optind!=2&&args.inbin_file==NULL){
           	explain_command(argv); exit(1);
         	}

	if(args.inbin_file==NULL){
		args.tumor_file = strdup(argv[optind]);
		args.normal_file = strdup(argv[optind+1]);

	        args.in_tmor = fopen(args.tumor_file,"r");
	        if(args.in_tmor == NULL)
	                { fprintf(stderr,"fopen %s: %s\n", args.tumor_file,strerror(errno));
        	          exit(1);
	                }

	        args.in_nml = fopen(args.normal_file,"r");
	        if(args.in_nml == NULL)
        	        { fprintf(stderr,"fopen %s: %s\n", args.normal_file,strerror(errno));
	                  exit(1);
	                }

		}
	else{
		args.inbin =  fopen(args.inbin_file,"r");
		if(args.inbin==NULL){
			fprintf(stderr,"fopen %s: %s\n", args.inbin_file,strerror(errno));
                        exit(1);
			}
		}
	

        if(args.outlier_file!=NULL) {
                args.outlier = fopen(args.outlier_file,"w");
                if(args.outlier==NULL) {fprintf(stderr,"fopen %s: %s\n",args.outlier_file,strerror(errno));exit(1);}
                }

        if(args.output_file!=NULL){
                args.output = fopen(args.output_file,"w");
                if(args.output==NULL) { fprintf(stderr,"fopen %s: cannot create the file.\n",args.output_file); exit(1);}
                }else{
		args.output = stdout;
		}

        if(args.binout_file!=NULL){
                args.outbin = fopen(args.binout_file,"w");
                if(args.outbin==NULL) { fprintf(stderr,"fopen %s: cannot create the file.\n",args.binout_file); exit(1);}
                }

	if(insert!=NULL){
		char *substr;
		substr = strtok(insert,",");
		args.insert = atoi(substr);
		substr=strtok(NULL,",");
		if(substr==NULL){fprintf(stderr,"Incorrect format for option -I\n");exit(1);}
		args.sd = atoi(substr);
		if(args.insert<0||args.sd<0) {fprintf(stderr,"Error, insert size and its standard deviaiton must be positive\n");}
		}

	set_lambda(args.lambda);

	return args;

	}