src/main/java/org/ncgr/gwas/PhenoSubjects.java
void printLabelsFile() {
	String header = "sample";
        for (int j=0; j<ccVars.length; j++)  {
            header += "\t"+ccVars[j];
        }
        System.out.println(header);
	// output samples to reach # cases = maxCases = # controls
	if (maxCases>0) {
	    // usually far less cases than controls, so let's pick them out from each batch individually
	    List<String> cases = new LinkedList<>();
	    List<String> controls = new LinkedList<>();
	    for (String sampleId : subjectStatus.keySet()) {
		if (includedSamples.size()>0 && !includedSamples.contains(sampleId)) continue;
		if (excludedSamples.contains(sampleId)) continue;
		String[] status = subjectStatus.get(sampleId);
		if (status[0].equals("case")) {
		    cases.add(sampleId);
		} else if (status[0].equals("ctrl")) {
		    controls.add(sampleId);
		}
	    }
	    // check that we've got >= maxCases
	    if (cases.size()<maxCases) {
		System.err.println("ERROR: cases.size()="+cases.size()+" < maxCases="+maxCases);
		System.exit(1);
	    }
	    if (controls.size()<maxCases) {
		System.err.println("ERROR: controls.size()="+controls.size()+" < maxCases="+maxCases);
		System.exit(1);
	    }
	    // randomly select and output cases
	    int caseCount = 0;
	    while (caseCount<maxCases) {
		Optional<String> optional = cases.stream().skip((int)(cases.size()*Math.random())).findFirst();
		if (optional.isPresent()) {
		    caseCount++;
		    String sampleId = optional.get();
		    System.out.println(sampleId+"\t"+"case");
		    boolean removed = cases.remove(sampleId);
		}
	    }
	    // randomly select and output cases
	    int ctrlCount = 0;
	    while (ctrlCount<maxCases) {
		Optional<String> optional = controls.stream().skip((int)(controls.size()*Math.random())).findFirst();
		if (optional.isPresent()) {
		    ctrlCount++;
		    String sampleId = optional.get();
		    System.out.println(sampleId+"\t"+"ctrl");
		    boolean removed = controls.remove(sampleId);
		}
	    }
	} else {
	    // output all samples except those to be ignored
	    for (String sampleId : subjectStatus.keySet()) {
		if (!excludedSamples.contains(sampleId)) {
		    String[] status = subjectStatus.get(sampleId);
		    String output = sampleId;
		    for (int j=0; j<status.length; j++) {
			output += "\t"+status[j];
		    }
		    System.out.println(output);
		}
	    }
	}
    }
/**
     * Print a two-column labels file to STDOUT.
     */
Print a two-column labels file to STDOUT.
Print a two - column labels file to STDOUT .
void printLabelsFile() {
	String header = "sample";
        for (int j=0; j<ccVars.length; j++)  {
            header += "\t"+ccVars[j];
        }
        System.out.println(header);
	if (maxCases>0) {
	    List<String> cases = new LinkedList<>();
	    List<String> controls = new LinkedList<>();
	    for (String sampleId : subjectStatus.keySet()) {
		if (includedSamples.size()>0 && !includedSamples.contains(sampleId)) continue;
		if (excludedSamples.contains(sampleId)) continue;
		String[] status = subjectStatus.get(sampleId);
		if (status[0].equals("case")) {
		    cases.add(sampleId);
		} else if (status[0].equals("ctrl")) {
		    controls.add(sampleId);
		}
	    }
	    if (cases.size()<maxCases) {
		System.err.println("ERROR: cases.size()="+cases.size()+" < maxCases="+maxCases);
		System.exit(1);
	    }
	    if (controls.size()<maxCases) {
		System.err.println("ERROR: controls.size()="+controls.size()+" < maxCases="+maxCases);
		System.exit(1);
	    }
	    int caseCount = 0;
	    while (caseCount<maxCases) {
		Optional<String> optional = cases.stream().skip((int)(cases.size()*Math.random())).findFirst();
		if (optional.isPresent()) {
		    caseCount++;
		    String sampleId = optional.get();
		    System.out.println(sampleId+"\t"+"case");
		    boolean removed = cases.remove(sampleId);
		}
	    }
	    int ctrlCount = 0;
	    while (ctrlCount<maxCases) {
		Optional<String> optional = controls.stream().skip((int)(controls.size()*Math.random())).findFirst();
		if (optional.isPresent()) {
		    ctrlCount++;
		    String sampleId = optional.get();
		    System.out.println(sampleId+"\t"+"ctrl");
		    boolean removed = controls.remove(sampleId);
		}
	    }
	} else {
	    for (String sampleId : subjectStatus.keySet()) {
		if (!excludedSamples.contains(sampleId)) {
		    String[] status = subjectStatus.get(sampleId);
		    String output = sampleId;
		    for (int j=0; j<status.length; j++) {
			output += "\t"+status[j];
		    }
		    System.out.println(output);
		}
	    }
	}
    }
void printLabelsFile ( ) { String header = "sample" ; for ( int j = 0 ; j < ccVars . length ; j ++ ) { header += "\t" + ccVars [ j ] ; } System . out . println ( header ) ; if ( maxCases > 0 ) { List < String > cases = new LinkedList < > ( ) ; List < String > controls = new LinkedList < > ( ) ; for ( String sampleId : subjectStatus . keySet ( ) ) { if ( includedSamples . size ( ) > 0 && ! includedSamples . contains ( sampleId ) ) continue ; if ( excludedSamples . contains ( sampleId ) ) continue ; String [ ] status = subjectStatus . get ( sampleId ) ; if ( status [ 0 ] . equals ( "case" ) ) { cases . add ( sampleId ) ; } else if ( status [ 0 ] . equals ( "ctrl" ) ) { controls . add ( sampleId ) ; } } if ( cases . size ( ) < maxCases ) { System . err . println ( "ERROR: cases.size()=" + cases . size ( ) + " < maxCases=" + maxCases ) ; System . exit ( 1 ) ; } if ( controls . size ( ) < maxCases ) { System . err . println ( "ERROR: controls.size()=" + controls . size ( ) + " < maxCases=" + maxCases ) ; System . exit ( 1 ) ; } int caseCount = 0 ; while ( caseCount < maxCases ) { Optional < String > optional = cases . stream ( ) . skip ( ( int ) ( cases . size ( ) * Math . random ( ) ) ) . findFirst ( ) ; if ( optional . isPresent ( ) ) { caseCount ++ ; String sampleId = optional . get ( ) ; System . out . println ( sampleId + "\t" + "case" ) ; boolean removed = cases . remove ( sampleId ) ; } } int ctrlCount = 0 ; while ( ctrlCount < maxCases ) { Optional < String > optional = controls . stream ( ) . skip ( ( int ) ( controls . size ( ) * Math . random ( ) ) ) . findFirst ( ) ; if ( optional . isPresent ( ) ) { ctrlCount ++ ; String sampleId = optional . get ( ) ; System . out . println ( sampleId + "\t" + "ctrl" ) ; boolean removed = controls . remove ( sampleId ) ; } } } else { for ( String sampleId : subjectStatus . keySet ( ) ) { if ( ! excludedSamples . contains ( sampleId ) ) { String [ ] status = subjectStatus . get ( sampleId ) ; String output = sampleId ; for ( int j = 0 ; j < status . length ; j ++ ) { output += "\t" + status [ j ] ; } System . out . println ( output ) ; } } } }
Print a two-column labels file to STDOUT.
Print a two - column labels file to STDOUT .
// output samples to reach # cases = maxCases = # controls // usually far less cases than controls, so let's pick them out from each batch individually // check that we've got >= maxCases // randomly select and output cases // randomly select and output cases // output all samples except those to be ignored