src/main/java/org/ncgr/gwas/PhenoSubjects.java
public static void main(String[] args) throws FileNotFoundException, IOException {
        Options options = new Options();
        CommandLineParser parser = new DefaultParser();
        HelpFormatter formatter = new HelpFormatter();
        CommandLine cmd;

	Option sampleFileOption = new Option("sf", "samplefile", true, "dbGaP samples file (needed if contains mapping from dbGaP_Subject_ID to sample ID used in VCF file)");
	sampleFileOption.setRequired(false);
	options.addOption(sampleFileOption);
        //
	Option sampleVarOption = new Option("sv", "samplevar", true, "study sample ID variable in dbGaP samples file (e.g. SAMPID; required if -sf)");
	sampleVarOption.setRequired(false);
	options.addOption(sampleVarOption);
	//
        Option phenoFileOption = new Option("pf", "phenofile", true, "dbGaP phenotype file");
        phenoFileOption.setRequired(true);
        options.addOption(phenoFileOption);
        //
        Option ccVarOption = new Option("ccv", "casecontrolvar", true, "(comma-separated) case/control variables in dbGaP phenotype file (e.g. ANALYSIS_CAT or pheno_241.2)");
	ccVarOption.setRequired(true);
        options.addOption(ccVarOption);
	// 
        // NOTE: this only allows a single value of case or control in the segregating variable! (Some files have control=1, say, and several case values.)
        Option caseValueOption = new Option("caseval", true, "case value in dbGaP phenotype file (e.g. Case)");
        caseValueOption.setRequired(false);
        options.addOption(caseValueOption);
        //
        Option controlValueOption = new Option("controlval", true, "control value in dbGaP phenotype file (e.g. Control)");
        controlValueOption.setRequired(false);
        options.addOption(controlValueOption);
	//
	Option caseThresholdOption = new Option("casethresh", true, "lower threshold for PheRS value to be considered case");
	caseThresholdOption.setRequired(false);
	options.addOption(caseThresholdOption);
	//
	Option controlThresholdOption = new Option("controlthresh", true, "upper threshold for PheRS value to be considered control (typically 0.0)");
	controlThresholdOption.setRequired(false);
	options.addOption(controlThresholdOption);
	//
	Option diseaseVarOption = new Option("dv", "diseasevar", true, "disease variable in dbGaP phenotype file (e.g. PRIMARY_DISEASE; required if -dn)");
        diseaseVarOption.setRequired(false);
        options.addOption(diseaseVarOption);
	//
	Option diseaseNameOption = new Option("dn", "diseasename", true, "desired case disease name in dbGaP phenotype file (e.g. Schizophrenia; required if -dv)");
        diseaseNameOption.setRequired(false);
        options.addOption(diseaseNameOption);
	//
	Option desiredSexOption = new Option("ds", "desiredsex", true, "phenotype value of desired sex (e.g. M or 1)");
	desiredSexOption.setRequired(false);
	options.addOption(desiredSexOption);
	//
	Option desiredRaceOption = new Option("dr", "desiredrace", true, "phenotype value of desired race (e.g. W)");
	desiredRaceOption.setRequired(false);
	options.addOption(desiredRaceOption);
	//
	Option maxCasesOption = new Option("mc", "maxcases", true, "maximum number of cases for cases=controls output (and no unknowns)");
	maxCasesOption.setRequired(false);
	options.addOption(maxCasesOption);
	//
	Option excludedSubjectsOption = new Option("es", "excludedsubjects", true, "exclude subjects listed in given file");
	excludedSubjectsOption.setRequired(false);
	options.addOption(excludedSubjectsOption);
	//
	Option includedSubjectsOption = new Option("is", "includedsubjects", true, "include only subjects listed in given file");
	includedSubjectsOption.setRequired(false);
	options.addOption(includedSubjectsOption);
	
        try {
            cmd = parser.parse(options, args);
        } catch (ParseException e) {
            System.err.println(e.getMessage());
            formatter.printHelp("PhenoSubjects", options);
            System.exit(1);
            return;
        }

        // spit out help if nothing supplied
        if (cmd.getOptions().length==0) {
            formatter.printHelp("PhenoSubjects", options);
            System.exit(1);
            return;
        }

	PhenoSubjects ps = new PhenoSubjects();

        // comma-separated case-control variables
	ps.ccVars = cmd.getOptionValue("casecontrolvar").split(",");
        
	if (cmd.hasOption("caseval") && cmd.hasOption("controlval")) {
	    ps.caseValue = cmd.getOptionValue("caseval");
	    ps.controlValue = cmd.getOptionValue("controlval");
	} else if (cmd.hasOption("casethresh") && cmd.hasOption("controlthresh")) {
	    ps.caseThreshold = Double.parseDouble(cmd.getOptionValue("casethresh"));
	    ps.controlThreshold = Double.parseDouble(cmd.getOptionValue("controlthresh"));
	} else {
	    System.err.println("ERROR: you must supply both -caseval and -controlval OR supply both -casethresh and -controlthresh");
	    System.exit(1);
	}
	
	ps.sampleVar = cmd.getOptionValue("samplevar");

	if (cmd.hasOption("diseasevar")) {
	    ps.diseaseVar = cmd.getOptionValue("diseasevar");
	    ps.diseaseName = cmd.getOptionValue("diseasename");
	}

	if (cmd.hasOption("desiredsex")) {
	    ps.desiredSexValue = cmd.getOptionValue("desiredsex");
	}

	if (cmd.hasOption("desiredrace")) {
	    ps.desiredRaceValue = cmd.getOptionValue("desiredrace");
	}

	// max case/controls to output
	if (cmd.hasOption("maxcases")) {
	    ps.maxCases = Integer.parseInt(cmd.getOptionValue("maxcases"));
	}

	// can only do the maxCases thing with a single disease
	if (ps.ccVars.length>1 && ps.maxCases>0) {
	    System.err.println("ERROR: you may only specify a single disease with maxcases>0");
	    System.exit(1);
	}

	// get the List of exluded samples
	if (cmd.hasOption("excludedsubjects")) {
	    ps.loadExcludedSamples(cmd.getOptionValue("excludedsubjects"));
	}

	// get the List of included samples
	if (cmd.hasOption("includedsubjects")) {
	    ps.loadIncludedSamples(cmd.getOptionValue("includedsubjects"));
	}

	// get the sample ID map
	if (cmd.hasOption("samplefile")) {
	    ps.samplefilename = cmd.getOptionValue("samplefile");
	    ps.loadSampleIdMap();
	}

	// get the subject status map from the pheno file
	ps.phenofilename = cmd.getOptionValue("phenofile");
	ps.loadSubjectStatus();

        // two-column labels file output
	ps.printLabelsFile();
    }
/**
     * Main class outputs a tab-delimited list of the subject IDs and disease or case/control status.
     */
Main class outputs a tab-delimited list of the subject IDs and disease or case/control status.
Main class outputs a tab - delimited list of the subject IDs and disease or case / control status .
public static void main(String[] args) throws FileNotFoundException, IOException {
        Options options = new Options();
        CommandLineParser parser = new DefaultParser();
        HelpFormatter formatter = new HelpFormatter();
        CommandLine cmd;
	Option sampleFileOption = new Option("sf", "samplefile", true, "dbGaP samples file (needed if contains mapping from dbGaP_Subject_ID to sample ID used in VCF file)");
	sampleFileOption.setRequired(false);
	options.addOption(sampleFileOption);
	Option sampleVarOption = new Option("sv", "samplevar", true, "study sample ID variable in dbGaP samples file (e.g. SAMPID; required if -sf)");
	sampleVarOption.setRequired(false);
	options.addOption(sampleVarOption);
        Option phenoFileOption = new Option("pf", "phenofile", true, "dbGaP phenotype file");
        phenoFileOption.setRequired(true);
        options.addOption(phenoFileOption);
        Option ccVarOption = new Option("ccv", "casecontrolvar", true, "(comma-separated) case/control variables in dbGaP phenotype file (e.g. ANALYSIS_CAT or pheno_241.2)");
	ccVarOption.setRequired(true);
        options.addOption(ccVarOption);
         NOTE: this only allows a single value of case or control in the segregating variable! (Some files have control=1, say, and several case values.)
        Option caseValueOption = new Option("caseval", true, "case value in dbGaP phenotype file (e.g. Case)");
        caseValueOption.setRequired(false);
        options.addOption(caseValueOption);
        Option controlValueOption = new Option("controlval", true, "control value in dbGaP phenotype file (e.g. Control)");
        controlValueOption.setRequired(false);
        options.addOption(controlValueOption);
	Option caseThresholdOption = new Option("casethresh", true, "lower threshold for PheRS value to be considered case");
	caseThresholdOption.setRequired(false);
	options.addOption(caseThresholdOption);
	Option controlThresholdOption = new Option("controlthresh", true, "upper threshold for PheRS value to be considered control (typically 0.0)");
	controlThresholdOption.setRequired(false);
	options.addOption(controlThresholdOption);
	Option diseaseVarOption = new Option("dv", "diseasevar", true, "disease variable in dbGaP phenotype file (e.g. PRIMARY_DISEASE; required if -dn)");
        diseaseVarOption.setRequired(false);
        options.addOption(diseaseVarOption);
	Option diseaseNameOption = new Option("dn", "diseasename", true, "desired case disease name in dbGaP phenotype file (e.g. Schizophrenia; required if -dv)");
        diseaseNameOption.setRequired(false);
        options.addOption(diseaseNameOption);
	Option desiredSexOption = new Option("ds", "desiredsex", true, "phenotype value of desired sex (e.g. M or 1)");
	desiredSexOption.setRequired(false);
	options.addOption(desiredSexOption);
	Option desiredRaceOption = new Option("dr", "desiredrace", true, "phenotype value of desired race (e.g. W)");
	desiredRaceOption.setRequired(false);
	options.addOption(desiredRaceOption);
	Option maxCasesOption = new Option("mc", "maxcases", true, "maximum number of cases for cases=controls output (and no unknowns)");
	maxCasesOption.setRequired(false);
	options.addOption(maxCasesOption);
	Option excludedSubjectsOption = new Option("es", "excludedsubjects", true, "exclude subjects listed in given file");
	excludedSubjectsOption.setRequired(false);
	options.addOption(excludedSubjectsOption);
	Option includedSubjectsOption = new Option("is", "includedsubjects", true, "include only subjects listed in given file");
	includedSubjectsOption.setRequired(false);
	options.addOption(includedSubjectsOption);
        try {
            cmd = parser.parse(options, args);
        } catch (ParseException e) {
            System.err.println(e.getMessage());
            formatter.printHelp("PhenoSubjects", options);
            System.exit(1);
            return;
        }
         spit out help if nothing supplied
        if (cmd.getOptions().length==0) {
            formatter.printHelp("PhenoSubjects", options);
            System.exit(1);
            return;
        }
	PhenoSubjects ps = new PhenoSubjects();
         comma-separated case-control variables
	ps.ccVars = cmd.getOptionValue("casecontrolvar").split(",");
	if (cmd.hasOption("caseval") && cmd.hasOption("controlval")) {
	    ps.caseValue = cmd.getOptionValue("caseval");
	    ps.controlValue = cmd.getOptionValue("controlval");
	} else if (cmd.hasOption("casethresh") && cmd.hasOption("controlthresh")) {
	    ps.caseThreshold = Double.parseDouble(cmd.getOptionValue("casethresh"));
	    ps.controlThreshold = Double.parseDouble(cmd.getOptionValue("controlthresh"));
	} else {
	    System.err.println("ERROR: you must supply both -caseval and -controlval OR supply both -casethresh and -controlthresh");
	    System.exit(1);
	}
	ps.sampleVar = cmd.getOptionValue("samplevar");
	if (cmd.hasOption("diseasevar")) {
	    ps.diseaseVar = cmd.getOptionValue("diseasevar");
	    ps.diseaseName = cmd.getOptionValue("diseasename");
	}
	if (cmd.hasOption("desiredsex")) {
	    ps.desiredSexValue = cmd.getOptionValue("desiredsex");
	}
	if (cmd.hasOption("desiredrace")) {
	    ps.desiredRaceValue = cmd.getOptionValue("desiredrace");
	}
	 max case/controls to output
	if (cmd.hasOption("maxcases")) {
	    ps.maxCases = Integer.parseInt(cmd.getOptionValue("maxcases"));
	}
	 can only do the maxCases thing with a single disease
	if (ps.ccVars.length>1 && ps.maxCases>0) {
	    System.err.println("ERROR: you may only specify a single disease with maxcases>0");
	    System.exit(1);
	}
	 get the List of exluded samples
	if (cmd.hasOption("excludedsubjects")) {
	    ps.loadExcludedSamples(cmd.getOptionValue("excludedsubjects"));
	}
	 get the List of included samples
	if (cmd.hasOption("includedsubjects")) {
	    ps.loadIncludedSamples(cmd.getOptionValue("includedsubjects"));
	}
	 get the sample ID map
	if (cmd.hasOption("samplefile")) {
	    ps.samplefilename = cmd.getOptionValue("samplefile");
	    ps.loadSampleIdMap();
	}
	 get the subject status map from the pheno file
	ps.phenofilename = cmd.getOptionValue("phenofile");
	ps.loadSubjectStatus();
         two-column labels file output
	ps.printLabelsFile();
    }
public static void main ( String [ ] args ) throws FileNotFoundException , IOException { Options options = new Options ( ) ; CommandLineParser parser = new DefaultParser ( ) ; HelpFormatter formatter = new HelpFormatter ( ) ; CommandLine cmd ; Option sampleFileOption = new Option ( "sf" , "samplefile" , true , "dbGaP samples file (needed if contains mapping from dbGaP_Subject_ID to sample ID used in VCF file)" ) ; sampleFileOption . setRequired ( false ) ; options . addOption ( sampleFileOption ) ; Option sampleVarOption = new Option ( "sv" , "samplevar" , true , "study sample ID variable in dbGaP samples file (e.g. SAMPID; required if -sf)" ) ; sampleVarOption . setRequired ( false ) ; options . addOption ( sampleVarOption ) ; Option phenoFileOption = new Option ( "pf" , "phenofile" , true , "dbGaP phenotype file" ) ; phenoFileOption . setRequired ( true ) ; options . addOption ( phenoFileOption ) ; Option ccVarOption = new Option ( "ccv" , "casecontrolvar" , true , "(comma-separated) case/control variables in dbGaP phenotype file (e.g. ANALYSIS_CAT or pheno_241.2)" ) ; ccVarOption . setRequired ( true ) ; options . addOption ( ccVarOption ) ; Option caseValueOption = new Option ( "caseval" , true , "case value in dbGaP phenotype file (e.g. Case)" ) ; caseValueOption . setRequired ( false ) ; options . addOption ( caseValueOption ) ; Option controlValueOption = new Option ( "controlval" , true , "control value in dbGaP phenotype file (e.g. Control)" ) ; controlValueOption . setRequired ( false ) ; options . addOption ( controlValueOption ) ; Option caseThresholdOption = new Option ( "casethresh" , true , "lower threshold for PheRS value to be considered case" ) ; caseThresholdOption . setRequired ( false ) ; options . addOption ( caseThresholdOption ) ; Option controlThresholdOption = new Option ( "controlthresh" , true , "upper threshold for PheRS value to be considered control (typically 0.0)" ) ; controlThresholdOption . setRequired ( false ) ; options . addOption ( controlThresholdOption ) ; Option diseaseVarOption = new Option ( "dv" , "diseasevar" , true , "disease variable in dbGaP phenotype file (e.g. PRIMARY_DISEASE; required if -dn)" ) ; diseaseVarOption . setRequired ( false ) ; options . addOption ( diseaseVarOption ) ; Option diseaseNameOption = new Option ( "dn" , "diseasename" , true , "desired case disease name in dbGaP phenotype file (e.g. Schizophrenia; required if -dv)" ) ; diseaseNameOption . setRequired ( false ) ; options . addOption ( diseaseNameOption ) ; Option desiredSexOption = new Option ( "ds" , "desiredsex" , true , "phenotype value of desired sex (e.g. M or 1)" ) ; desiredSexOption . setRequired ( false ) ; options . addOption ( desiredSexOption ) ; Option desiredRaceOption = new Option ( "dr" , "desiredrace" , true , "phenotype value of desired race (e.g. W)" ) ; desiredRaceOption . setRequired ( false ) ; options . addOption ( desiredRaceOption ) ; Option maxCasesOption = new Option ( "mc" , "maxcases" , true , "maximum number of cases for cases=controls output (and no unknowns)" ) ; maxCasesOption . setRequired ( false ) ; options . addOption ( maxCasesOption ) ; Option excludedSubjectsOption = new Option ( "es" , "excludedsubjects" , true , "exclude subjects listed in given file" ) ; excludedSubjectsOption . setRequired ( false ) ; options . addOption ( excludedSubjectsOption ) ; Option includedSubjectsOption = new Option ( "is" , "includedsubjects" , true , "include only subjects listed in given file" ) ; includedSubjectsOption . setRequired ( false ) ; options . addOption ( includedSubjectsOption ) ; try { cmd = parser . parse ( options , args ) ; } catch ( ParseException e ) { System . err . println ( e . getMessage ( ) ) ; formatter . printHelp ( "PhenoSubjects" , options ) ; System . exit ( 1 ) ; return ; } if ( cmd . getOptions ( ) . length == 0 ) { formatter . printHelp ( "PhenoSubjects" , options ) ; System . exit ( 1 ) ; return ; } PhenoSubjects ps = new PhenoSubjects ( ) ; ps . ccVars = cmd . getOptionValue ( "casecontrolvar" ) . split ( "," ) ; if ( cmd . hasOption ( "caseval" ) && cmd . hasOption ( "controlval" ) ) { ps . caseValue = cmd . getOptionValue ( "caseval" ) ; ps . controlValue = cmd . getOptionValue ( "controlval" ) ; } else if ( cmd . hasOption ( "casethresh" ) && cmd . hasOption ( "controlthresh" ) ) { ps . caseThreshold = Double . parseDouble ( cmd . getOptionValue ( "casethresh" ) ) ; ps . controlThreshold = Double . parseDouble ( cmd . getOptionValue ( "controlthresh" ) ) ; } else { System . err . println ( "ERROR: you must supply both -caseval and -controlval OR supply both -casethresh and -controlthresh" ) ; System . exit ( 1 ) ; } ps . sampleVar = cmd . getOptionValue ( "samplevar" ) ; if ( cmd . hasOption ( "diseasevar" ) ) { ps . diseaseVar = cmd . getOptionValue ( "diseasevar" ) ; ps . diseaseName = cmd . getOptionValue ( "diseasename" ) ; } if ( cmd . hasOption ( "desiredsex" ) ) { ps . desiredSexValue = cmd . getOptionValue ( "desiredsex" ) ; } if ( cmd . hasOption ( "desiredrace" ) ) { ps . desiredRaceValue = cmd . getOptionValue ( "desiredrace" ) ; } if ( cmd . hasOption ( "maxcases" ) ) { ps . maxCases = Integer . parseInt ( cmd . getOptionValue ( "maxcases" ) ) ; } if ( ps . ccVars . length > 1 && ps . maxCases > 0 ) { System . err . println ( "ERROR: you may only specify a single disease with maxcases>0" ) ; System . exit ( 1 ) ; } if ( cmd . hasOption ( "excludedsubjects" ) ) { ps . loadExcludedSamples ( cmd . getOptionValue ( "excludedsubjects" ) ) ; } if ( cmd . hasOption ( "includedsubjects" ) ) { ps . loadIncludedSamples ( cmd . getOptionValue ( "includedsubjects" ) ) ; } if ( cmd . hasOption ( "samplefile" ) ) { ps . samplefilename = cmd . getOptionValue ( "samplefile" ) ; ps . loadSampleIdMap ( ) ; } ps . phenofilename = cmd . getOptionValue ( "phenofile" ) ; ps . loadSubjectStatus ( ) ; ps . printLabelsFile ( ) ; }
Main class outputs a tab-delimited list of the subject IDs and disease or case/control status.
Main class outputs a tab - delimited list of the subject IDs and disease or case / control status .
// // // //  // NOTE: this only allows a single value of case or control in the segregating variable! (Some files have control=1, say, and several case values.) // // // // // // // // // // // spit out help if nothing supplied // comma-separated case-control variables // max case/controls to output // can only do the maxCases thing with a single disease // get the List of exluded samples // get the List of included samples // get the sample ID map // get the subject status map from the pheno file // two-column labels file output