Example #1
0
        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);
                    }
                }
            }
        }
Example #2
0
 protected override void EndProcessing()
 {
     Path = IO.GetAbsolutePath(this, Path);
     DataSourceSetCTFBuilder.Write(Path, DataSources, WithSequenceAxis);
 }