private void WriteCountNode( XmlTextWriter writer, CountItem item) { writer.WriteStartElement("counter-item"); WriteElement(writer, "name", item.Name); WriteElement(writer, "count", item.Count.ToString()); writer.WriteEndElement(); }
public override IEnumerable <string> Process() { var countfiles = options.GetCountFiles(); List <CountItem> counts = new List <CountItem>(); foreach (var file in countfiles) { Progress.SetMessage("reading " + file.File + " ..."); var count = new CountItem() { Dir = file.Name, Data = (from line in File.ReadAllLines(file.File).Skip(1) let parts = line.Split('\t') where parts.Length >= 6 select parts).ToDictionary(m => m[0]) }; counts.Add(count); } var features = (from c in counts from k in c.Data.Keys select k).Distinct().OrderBy(m => m).ToList(); var checkSequence = counts.First().Data.First().Value[2]; double value; var hasSequence = !double.TryParse(checkSequence, out value); var seqheader = hasSequence ? "\tSequence" : ""; var startIndex = hasSequence ? 3 : 2; using (StreamWriter sw = new StreamWriter(options.OutputFile)) using (StreamWriter swIso = new StreamWriter(options.IsomirFile)) { sw.WriteLine("Feature\tLocation{0}\t{1}", seqheader, (from c in counts select c.Dir).Merge("\t")); swIso.WriteLine("Feature\tLocation{0}\t{1}", seqheader, (from c in counts select c.Dir).Merge("\t")); foreach (var feature in features) { OutputCount(counts, sw, feature, startIndex, "", hasSequence); OutputCount(counts, swIso, feature, startIndex + 1, "_+_0", hasSequence); OutputCount(counts, swIso, feature, startIndex + 2, "_+_1", hasSequence); OutputCount(counts, swIso, feature, startIndex + 3, "_+_2", hasSequence); } } var result = new[] { options.OutputFile, options.IsomirFile }.ToList(); var infofile = Path.ChangeExtension(options.OutputFile, ".info"); if (CountUtils.WriteInfoSummaryFile(infofile, options.GetCountFiles().ToDictionary(m => m.Name, m => m.File))) { result.Add(infofile); } return(result); }
public async void init(string did) { state = new bool[50]; for (int i = 0; i < 50; i++) { state[i] = false; } var result = await HttpUtil.GetDuties(did); if ((bool)result["ok"]) { JArray duties = (JArray)result["duties"]; JArray counts = (JArray)result["counts"]; for (var i = 0; i < duties.Count; i++) { DutyItem D = new DutyItem(); D.cno = (int)duties[i]["dno"]; D.name = (string)duties[i]["name"]; long second = (long)duties[i]["time"]; D.time = new DateTime(second); D.note = (string)duties[i]["note"]; dutyitems.Add(D); } for (var i = 0; i < counts.Count; i++) { CountItem C = new CountItem(); C.count = (int)counts[i]["count"]; C.name = (string)counts[i]["name"]; C.no = (int)counts[i]["mno"]; countitems.Add(C); } } else { var md = new MessageDialog("duty models init fail!!").ShowAsync(); return; } result = await HttpUtil.GetMembers(App.account); if ((bool)result["ok"]) { JArray member = (JArray)result["members"]; for (var i = 0; i < member.Count; i++) { string mno = (string)member[i]["mno"]; MemberItem m = new MemberItem(); m.name = (string)member[i]["name"]; long second = (long)member[i]["birth"]; m.birth = new System.DateTime(second); m.pic = new System.Uri("http://www.sysu7s.cn:3000/api/dormitory//get-member-image/" + App.account + "/" + mno); m.location = (string)member[i]["location"]; memberitems.Add(m); } } }
public override IEnumerable<string> Process() { var countfiles = options.GetCountFiles(); List<CountItem> counts = new List<CountItem>(); foreach (var file in countfiles) { Progress.SetMessage("reading " + file.File + " ..."); var count = new CountItem() { Dir = file.Name, Data = (from line in File.ReadAllLines(file.File).Skip(1) let parts = line.Split('\t') where parts.Length >= 6 select parts).ToDictionary(m => m[0]) }; counts.Add(count); } var features = (from c in counts from k in c.Data.Keys select k).Distinct().OrderBy(m => m).ToList(); var checkSequence = counts.First().Data.First().Value[2]; double value; var hasSequence = !double.TryParse(checkSequence, out value); var seqheader = hasSequence ? "\tSequence" : ""; var startIndex = hasSequence ? 3 : 2; using (StreamWriter sw = new StreamWriter(options.OutputFile)) using (StreamWriter swIso = new StreamWriter(options.IsomirFile)) { sw.WriteLine("Feature\tLocation{0}\t{1}", seqheader, (from c in counts select c.Dir).Merge("\t")); swIso.WriteLine("Feature\tLocation{0}\t{1}", seqheader, (from c in counts select c.Dir).Merge("\t")); foreach (var feature in features) { OutputCount(counts, sw, feature, startIndex, "", hasSequence); OutputCount(counts, swIso, feature, startIndex + 1, "_+_0", hasSequence); OutputCount(counts, swIso, feature, startIndex + 2, "_+_1", hasSequence); OutputCount(counts, swIso, feature, startIndex + 3, "_+_2", hasSequence); } } var result = new[] { options.OutputFile, options.IsomirFile }.ToList(); var infofile = Path.ChangeExtension(options.OutputFile, ".info"); if (CountUtils.WriteInfoSummaryFile(infofile, options.GetCountFiles().ToDictionary(m => m.Name, m => m.File))) { result.Add(infofile); } return result; }
public void CountMaster_Saves_Counts() { var sut = new CountMaster("counts.xml"); var input = new CountItem("Casual", 4); sut.PutItem(input); var result = (CountItem)sut.TheHt["Casual"]; Assert.True(result.Count == 4); }
public void RemoveItem(CountItem it) { if (it == null) { return; } if (_eventList.Contains(it)) { _eventList.Remove(it); } }
public void Test_CountItem_Properties() { // Arrange var count = new CountItem(); // Act count.Id = "a"; count.Key = "b"; // Assert count.Id.Should().Be("a"); count.Key.Should().Be("b"); }
public void AddItem(CountItem it) { if (it.endimeToCall > it.startTimeToCall) { Random random = new Random(); it.realTimeToCall = Random.Range(it.startTimeToCall, it.endimeToCall); } else { it.realTimeToCall = it.startTimeToCall; } _eventList.Add(it); }
public void PutItem( CountItem item) { var name = item.Name; if (!TheHt.ContainsKey(name)) { TheHt.Add( key: name, value: item); IsDirty = true; } else { TheHt[name] = item; } }
/// <summary> /// 進捗表示の更新を実行する /// </summary> /// <param name="index">区分インデックスを表す数値</param> /// <param name="e">イベント引数</param> private void ChangeProgress(int index, ItemProgressedEventArgs e) { ProgressBar pb = index switch { 1 => _fileProgressBar, 2 => _viewProgressBar, 3 => _itemProgressBar, _ => null }; Label nameLabel = index switch { 1 => _fileNameLabel, 2 => _categoryNameLabel, 3 => _itemNameLabel, _ => null }; Label countLabel = index switch { 1 => _fileCountLabel, 2 => _categoryCountLabel, 3 => _itemCountLabel, _ => null }; CountItem item = index switch { 1 => e.FileCount, 2 => e.ViewCount, 3 => e.DetailCount, _ => new CountItem() }; // Application.DoEvents(); pb.Maximum = item.Items; pb.Value = item.Counter; nameLabel.Text = item.Name; countLabel.Text = $"{item.Counter}/{item.Items}"; int rate = 0; if (e.DetailCount.Items > 1) { rate = 100 * e.DetailCount.Counter / e.DetailCount.Items; } Text = $"{GetFormText()}{rate.ToString()}%"; }
/// <summary> /// 添加回调事件多长时间之后执行回调 /// </summary> /// <param name="startTime">多长时间</param> /// <param name="endTime">多长时间</param> /// <param name="callback">执行回调</param> /// <param name="repeatCount">重复次数 -1:永久重复</param> public void AddCallBack(Action callback, float startTime, int repeatCount = 1, float endTime = -1) { CountItem it = new CountItem(); it.callback = callback; it.startTimeToCall = startTime; it.endimeToCall = endTime; if (it.endimeToCall > it.startTimeToCall) { Random random = new Random(); it.realTimeToCall = Random.Range(it.startTimeToCall, it.endimeToCall); } else { it.realTimeToCall = it.startTimeToCall; } it.totalRepeatCount = repeatCount; _eventList.Add(it); }
private void DoProcess(Func <FastqSequence, bool> accept, SmallRNACountMap map, string outputFile, Dictionary <int, CountItem> dic) { Progress.SetMessage("Processing " + options.InputFile + " and writing to " + outputFile + "..."); var ccaMap = new MapItemReader(0, 1).ReadFromFile(options.CCAFile).ToDictionary(m => m.Key, m => bool.Parse(m.Value.Value)); var parser = new FastqReader(); var writer = new FastqWriter(); StreamWriter swCount = null; if (map.HasCountFile) { swCount = new StreamWriter(outputFile + ".dupcount"); swCount.WriteLine("Query\tCount\tSequence"); } try { int readcount = 0; var tmpFile = outputFile + ".tmp"; using (var sr = StreamUtils.GetReader(options.InputFile)) { using (var sw = StreamUtils.GetWriter(tmpFile, outputFile.ToLower().EndsWith(".gz"))) { FastqSequence seq; while ((seq = parser.Parse(sr)) != null) { readcount++; if (readcount % 100000 == 0) { Progress.SetMessage("{0} reads processed", readcount); } if (!accept(seq)) { continue; } var name = seq.Name; var sequence = seq.SeqString; var score = seq.Score; var len = sequence.Length; var description = seq.Description; var count = map.GetCount(seq.Name); if (map.HasCountFile) { swCount.WriteLine("{0}\t{1}\t{2}", seq.Name, count, seq.SeqString); } CountItem item; if (!dic.TryGetValue(sequence.Length, out item)) { item = new CountItem(); dic[sequence.Length] = item; } string clipped; if (sequence.EndsWith("CCAA")) { clipped = "CCAA"; sequence = sequence.Substring(0, sequence.Length - 4); item.CCAA += count; } else if (sequence.EndsWith("CCA")) { clipped = "CCA"; sequence = sequence.Substring(0, sequence.Length - 3); item.CCA += count; } else if (sequence.EndsWith("CC")) { bool isCCA; if (ccaMap.TryGetValue(name, out isCCA) && isCCA) { clipped = "CC"; sequence = sequence.Substring(0, sequence.Length - 2); item.CC += count; } else { clipped = string.Empty; item.notNTA += count; } } else { clipped = string.Empty; item.notNTA += count; } if (!string.IsNullOrEmpty(clipped)) { var newlen = sequence.Length; seq.SeqString = sequence; seq.Score = score.Substring(0, newlen); seq.Reference = string.Format("{0}{1}{2}", name, SmallRNAConsts.NTA_TAG, clipped); } else { seq.Reference = string.Format("{0}{1}", name, SmallRNAConsts.NTA_TAG); } writer.Write(sw, seq); if (map.HasCountFile) { swCount.WriteLine("{0}\t{1}\t{2}", seq.Name, count, seq.SeqString); } } } } File.Move(tmpFile, outputFile); } finally { if (map.HasCountFile) { swCount.Close(); } } }
private void AddCount( CountItem item) { PutItem(item); }
private void DoProcess(Func<FastqSequence, bool> accept, SmallRNACountMap map, string outputFile, Dictionary<int, CountItem> dic) { Progress.SetMessage("Processing " + options.InputFile + " and writing to " + outputFile + "..."); var ccaMap = new MapItemReader(0, 1).ReadFromFile(options.CCAFile).ToDictionary(m => m.Key, m => bool.Parse(m.Value.Value)); var parser = new FastqReader(); var writer = new FastqWriter(); StreamWriter swCount = null; if (map.HasCountFile) { swCount = new StreamWriter(outputFile + ".dupcount"); swCount.WriteLine("Query\tCount\tSequence"); } try { int readcount = 0; var tmpFile = outputFile + ".tmp"; using (var sr = StreamUtils.GetReader(options.InputFile)) { using (var sw = StreamUtils.GetWriter(tmpFile, outputFile.ToLower().EndsWith(".gz"))) { FastqSequence seq; while ((seq = parser.Parse(sr)) != null) { readcount++; if (readcount % 100000 == 0) { Progress.SetMessage("{0} reads processed", readcount); } if (!accept(seq)) { continue; } var name = seq.Name; var sequence = seq.SeqString; var score = seq.Score; var len = sequence.Length; var description = seq.Description; var count = map.GetCount(seq.Name); if (map.HasCountFile) { swCount.WriteLine("{0}\t{1}\t{2}", seq.Name, count, seq.SeqString); } CountItem item; if (!dic.TryGetValue(sequence.Length, out item)) { item = new CountItem(); dic[sequence.Length] = item; } string clipped; if (sequence.EndsWith("CCAA")) { clipped = "CCAA"; sequence = sequence.Substring(0, sequence.Length - 4); item.CCAA += count; } else if (sequence.EndsWith("CCA")) { clipped = "CCA"; sequence = sequence.Substring(0, sequence.Length - 3); item.CCA += count; } else if (sequence.EndsWith("CC")) { bool isCCA; if (ccaMap.TryGetValue(name, out isCCA) && isCCA) { clipped = "CC"; sequence = sequence.Substring(0, sequence.Length - 2); item.CC += count; } else { clipped = string.Empty; item.notNTA += count; } } else { clipped = string.Empty; item.notNTA += count; } if (!string.IsNullOrEmpty(clipped)) { var newlen = sequence.Length; seq.SeqString = sequence; seq.Score = score.Substring(0, newlen); seq.Reference = string.Format("{0}{1}{2}", name, SmallRNAConsts.NTA_TAG, clipped); } else { seq.Reference = string.Format("{0}{1}", name, SmallRNAConsts.NTA_TAG); } writer.Write(sw, seq); if (map.HasCountFile) { swCount.WriteLine("{0}\t{1}\t{2}", seq.Name, count, seq.SeqString); } } } } File.Move(tmpFile, outputFile); } finally { if (map.HasCountFile) { swCount.Close(); } } }