Exemplo n.º 1
0
        protected IDictionary <ResultKey, TResult> MakeChromInfoResultsMap <TChromInfo, TResult>(
            Results <TChromInfo> results, Func <ResultFile, TResult> newResultFunc) where TChromInfo : ChromInfo
        {
            var resultMap = new Dictionary <ResultKey, TResult>();

            if (results == null)
            {
                return(resultMap);
            }
            for (int replicateIndex = 0; replicateIndex < results.Count; replicateIndex++)
            {
                var replicate = new Replicate(DataSchema, replicateIndex);
                var files     = results[replicateIndex];
                if (null == files)
                {
                    continue;
                }
                for (int fileIndex = 0; fileIndex < files.Count; fileIndex++)
                {
                    var chromInfo = files[fileIndex];
                    if (null == chromInfo)
                    {
                        continue;
                    }
                    var key        = new ResultKey(replicate, fileIndex);
                    var resultFile = new ResultFile(replicate, chromInfo.FileId, ResultFile.GetOptStep(chromInfo));
                    resultMap.Add(key, newResultFunc(resultFile));
                }
            }
            return(resultMap);
        }
Exemplo n.º 2
0
        protected IDictionary <ResultKey, TResult> MakeChromInfoResultsMap <TChromInfo, TResult>(
            Results <TChromInfo> results, Func <ResultFile, TResult> newResultFunc) where TChromInfo : ChromInfo
        {
            if (results == null)
            {
                return(ImmutableSortedList <ResultKey, TResult> .EMPTY.AsDictionary());
            }
            var replicates  = DataSchema.ReplicateList;
            var resultFiles = DataSchema.ResultFileList;

            if (replicates.Count == results.Count && results.All(r => r.Count == 1 && r[0] != null))
            {
                // If every replicate has exactly one result, then we can reuse the keys in "DataSchema.ReplicateList".
                var newValues = new List <TResult>(replicates.Count);
                for (int replicateIndex = 0; replicateIndex < replicates.Count; replicateIndex++)
                {
                    var        chromInfo  = results[replicateIndex][0];
                    var        optStep    = ResultFile.GetOptStep(chromInfo);
                    ResultFile resultFile = null;
                    if (optStep == 0)
                    {
                        resultFiles.TryGetValue(new ResultFileKey(replicateIndex, chromInfo.FileId, optStep), out resultFile);
                    }
                    if (resultFile == null)
                    {
                        resultFile = new ResultFile(replicates.Values[replicateIndex], chromInfo.FileId, optStep);
                    }
                    newValues.Add(newResultFunc(resultFile));
                }
                return(replicates.ReplaceValues(newValues).AsDictionary());
            }
            var newEntries = new List <KeyValuePair <ResultKey, TResult> >();

            for (int replicateIndex = 0; replicateIndex < results.Count; replicateIndex++)
            {
                var replicate = new Replicate(DataSchema, replicateIndex);
                var files     = results[replicateIndex];
                for (int fileIndex = 0; fileIndex < files.Count; fileIndex++)
                {
                    var chromInfo = files[fileIndex];
                    if (null == chromInfo)
                    {
                        continue;
                    }
                    var        key        = fileIndex == 0 ? replicates.Keys[replicateIndex] : new ResultKey(replicate, fileIndex);
                    int        optStep    = ResultFile.GetOptStep(chromInfo);
                    ResultFile resultFile = null;
                    if (optStep == 0)
                    {
                        resultFiles.TryGetValue(new ResultFileKey(replicateIndex, chromInfo.FileId, optStep), out resultFile);
                    }
                    if (resultFile == null)
                    {
                        resultFile = new ResultFile(replicates.Values[replicateIndex], chromInfo.FileId, optStep);
                    }
                    newEntries.Add(new KeyValuePair <ResultKey, TResult>(key, newResultFunc(resultFile)));
                }
            }
            return(ImmutableSortedList <ResultKey, TResult> .FromValues(newEntries, Comparer <ResultKey> .Default)
                   .AsDictionary());
        }