1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
/*
* Copyright (C) 2014-2021 Brian L. Browning
*
* This file is part of Beagle
*
* Beagle is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Beagle is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package bref;
import blbutil.Const;
import blbutil.FileUtil;
import blbutil.SampleFileIt;
import blbutil.Utilities;
import java.io.File;
import java.io.PrintWriter;
import vcf.RefGTRec;
import vcf.VcfWriter;
/**
* <p>Class {@code UnBref3} converts files in bref version 3 format
* into VCF format.
* </p>
* <p>Instances of class {@code UnBref3} are not thread-safe.</p>
*
* @author Brian L. Browning {@code <browning@uw.edu>}
*/
public class UnBref3 {
private static final String program = "unbref3.22Jul22.46e.jar";
/**
* The {@code main()} method is the entry point to the bref program.
* See the usage() method for usage instructions.
*
* @param args the command line arguments
*/
public static void main(String[] args) {
if (args.length>1) {
exit(usage());
}
if (args.length==1 && args[0].equalsIgnoreCase("help")) {
exit(usage());
}
String fileName = args.length==0 ? null : args[0];
writeVcf(fileName);
}
private static void exit(String msg) {
System.out.println(usage());
Utilities.exit(msg);
}
private static void writeVcf(String fileName) {
try (PrintWriter out = FileUtil.stdOutPrintWriter();
SampleFileIt<RefGTRec> brefIt = bref3It(fileName)) {
if (brefIt.hasNext()) {
RefGTRec ve = brefIt.next();
VcfWriter.writeMetaLinesGT(ve.samples().ids(), program, out);
out.println(ve.toString());
}
while (brefIt.hasNext()) {
out.println(brefIt.next().toString());
}
}
}
private static SampleFileIt<RefGTRec> bref3It(String fileName) {
File file = fileName==null ? null : new File(fileName);
return new Bref3It(file);
}
private static String usage() {
StringBuilder sb = new StringBuilder(500);
sb.append("usage:");
sb.append(Const.nl);
sb.append(" java -jar ");
sb.append(program);
sb.append(" help");
sb.append(Const.nl);
sb.append(Const.nl);
sb.append(" java -jar ");
sb.append(program);
sb.append(" [bref3] > [vcf])");
sb.append(Const.nl);
sb.append(Const.nl);
sb.append(" cat [bref3] | java -jar ");
sb.append(program);
sb.append(" > [vcf]");
sb.append(Const.nl);
sb.append(Const.nl);
sb.append("where");
sb.append(Const.nl);
sb.append(" [bref3] = the input bref3 file");
sb.append(Const.nl);
sb.append(" [vcf] = the ouput VCF file");
sb.append(Const.nl);
return sb.toString();
}
}
|