本文整理汇总了C#中CsvReader.CopyCurrentRecordTo方法的典型用法代码示例。如果您正苦于以下问题:C# CsvReader.CopyCurrentRecordTo方法的具体用法?C# CsvReader.CopyCurrentRecordTo怎么用?C# CsvReader.CopyCurrentRecordTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsvReader
的用法示例。
在下文中一共展示了CsvReader.CopyCurrentRecordTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LastFieldEmptyFollowedByMissingFieldsOnNextRecord
public void LastFieldEmptyFollowedByMissingFieldsOnNextRecord()
{
const string Data = "a,b,c,d,e"
+ "\na,b,c,d,"
+ "\na,b,";
using (var csv = new CsvReader(new StringReader(Data), false))
{
csv.MissingFieldAction = MissingFieldAction.ReplaceByNull;
var record = new string[5];
Assert.IsTrue(csv.ReadNextRecord());
csv.CopyCurrentRecordTo(record);
Assert.AreEqual(new string[] { "a", "b", "c", "d", "e" }, record);
Assert.IsTrue(csv.ReadNextRecord());
csv.CopyCurrentRecordTo(record);
Assert.AreEqual(new string[] { "a", "b", "c", "d", "" }, record);
Assert.IsTrue(csv.ReadNextRecord());
csv.CopyCurrentRecordTo(record);
Assert.AreEqual(new string[] { "a", "b", "", null, null }, record);
Assert.IsFalse(csv.ReadNextRecord());
}
}
示例2: ArgumentTestCopyCurrentRecordTo3
public void ArgumentTestCopyCurrentRecordTo3()
{
using (CsvReader csv = new CsvReader(new StringReader(CsvReaderSampleData.SampleData1), false))
{
csv.CopyCurrentRecordTo(new string[1], 1);
}
}
示例3: ArgumentTestCopyCurrentRecordTo4
public void ArgumentTestCopyCurrentRecordTo4()
{
using (CsvReader csv = new CsvReader(new StringReader(CsvReaderSampleData.SampleData1), false))
{
csv.ReadNextRecord();
csv.CopyCurrentRecordTo(new string[CsvReaderSampleData.SampleData1RecordCount - 1], 0);
}
}
示例4: CopyCurrentRecordToTest1
public void CopyCurrentRecordToTest1()
{
using (CsvReader csv = new CsvReader(new StringReader(CsvReaderSampleData.SampleData1), false))
{
csv.CopyCurrentRecordTo(new string[CsvReaderSampleData.SampleData1RecordCount]);
}
}
示例5: WriteOutputFiles
private void WriteOutputFiles(IEnumerable<QuantFile> quantFiles)
{
OnUpdateLog("Writing output files...");
foreach (QuantFile file in quantFiles)
{
string filePath = file.FilePath;
string fileName = Path.GetFileNameWithoutExtension(filePath);
string outputFilePath = Path.Combine(OutputDirectory, fileName+"_quant.csv");
OnUpdateLog("Writing "+outputFilePath+"...");
using (CsvReader reader = new CsvReader(new StreamReader(filePath), true))
{
using (StreamWriter writer = new StreamWriter(outputFilePath))
{
StringBuilder sb = new StringBuilder();
string[] headerColumns = reader.GetFieldHeaders();
int headerCount = headerColumns.Length;
string header = string.Join(",", headerColumns);
sb.Append(header);
if (CalculatePurity)
{
sb.Append(",Precursor Purity (%)");
}
// Raw Intensities
foreach (TagInformation tag in UsedTags.Values)
{
sb.AppendFormat(",{0} ({1} NL)", tag.SampleName, tag.TagName);
}
// Denormalized Intensities
foreach (TagInformation tag in UsedTags.Values)
{
sb.AppendFormat(",{0} ({1} dNL)", tag.SampleName, tag.TagName);
}
// Purity Corrected Intensities
foreach (TagInformation tag in UsedTags.Values)
{
sb.AppendFormat(",{0} ({1} PC)", tag.SampleName, tag.TagName);
}
// Purity Corrected Normalized Intensities
foreach (TagInformation tag in UsedTags.Values)
{
sb.AppendFormat(",{0} ({1} PCN)", tag.SampleName, tag.TagName);
}
// Number of Channels Detected
sb.Append(",Channels Detected");
writer.WriteLine(sb.ToString());
while (reader.ReadNextRecord())
{
sb.Clear();
string[] inputData = new string[headerCount];
reader.CopyCurrentRecordTo(inputData);
for(int i=0; i <inputData.Length; i++)
{
string data = inputData[i];
if (data.Contains('"'))
data = data.Replace("\"", "\"\"");
if (data.Contains(','))
{
sb.Append('"');
sb.Append(data);
sb.Append('"');
}
else
{
sb.Append(data);
}
sb.Append(',');
}
sb.Remove(sb.Length - 1, 1);
//sb.Append(string.Join(",", inputData));
//int scanNumber = int.Parse(reader["Spectrum number"]);
string fileId = reader["Filename/id"];
PSM psm = file[fileId];
List<QuantPeak> peaks =
(from TagInformation tag in UsedTags.Values select psm[tag]).ToList();
// Print out precrusor purity if requested
if (CalculatePurity)
{
sb.Append(',');
sb.Append(psm.Purity*100);
}
// Raw Intensities
foreach (QuantPeak peak in peaks)
{
//.........这里部分代码省略.........
示例6: TrimFieldValuesTest
public void TrimFieldValuesTest(string data, ValueTrimmingOptions trimmingOptions, params string[] expected)
{
using (var csv = new CsvReader(new StringReader(data), false, CsvReader.DefaultDelimiter, CsvReader.DefaultQuote, CsvReader.DefaultEscape, CsvReader.DefaultComment, trimmingOptions))
{
while (csv.ReadNextRecord())
{
var actual = new string[csv.FieldCount];
csv.CopyCurrentRecordTo(actual);
Assert.AreEqual(expected, actual);
}
}
}
示例7: CheckSampleData1
public static void CheckSampleData1(long recordIndex, CsvReader csv)
{
string[] fields = new string[6];
csv.CopyCurrentRecordTo(fields);
CheckSampleData1(csv.HasHeaders, recordIndex, fields, 0);
}
示例8: CompileResults
private List<Protein> CompileResults(List<LocalizedHit> hits, string csvFile, string outputDirectory, bool breakProteinsApart = false)
{
Dictionary<string, LocalizedHit> hitsdict = new Dictionary<string, LocalizedHit>();
// Group all the localized Hits into proteins
Dictionary<string, Protein> proteins = new Dictionary<string, Protein>();
foreach (LocalizedHit hit in hits)
{
hitsdict.Add(hit.PSM.Filename, hit);
string defline = hit.PSM.Defline;
if (breakProteinsApart)
{
string[] groups = hit.PSM.ProteinGroup.Split('|');
foreach (string group in groups)
{
Protein prot;
if (!proteins.TryGetValue(group, out prot))
{
prot = new Protein(group, defline);
proteins.Add(group, prot);
}
prot.AddHit(hit);
}
}
else
{
Protein prot;
if (!proteins.TryGetValue(hit.PSM.ProteinGroup, out prot))
{
prot = new Protein(hit.PSM.ProteinGroup, defline);
proteins.Add(hit.PSM.ProteinGroup, prot);
}
prot.AddHit(hit);
}
}
using (StreamWriter writer = new StreamWriter(Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(csvFile) + "_all.csv")),
localizedWriter = new StreamWriter(Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(csvFile) + "_localized.csv")))
{
using (CsvReader reader = new CsvReader(new StreamReader(csvFile), true))
{
LocalizedHit hit = null;
headerInfo = reader.GetFieldHeaders();
bool tqFound = false;
for (int i = 0; i < reader.FieldCount; i++)
{
if (headerInfo[i].EndsWith("NL)"))
{
if (!tqFound)
{
FirstQuantColumn = i;
tqFound = true;
}
}
if(headerInfo[i] == "Channels Detected")
LastQuantColumn = i-1;
}
string header = string.Join(",", headerInfo) + ",# Isoforms,# of Considered Fragments,Localized?,Delta Score,Best Isoform,Spectral Matches,% TIC,Second Best Isoform,Second Spectral Matches,Second % TIC";
writer.WriteLine(header);
localizedWriter.WriteLine(header);
while (reader.ReadNextRecord())
{
string mods = reader["Mods"];
if (string.IsNullOrEmpty(mods))
continue;
List<Modification> variableMods = OmssaModification.ParseModificationLine(mods).Select(item => item.Item1).OfType<Modification>().ToList();
// Only keep things with quantified Modifications
if (!variableMods.Any(mod => QuantifiedModifications.Contains(mod)))
continue;
string filename = reader["Filename/id"];
if(!hitsdict.TryGetValue(filename, out hit))
continue;
string[] data = new string[reader.FieldCount];
reader.CopyCurrentRecordTo(data);
hit.omssapsm = data;
StringBuilder sb = new StringBuilder();
foreach (string datum in data)
{
if (datum.Contains(','))
{
sb.Append("\"");
sb.Append(datum);
sb.Append("\"");
}
else
sb.Append(datum);
sb.Append(',');
}
sb.Append(hit.PSM.Isoforms);
sb.Append(',');
sb.Append(hit.LocalizedIsoform.Fragments.Count);
//.........这里部分代码省略.........
示例9: CopyCurrentRecordTo_NotEnoughSlotsAfterIndex_ThrowsArgumentOutOfRangeException
public void CopyCurrentRecordTo_NotEnoughSlotsAfterIndex_ThrowsArgumentOutOfRangeException()
{
using (CsvReader csv = new CsvReader(new StringReader(CsvReaderSampleData.SampleData1), false))
{
csv.ReadNextRecord();
csv.CopyCurrentRecordTo(new string[CsvReaderSampleData.SampleData1RecordCount], 1);
}
}
示例10: LastFieldEmptyFollowedByMissingFieldsOnNextRecord
public void LastFieldEmptyFollowedByMissingFieldsOnNextRecord()
{
const string Data = "a,b,c,d,e"
+ "\na,b,c,d,"
+ "\na,b,";
using (var csv = new CsvReader(new StringReader(Data), CsvReader.DefaultBufferSize, new CsvLayout(hasHeaders:false),
new CsvBehaviour(missingFieldAction:MissingFieldAction.ReplaceByNull)))
{
var record = new string[5];
Assert.IsTrue(csv.ReadNextRecord());
csv.CopyCurrentRecordTo(record);
CollectionAssert.AreEqual(new string[] { "a", "b", "c", "d", "e" }, record);
Assert.IsTrue(csv.ReadNextRecord());
csv.CopyCurrentRecordTo(record);
CollectionAssert.AreEqual(new string[] { "a", "b", "c", "d", "" }, record);
Assert.IsTrue(csv.ReadNextRecord());
csv.CopyCurrentRecordTo(record);
CollectionAssert.AreEqual(new string[] { "a", "b", "", null, null }, record);
Assert.IsFalse(csv.ReadNextRecord());
}
}
示例11: CopyCurrentRecordTo_ArrayTooSmall_ThrowsArgumentException
public void CopyCurrentRecordTo_ArrayTooSmall_ThrowsArgumentException()
{
using (CsvReader csv = new CsvReader(new StringReader(CsvReaderSampleData.SampleData1), false))
{
csv.ReadNextRecord();
csv.CopyCurrentRecordTo(new string[CsvReaderSampleData.SampleData1RecordCount - 1], 0);
}
}
示例12: CopyCurrentRecordTo_ArrayBeyondBounds_ThrowsArgumentOutOfRangeException
public void CopyCurrentRecordTo_ArrayBeyondBounds_ThrowsArgumentOutOfRangeException()
{
using (CsvReader csv = new CsvReader(new StringReader(CsvReaderSampleData.SampleData1), false))
{
csv.CopyCurrentRecordTo(new string[1], 1);
}
}
示例13: CopyCurrentRecordTo_Null_ThrowsArgumentNullException
public void CopyCurrentRecordTo_Null_ThrowsArgumentNullException()
{
using (CsvReader csv = new CsvReader(new StringReader(CsvReaderSampleData.SampleData1), false))
{
csv.CopyCurrentRecordTo(null);
}
}
示例14: Phosphinate
//.........这里部分代码省略.........
//quant = header_line.Contains("TQ_");
non_phospho_output.WriteLine(header_line);
localized_phospho_output.WriteLine(header_line +
", Number of Theoretical Fragments, Identified Phosphoisoform, Identified Phosphoisoform Number of Matching Fragments, Best Phosphoisoforms, Best Phosphoisoform, Best Phosphoisoform Number of Matching Fragments, Second-Best Phosphoisoform, Second-Best Phosphoisoform Number of Matching Fragments, Identified Phosphoisoform Correct?, Preliminary Localization of All Phosphorylations?, Peptide Phosphorylation Sites, Probability of Spurious Fragment Match, Number of Theoretical Site-Determining Fragment Ions, Number of Matching Site-Determining Fragment Ions, Matching Site-Determining Fragment Ions, Probability Values, Ambiguity Scores, Phosphorylation Sites Localized?, All Phosphorylation Sites Localized?");
unlocalized_phospho_output.WriteLine(header_line +
", Number of Theoretical Fragments, Identified Phosphoisoform, Identified Phosphoisoform Number of Matching Fragments, Best Phosphoisoforms, Best Phosphoisoform, Best Phosphoisoform Number of Matching Fragments, Second-Best Phosphoisoform, Second-Best Phosphoisoform Number of Matching Fragments, Identified Phosphoisoform Correct?, Preliminary Localization of All Phosphorylations?, Peptide Phosphorylation Sites, Probability of Spurious Fragment Match, Number of Theoretical Site-Determining Fragment Ions, Number of Matching Site-Determining Fragment Ions, Matching Site-Determining Fragment Ions, Probability Values, Ambiguity Scores, Phosphorylation Sites Localized?, All Phosphorylation Sites Localized?");
while (reader.ReadNextRecord())
{
//string line = csv.ReadLine();
//string[] fields = Regex.Split(line,
// @",(?!(?<=(?:^|,)\s*\x22(?:[^\x22]|\x22\x22|\\\x22)*,)(?:[^\x22]|\x22\x22|\\\x22)*\x22\s*(?:,|$))");
// // crazy regex to parse CSV with internal double quotes from http://regexlib.com/REDetails.aspx?regexp_id=621
string sequence = reader["Peptide"];
string dynamic_modifications = reader["Mods"];
if (!dynamic_modifications.Contains("phosphorylation"))
{
//non_phospho_output.WriteLine(line);
}
else
{
Peptide identified_phosphopeptide = new Peptide(sequence, fixedModifications,
dynamic_modifications);
int start_residue = int.Parse(reader["Start"]);
int stop_residue = int.Parse(reader["Stop"]);
string protein_description = reader["Defline"].Trim('"');
StringBuilder sb = new StringBuilder();
reader.CopyCurrentRecordTo(lineData);
foreach (string datum in lineData)
{
if (datum.Contains(','))
sb.Append("\"" + datum + "\"");
else
sb.Append(datum);
sb.Append(',');
}
sb.Remove(sb.Length - 1, 1);
string line = sb.ToString();
if (!identified_sites_by_protein.ContainsKey(protein_description))
{
identified_sites_by_protein.Add(protein_description, new Dictionary<string, int>());
}
foreach (KeyValuePair<int, string> kvp in identified_phosphopeptide.DynamicModifications)
{
if (kvp.Value.Contains("phosphorylation"))
{
string site = sequence[kvp.Key - 1] + (start_residue + kvp.Key).ToString();
if (!identified_sites_by_protein[protein_description].ContainsKey(site))
{
identified_sites_by_protein[protein_description].Add(site, 0);
}
identified_sites_by_protein[protein_description][site]++;
}
}
int scan_number = int.Parse(reader["Spectrum number"]);
string filenameID = reader["Filename/id"];
FragmentType[] fragment_types = null;
if (filenameID.Contains(".ETD.") || filenameID.Contains(".ECD."))
示例15: WriteFiles
//.........这里部分代码省略.........
decoyWriter.WriteLine(headerLine);
targetWriter.WriteLine(headerLine);
scansWriter.WriteLine(headerLine);
targetUniqueWriter.WriteLine(headerLine);
decoyUniqueWriter.WriteLine(headerLine);
if (firstHeader)
{
batchScansWriter.WriteLine(headerLine);
batchDecoyWriter.WriteLine(headerLine);
batchTargetWriter.WriteLine(headerLine);
if (isBatched)
{
batchDecoyUniqueWriter.WriteLine(headerLine);
batchTargetUniqueWriter.WriteLine(headerLine);
}
firstHeader = false;
}
while (reader.ReadNextRecord())
{
PSM psm;
int spectralNumber = int.Parse(reader["Spectrum number"]);
if (scansProcessed.Contains(spectralNumber))
continue;
string fileName = reader["Filename/id"];
string sequence = reader["Peptide"].ToUpper();
if (allPsms.TryGetValue(fileName + sequence, out psm))
{
bool isNegative = psm.Charge < 0;
scansProcessed.Add(spectralNumber);
sb.Clear();
reader.CopyCurrentRecordTo(data);
for (int i = 0; i < 15; i++)
{
string datum = data[i];
if (_includeFixedMods && i == modsColumnIndex)
{
datum = OmssaModification.WriteModificationString(psm.Peptide);
}
// Replace the charge if negative
if (isNegative && i == chargeColumnIndex)
{
sb.Append(psm.Charge);
sb.Append(',');
continue;
}
if (datum.Contains('"'))
datum = datum.Replace("\"", "\"\"");
if (datum.Contains(','))
{
sb.Append('"');
sb.Append(datum);
sb.Append('"');
}
else
{
sb.Append(datum);
}
sb.Append(',');