protected override void BeginProcessing() { Path = IO.GetAbsolutePath(this, Path); if (AsEnumerator) { var reader = new StreamReader(Path, Encoding.UTF8); var e = CTFTools.GetSampleReader(reader).GetEnumerator(); var psobj = new PSObject(e); psobj.Properties.Add(new PSNoteProperty("Reader", reader)); WriteObject(psobj); } else { using (var reader = new StreamReader(Path, Encoding.UTF8)) { var e = CTFTools.GetSampleReader(reader); foreach (var sample in e) { WriteObject(sample); if (sample.SequenceCount == ReadCount) { break; } } } } }
private int GetTotalSeqCount() { if (_totalSeqCount != -1) { return(_totalSeqCount); } using (var reader = new StreamReader(Path, Encoding.UTF8)) { _totalSeqCount = CTFTools.CountLines(reader).Item2; return(_totalSeqCount); } }
protected override void BeginProcessing() { Path = IO.GetAbsolutePath(this, Path); // Count sequeneces Tuple <int, int> lines; using (var reader = new StreamReader(Path, Encoding.UTF8)) { lines = CTFTools.CountLines(reader); } WriteObject(new CTFLineInfo() { Lines = lines.Item1, Sequences = lines.Item2 }); }
protected override void BeginProcessing() { // Convert ratios into sequence counts if (ParameterSetName == "ratios") { SequenceCounts = new int[Ratios.Length]; var total = GetTotalSeqCount(); for (var i = 0; i < Ratios.Length; ++i) { if (Ratios[i] == -1) { continue; } SequenceCounts[i] = (int)(Ratios[i] * total); } } // Fix sequence counts if (OutFiles.Length == SequenceCounts.Length) { var total = GetTotalSeqCount(); for (var i = 0; i < SequenceCounts.Length; ++i) { if (SequenceCounts[i] == -1) { SequenceCounts[i] = total - (SequenceCounts.Sum() + 1); break; } } } else if (OutFiles.Length == SequenceCounts.Length + 1) { var lastCount = GetTotalSeqCount() - SequenceCounts.Sum(); var newSeqs = new int[SequenceCounts.Length + 1]; SequenceCounts.CopyTo(newSeqs, 0); newSeqs[newSeqs.Length - 1] = lastCount; SequenceCounts = newSeqs; } else { WriteError(new ErrorRecord(new ArgumentException("The number of SequenceCounts/Ratios should match the number of OutFiles"), "", ErrorCategory.InvalidArgument, null)); return; } for (var i = 0; i < SequenceCounts.Length; ++i) { WriteVerbose(string.Format("{0}-th sequences: {1}", i, SequenceCounts[i])); } // Get absolute paths for (var i = 0; i < OutFiles.Length; ++i) { OutFiles[i] = IO.GetAbsolutePath(this, OutFiles[i]); } // Write partial files using (var reader = new StreamReader(Path, Encoding.UTF8)) { string lastLine = null; for (var i = 0; i < OutFiles.Length; ++i) { using (var writer = new StreamWriter(OutFiles[i], false, new UTF8Encoding(false))) { lastLine = CTFTools.WritePartial(reader, writer, SequenceCounts[i], lastLine); } } } }