private static VcfHeader InternalReadHeader(StreamReader reader) { VcfHeader header = null; string cline = null; while ((cline = reader.ReadLine()) != null) { string line = cline.Trim(); if (line.StartsWith("##")) { if (line.StartsWith("##INFO=<")) { //parse info line, to be implemented } else if (line.StartsWith("##FORMAT=<")) { //parse format line, to be implemented } else if (line.StartsWith("##FILTER=<")) { //parse filter line, to be implemented } else if (line.StartsWith("##ALT=<")) { //parse alt line, to be implemented } else { //parse other meta information line, to be implemented } } else if (line.StartsWith("#CHROM")) { header = new VcfHeader(line.Split('\t')); break; } else if (header == null && !line.StartsWith("#")) { throw new Exception("Invalid VCF file. Header was not found before the data lines."); } else { break; } } if (header == null) { throw new Exception("Invalid VCF file: header line was not found."); } return(header); }
private bool Load(string fileName) { if (this.gzip) //I should use BGZF stream for compressed vcf.gz, use standard gzip reader here for demo purpose { this.stream = new GZipStream(File.OpenRead(fileName), CompressionMode.Decompress); } else { this.stream = File.OpenRead(fileName); } this.vcfReader = new StreamReader(this.stream); //read header of vcf file header = InternalReadHeader(this.vcfReader); this.firstLinePosition = this.stream.Position; return(true); }