forked from smith-chem-wisc/FlashLFQ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPsmReader.cs
More file actions
807 lines (710 loc) · 34.7 KB
/
Copy pathPsmReader.cs
File metadata and controls
807 lines (710 loc) · 34.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
using FlashLFQ;
using MzLibUtil;
using Readers;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using ThermoFisher.CommonCore.Data.Business;
using UsefulProteomicsDatabases;
namespace Util
{
internal enum PsmFileType
{ MetaMorpheus, Morpheus, MaxQuant, PeptideShaker, Generic, Percolator, Unknown }
public class PsmReader
{
public PsmReader()
{
//Set optional columns to -1
GeneNameColumn = -1;
OrganismColumn = -1;
DecoyColumn = -1;
ScoreColumn = -1;
QValueColumn = -1;
QValueNotchColumn = -1;
}
public int FileNameColumn { get; private set; }
public int BaseSeqColumn { get; private set; }
public int FullSeqColumn { get; private set; }
public int MonoisotopicMassColumn { get; private set; }
public int MsmsRTColumn { get; private set; }
public int MsmsScanNumberColumn { get; private set; }
public int ChargeStateColumn { get; private set; }
public int ProteinColumn { get; private set; }
// optional columns
public int GeneNameColumn { get; private set; }
public int OrganismColumn { get; private set; }
public int DecoyColumn { get; private set; }
public int ScoreColumn { get; private set; }
public static int QValueColumn { get; private set; }
public static int QValueNotchColumn { get; private set; }
private Dictionary<string, double> _modSequenceToMonoMass;
private Dictionary<string, ProteinGroup> allProteinGroups;
private List<ScanHeaderInfo> _scanHeaderInfo = new List<ScanHeaderInfo>();
//Delimiters refere to contents of one field, not the delimiter between fields
private static readonly Dictionary<PsmFileType, string[]> delimiters = new Dictionary<PsmFileType, string[]>
{
{ PsmFileType.MetaMorpheus, new string[] { "|", " or " } },
{ PsmFileType.Morpheus, new string[] { ";" } },
{ PsmFileType.MaxQuant, new string[] { ";" } },
{ PsmFileType.Percolator, new string[] { "," } },
{ PsmFileType.Generic, new string[] { ";" } },
{ PsmFileType.PeptideShaker, new string[] { ", " } },
};
// TODO:
// try to cast filetype as IQuantifiableResultFile
// var readResult as IQuantifiableResultFile
// 1. use Parsefiletype extension to get supported filetype enum
// 2. get ResultFile by passing in filePath and enum
// try cast resultFile to IQuantResultFile
private static List<Identification> TryReadQuantifiableResultFile(string filepath, bool silent, List<SpectraFileInfo> rawfiles)
{
try
{
IQuantifiableResultFile quantifiable = FileReader.ReadQuantifiableResultFile(filepath);
List<Identification> identifications = quantifiable.MakeIdentifications(rawfiles);
if (!silent)
{
Console.WriteLine("Done reading PSMs; found " + identifications.Count);
}
return identifications;
}
catch (Exception e)
{
// not every file read in will be a QuantifiableResultFile, support for this is still in development
}
return null;
}
public List<Identification> ReadPsms(string filepath, bool silent, List<SpectraFileInfo> rawfiles, double qValueThreshold = 0.01, bool usePepQValue = false)
{
// check if file path can be read in using readers as QuantifiableResultFile
List<Identification> quantifiableIdentifications = TryReadQuantifiableResultFile(filepath, silent, rawfiles);
if (quantifiableIdentifications != null)
{
return quantifiableIdentifications;
}
if (_modSequenceToMonoMass == null)
{
_modSequenceToMonoMass = new Dictionary<string, double>();
}
if (allProteinGroups == null)
{
allProteinGroups = new Dictionary<string, ProteinGroup>();
}
var rawFileDictionary = rawfiles.ToDictionary(p => p.FilenameWithoutExtension, v => v);
List<Identification> flashLfqIdentifications = new();
PsmFileType fileType = PsmFileType.Unknown;
if (!silent)
{
Console.WriteLine("Opening PSM file " + filepath);
}
StreamReader reader;
try
{
reader = new StreamReader(filepath);
}
catch (Exception e)
{
if (!silent)
{
Console.WriteLine("Error reading file " + filepath + "\n" + e.Message);
}
return new List<Identification>();
}
List<string> inputPsms = File.ReadAllLines(filepath).ToList();
string[] header = inputPsms[0].Split('\t');
try
{
fileType = GetFileTypeFromHeader(inputPsms[0], usePepQValue);
inputPsms.RemoveAt(0);
}
catch
{
throw new Exception("Could not interpret PSM header labels from file: " + filepath);
}
var psmsGroupedByFile = inputPsms.GroupBy(p => PeriodTolerantFilenameWithoutExtension.GetPeriodTolerantFilenameWithoutExtension(p.Split('\t')[FileNameColumn])).ToList();
foreach (var fileSpecificPsms in psmsGroupedByFile)
{
int myFileIndex = rawFileDictionary.Keys.ToList().IndexOf(fileSpecificPsms.Key);
string fullFilePathWithExtension = rawFileDictionary[fileSpecificPsms.Key].FullFilePathWithExtension;
List<Identification> myFileIndentifications = new();
List<ScanHeaderInfo> scanHeaderInfo = new();
if (fileType == PsmFileType.Percolator)
{
scanHeaderInfo = scanHeaderInfo = ScanInfoRecovery.FileScanHeaderInfo(fullFilePathWithExtension);
foreach (var psm in fileSpecificPsms)
{
try
{
Identification id = GetPercolatorIdentification(psm, scanHeaderInfo, silent, rawFileDictionary);
if (id != null)
{
myFileIndentifications.Add(id);
}
}
catch (Exception e)
{
if (!silent)
{
Console.WriteLine("Problem reading line in the identification file" + "; " + e.Message);
Console.WriteLine("Decoy column set to: " + DecoyColumn);
}
}
}
}
else
{
foreach (var psm in fileSpecificPsms)
{
try
{
Identification id = GetIdentification(psm, silent, rawFileDictionary, fileType, qValueThreshold);
if (id != null)
{
myFileIndentifications.Add(id);
}
}
catch (Exception e)
{
if (!silent)
{
Console.WriteLine("Problem reading line in the identification file" + "; " + e.Message);
Console.WriteLine("Decoy column set to: " + DecoyColumn);
}
}
}
}
_scanHeaderInfo.AddRange(scanHeaderInfo);
flashLfqIdentifications.AddRange(myFileIndentifications);
}
if (!silent)
{
Console.WriteLine("Done reading PSMs; found " + flashLfqIdentifications.Count);
}
return flashLfqIdentifications;
}
/// <summary>
/// Retrieves an individual ID from a line of a PSM file
/// </summary>
/// <param name="line"></param>
/// <param name="silent"></param>
/// <param name="rawFileDictionary"></param>
/// <param name="fileType"></param>
/// <param name="qValueThreshold"> Minimum is 0.01. </param>
/// <returns></returns>
private Identification GetIdentification(string line, bool silent, Dictionary<string, SpectraFileInfo> rawFileDictionary, PsmFileType fileType, double qValueThreshold = 0.01)
{
var param = line.Split('\t');
double qValue= 0;
qValueThreshold = Math.Max(qValueThreshold, 0.01);
// only quantify PSMs below the qValueThreshold with MetaMorpheus/Morpheus/Generic results
switch (fileType)
{
case (PsmFileType.MetaMorpheus):
qValue = double.Parse(param[QValueNotchColumn], CultureInfo.InvariantCulture);
if (qValue > qValueThreshold)
return null;
break;
case (PsmFileType.Morpheus): // This is legacy code, I have no idea how Morpheus files work or why Q values would be greater than 1
if (double.Parse(param[QValueColumn], CultureInfo.InvariantCulture) > 1.00)
return null;
break;
default:
if (QValueColumn < 0)
break;
qValue = double.Parse(param[QValueColumn], CultureInfo.InvariantCulture);
if (qValue > qValueThreshold)
return null;
break;
}
// find and label decoys in MetaMorpheus results
//TODO: what about decoys from other input types?
bool decoy = ((fileType == PsmFileType.MetaMorpheus || fileType == PsmFileType.Morpheus || fileType == PsmFileType.Generic)
&& DecoyColumn >= 0
&& param[DecoyColumn].Contains('D'));
// spectrum file name
string fileName = PeriodTolerantFilenameWithoutExtension.GetPeriodTolerantFilenameWithoutExtension(param[FileNameColumn]);
// base sequence
string baseSequence = param[BaseSeqColumn];
// modified sequence
string modSequence = param[FullSeqColumn];
// skip ambiguous sequence in MetaMorpheus output
if (fileType == PsmFileType.MetaMorpheus && (modSequence.Contains(" or ") || modSequence.Contains("|") || modSequence.ToLowerInvariant().Contains("too long")))
{
return null;
}
// monoisotopic mass
if (double.TryParse(param[MonoisotopicMassColumn], NumberStyles.Number, CultureInfo.InvariantCulture, out double monoisotopicMass))
{
if (_modSequenceToMonoMass.TryGetValue(modSequence, out double storedMonoisotopicMass))
{
if (storedMonoisotopicMass != monoisotopicMass)
{
if (!silent)
{
Console.WriteLine("Caution! PSM with could not be read. A peptide with the same modified sequence but a different monoisotopic mass has already been added." + "\n"
+ line);
}
return null;
}
}
else
{
_modSequenceToMonoMass.Add(modSequence, monoisotopicMass);
}
}
else
{
if (!silent)
{
Console.WriteLine("Caution! PSM with could not be read. Monoisotopic mass not interpretable." + "\n"
+ line);
}
return null;
}
// retention time
double ms2RetentionTime = -1;
if (double.TryParse(param[MsmsRTColumn], NumberStyles.Number, CultureInfo.InvariantCulture, out double retentionTime))
{
ms2RetentionTime = retentionTime;
if (fileType == PsmFileType.PeptideShaker)
{
// peptide shaker RT is in seconds - convert to minutes
ms2RetentionTime = retentionTime / 60.0;
}
if (ms2RetentionTime < 0)
{
if (!silent)
{
Console.WriteLine("Caution! PSM retention time was negative." + "\n"
+ line);
}
return null;
}
}
else
{
if (!silent)
{
Console.WriteLine("PSM retention time was not interpretable." + "\n"
+ line);
}
return null;
}
// charge state
int chargeState;
if (fileType == PsmFileType.PeptideShaker)
{
string chargeStringNumbersOnly = new String(param[ChargeStateColumn].Where(Char.IsDigit).ToArray());
if (string.IsNullOrWhiteSpace(chargeStringNumbersOnly))
{
if (!silent)
{
Console.WriteLine("PSM charge state was not interpretable." + "\n"
+ line);
}
return null;
}
else
{
if (!int.TryParse(chargeStringNumbersOnly, out chargeState))
{
if (!silent)
{
Console.WriteLine("PSM charge state was not interpretable." + "\n"
+ line);
}
return null;
}
}
}
else
{
if (!double.TryParse(param[ChargeStateColumn], NumberStyles.Number, CultureInfo.InvariantCulture, out double chargeStateDouble))
{
if (!silent)
{
Console.WriteLine("PSM charge state was not interpretable." + "\n"
+ line);
}
return null;
}
chargeState = (int)chargeStateDouble;
}
// protein groups
// use all proteins listed
string[] proteins = null;
string[] genes = null;
string[] organisms = null;
List<ProteinGroup> proteinGroups = new List<ProteinGroup>();
proteins = param[ProteinColumn].Split(delimiters[fileType], StringSplitOptions.None);
if (GeneNameColumn >= 0)
{
genes = param[GeneNameColumn].Split(delimiters[fileType], StringSplitOptions.None);
}
if (OrganismColumn >= 0)
{
organisms = param[OrganismColumn].Split(delimiters[fileType], StringSplitOptions.None);
}
for (int pr = 0; pr < proteins.Length; pr++)
{
string proteinName = proteins[pr];
string gene = "";
string organism = "";
if (genes != null)
{
if (genes.Length == 1)
{
gene = genes[0];
}
else if (genes.Length == proteins.Length)
{
gene = genes[pr];
}
else if (proteins.Length == 1)
{
gene = param[GeneNameColumn];
}
}
if (organisms != null)
{
if (organisms.Length == 1)
{
organism = organisms[0];
}
else if (organisms.Length == proteins.Length)
{
organism = organisms[pr];
}
else if (proteins.Length == 1)
{
organism = param[OrganismColumn];
}
}
if (allProteinGroups.TryGetValue(proteinName, out ProteinGroup pg))
{
proteinGroups.Add(pg);
}
else
{
ProteinGroup newPg = new ProteinGroup(proteinName, gene, organism);
allProteinGroups.Add(proteinName, newPg);
proteinGroups.Add(newPg);
}
}
if (!rawFileDictionary.TryGetValue(fileName, out SpectraFileInfo spectraFileInfoToUse))
{
// skip PSMs for files with no spectrum data input
return null;
}
double score;
if(ScoreColumn > 0 && fileType == PsmFileType.MetaMorpheus)
{
double.TryParse(param[ScoreColumn], out score);
}
else
{
score = 0;
}
// construct id
return new Identification(spectraFileInfoToUse, baseSequence, modSequence,
monoisotopicMass, ms2RetentionTime, chargeState, proteinGroups,
decoy: decoy, qValue: qValue, psmScore: score);
}
private Identification GetPercolatorIdentification(string line, List<ScanHeaderInfo> scanHeaderInfo, bool silent, Dictionary<string, SpectraFileInfo> rawFileDictionary)
{
var param = line.Split('\t');
// spectrum file name
string fileName = param[FileNameColumn];
// base sequence
string baseSequence = null;
// modified sequence
string modSequence = param[FullSeqColumn];
// skip ambiguous sequence in MetaMorpheus output
if (modSequence.Contains("|") || modSequence.ToLowerInvariant().Contains("too long"))
{
return null;
}
// monoisotopic mass
if (double.TryParse(param[MonoisotopicMassColumn], NumberStyles.Number, CultureInfo.InvariantCulture, out double monoisotopicMass))
{
if (_modSequenceToMonoMass.TryGetValue(modSequence, out double storedMonoisotopicMass))
{
if (storedMonoisotopicMass != monoisotopicMass)
{
if (!silent)
{
Console.WriteLine("Caution! PSM with could not be read. A peptide with the same modified sequence but a different monoisotopic mass has already been added." + "\n"
+ line);
}
return null;
}
}
else
{
_modSequenceToMonoMass.Add(modSequence, monoisotopicMass);
}
}
else
{
if (!silent)
{
Console.WriteLine("Caution! PSM with could not be read. Monoisotopic mass not interpretable." + "\n"
+ line);
}
return null;
}
// retention time
double ms2RetentionTime = -1;
//percolator input files do not have retention times. So, we have to get them from the data file using the scan number.
if (int.TryParse(param[MsmsScanNumberColumn], NumberStyles.Number, CultureInfo.InvariantCulture, out int scanNumber))
{
ms2RetentionTime = scanHeaderInfo.Where(i => PeriodTolerantFilenameWithoutExtension.GetPeriodTolerantFilenameWithoutExtension(i.FileNameWithoutExtension) == PeriodTolerantFilenameWithoutExtension.GetPeriodTolerantFilenameWithoutExtension(fileName) && i.ScanNumber == scanNumber).FirstOrDefault().RetentionTime;
}
// charge state
int chargeState;
if (!double.TryParse(param[ChargeStateColumn], NumberStyles.Number, CultureInfo.InvariantCulture, out double chargeStateDouble))
{
if (!silent)
{
Console.WriteLine("Caution! PSM with could not be read. Charge state not interpretable." + "\n"
+ line);
}
return null;
}
chargeState = (int)chargeStateDouble;
// protein groups
// use all proteins listed
string[] proteins = null;
string[] genes = null;
string[] organisms = null;
List<ProteinGroup> proteinGroups = new List<ProteinGroup>();
proteins = param[ProteinColumn].Split(delimiters[PsmFileType.Percolator], StringSplitOptions.None);
if (GeneNameColumn >= 0)
{
genes = param[GeneNameColumn].Split(delimiters[PsmFileType.Percolator], StringSplitOptions.None);
}
if (OrganismColumn >= 0)
{
organisms = param[OrganismColumn].Split(delimiters[PsmFileType.Percolator], StringSplitOptions.None);
}
for (int pr = 0; pr < proteins.Length; pr++)
{
string proteinName = proteins[pr];
string gene = "";
string organism = "";
if (genes != null)
{
if (genes.Length == 1)
{
gene = genes[0];
}
else if (genes.Length == proteins.Length)
{
gene = genes[pr];
}
else if (proteins.Length == 1)
{
gene = param[GeneNameColumn];
}
}
if (organisms != null)
{
if (organisms.Length == 1)
{
organism = organisms[0];
}
else if (organisms.Length == proteins.Length)
{
organism = organisms[pr];
}
else if (proteins.Length == 1)
{
organism = param[OrganismColumn];
}
}
if (allProteinGroups.TryGetValue(proteinName, out ProteinGroup pg))
{
proteinGroups.Add(pg);
}
else
{
ProteinGroup newPg = new ProteinGroup(proteinName, gene, organism);
allProteinGroups.Add(proteinName, newPg);
proteinGroups.Add(newPg);
}
}
if (!rawFileDictionary.TryGetValue(PeriodTolerantFilenameWithoutExtension.GetPeriodTolerantFilenameWithoutExtension(fileName), out SpectraFileInfo spectraFileInfoToUse))
{
// skip PSMs for files with no spectrum data input
return null;
}
return new Identification(spectraFileInfoToUse, baseSequence, modSequence, monoisotopicMass, ms2RetentionTime, chargeState, proteinGroups);
}
/// <summary>
/// In addition to determining the file type based off of the header, this also sets the column indices for all the fields
/// that will be read when reading in the Identificatoin
/// </summary>
private PsmFileType GetFileTypeFromHeader(string header, bool usePepQValue = false)
{
PsmFileType type = PsmFileType.Unknown;
var split = header.Split('\t').Select(p => p.ToLowerInvariant()).ToArray();
// MetaMorpheus MS/MS input
if (split.Contains("File Name".ToLowerInvariant())
&& split.Contains("Base Sequence".ToLowerInvariant())
&& split.Contains("Full Sequence".ToLowerInvariant())
&& split.Contains("Peptide Monoisotopic Mass".ToLowerInvariant())
&& split.Contains("Scan Retention Time".ToLowerInvariant())
&& split.Contains("Precursor Charge".ToLowerInvariant())
&& split.Contains("Protein Accession".ToLowerInvariant())
&& split.Contains("Decoy/Contaminant/Target".ToLowerInvariant())
&& split.Contains("QValue".ToLowerInvariant())
&& split.Contains("QValue Notch".ToLowerInvariant()))
{
FileNameColumn = Array.IndexOf(split, "File Name".ToLowerInvariant());
BaseSeqColumn = Array.IndexOf(split, "Base Sequence".ToLowerInvariant());
FullSeqColumn = Array.IndexOf(split, "Full Sequence".ToLowerInvariant());
MonoisotopicMassColumn = Array.IndexOf(split, "Peptide Monoisotopic Mass".ToLowerInvariant());
MsmsRTColumn = Array.IndexOf(split, "Scan Retention Time".ToLowerInvariant());
ChargeStateColumn = Array.IndexOf(split, "Precursor Charge".ToLowerInvariant());
ProteinColumn = Array.IndexOf(split, "Protein Accession".ToLowerInvariant());
DecoyColumn = Array.IndexOf(split, "Decoy/Contaminant/Target".ToLowerInvariant());
ScoreColumn = Array.IndexOf(split, "Score".ToLowerInvariant());
if(usePepQValue)
{
QValueColumn = Array.IndexOf(split, "PEP_QValue".ToLowerInvariant());
QValueNotchColumn = Array.IndexOf(split, "PEP_QValue".ToLowerInvariant());
}
else
{
QValueColumn = Array.IndexOf(split, "QValue".ToLowerInvariant());
QValueNotchColumn = Array.IndexOf(split, "QValue Notch".ToLowerInvariant());
}
GeneNameColumn = Array.IndexOf(split, "Gene Name".ToLowerInvariant());
OrganismColumn = Array.IndexOf(split, "Organism Name".ToLowerInvariant());
return PsmFileType.MetaMorpheus;
}
// Morpheus MS/MS input
else if (split.Contains("Filename".ToLowerInvariant())
&& split.Contains("Base Peptide Sequence".ToLowerInvariant())
&& split.Contains("Peptide Sequence".ToLowerInvariant())
&& split.Contains("Theoretical Mass (Da)".ToLowerInvariant())
&& split.Contains("Retention Time (minutes)".ToLowerInvariant())
&& split.Contains("Precursor Charge".ToLowerInvariant())
&& split.Contains("Protein Description".ToLowerInvariant())
&& split.Contains("Decoy?".ToLowerInvariant())
&& split.Contains("Q-Value (%)".ToLowerInvariant()))
{
FileNameColumn = Array.IndexOf(split, "Filename".ToLowerInvariant());
BaseSeqColumn = Array.IndexOf(split, "Base Peptide Sequence".ToLowerInvariant());
FullSeqColumn = Array.IndexOf(split, "Peptide Sequence".ToLowerInvariant());
MonoisotopicMassColumn = Array.IndexOf(split, "Theoretical Mass (Da)".ToLowerInvariant());
MsmsRTColumn = Array.IndexOf(split, "Retention Time (minutes)".ToLowerInvariant());
ChargeStateColumn = Array.IndexOf(split, "Precursor Charge".ToLowerInvariant());
ProteinColumn = Array.IndexOf(split, "Protein Description".ToLowerInvariant());
DecoyColumn = Array.IndexOf(split, "Decoy?".ToLowerInvariant());
QValueColumn = Array.IndexOf(split, "Q-Value (%)".ToLowerInvariant());
GeneNameColumn = Array.IndexOf(split, "Gene Name".ToLowerInvariant()); // probably doesn't exist
OrganismColumn = Array.IndexOf(split, "Organism Name".ToLowerInvariant());
return PsmFileType.Morpheus;
}
// MaxQuant MS/MS input
else if (split.Contains("Raw file".ToLowerInvariant())
&& split.Contains("Sequence".ToLowerInvariant())
&& split.Contains("Modified sequence".ToLowerInvariant())
&& split.Contains("Mass".ToLowerInvariant())
&& split.Contains("Retention time".ToLowerInvariant())
&& split.Contains("Charge".ToLowerInvariant())
&& split.Contains("Proteins".ToLowerInvariant()))
{
FileNameColumn = Array.IndexOf(split, "Raw file".ToLowerInvariant());
BaseSeqColumn = Array.IndexOf(split, "Sequence".ToLowerInvariant());
FullSeqColumn = Array.IndexOf(split, "Modified sequence".ToLowerInvariant());
MonoisotopicMassColumn = Array.IndexOf(split, "Mass".ToLowerInvariant());
MsmsRTColumn = Array.IndexOf(split, "Retention time".ToLowerInvariant());
ChargeStateColumn = Array.IndexOf(split, "Charge".ToLowerInvariant());
ProteinColumn = Array.IndexOf(split, "Proteins".ToLowerInvariant());
GeneNameColumn = Array.IndexOf(split, "Gene Names".ToLowerInvariant());
OrganismColumn = Array.IndexOf(split, "Organism Name".ToLowerInvariant());
return PsmFileType.MaxQuant;
}
// Peptide Shaker Input
else if (split.Contains("Spectrum File".ToLowerInvariant())
&& split.Contains("Sequence".ToLowerInvariant())
&& split.Contains("Modified Sequence".ToLowerInvariant())
&& split.Contains("Theoretical Mass".ToLowerInvariant())
&& split.Contains("RT".ToLowerInvariant())
&& split.Contains("Identification Charge".ToLowerInvariant())
&& split.Contains("Protein(s)".ToLowerInvariant()))
{
FileNameColumn = Array.IndexOf(split, "Spectrum File".ToLowerInvariant());
BaseSeqColumn = Array.IndexOf(split, "Sequence".ToLowerInvariant());
FullSeqColumn = Array.IndexOf(split, "Modified Sequence".ToLowerInvariant());
MonoisotopicMassColumn = Array.IndexOf(split, "Theoretical Mass".ToLowerInvariant());
MsmsRTColumn = Array.IndexOf(split, "RT".ToLowerInvariant());
ChargeStateColumn = Array.IndexOf(split, "Identification Charge".ToLowerInvariant());
ProteinColumn = Array.IndexOf(split, "Protein(s)".ToLowerInvariant());
GeneNameColumn = Array.IndexOf(split, "Gene Name".ToLowerInvariant()); // probably doesn't exist
OrganismColumn = Array.IndexOf(split, "Organism Name".ToLowerInvariant());
return PsmFileType.PeptideShaker;
}
// Percolator Input
// Assume that no decoy are provided in this input
else if (split.Contains("file_idx".ToLowerInvariant())
&& split.Contains("scan".ToLowerInvariant())
&& split.Contains("charge".ToLowerInvariant())
&& split.Contains("spectrum neutral mass".ToLowerInvariant()) //experimental neutral mass
&& split.Contains("peptide mass".ToLowerInvariant()) //theoretical neutral (uncharged) peptide mass
&& split.Contains("sequence".ToLowerInvariant())
&& split.Contains("protein id".ToLowerInvariant()))
{
FileNameColumn = Array.IndexOf(split, "file_idx".ToLowerInvariant());
FullSeqColumn = Array.IndexOf(split, "sequence".ToLowerInvariant());
MonoisotopicMassColumn = Array.IndexOf(split, "peptide mass".ToLowerInvariant()); //TODO: see if this needs to be theoretical or experimental mass AND if it is neutral or monoisotopic(H+)
MsmsScanNumberColumn = Array.IndexOf(split, "scan".ToLowerInvariant());
ChargeStateColumn = Array.IndexOf(split, "charge".ToLowerInvariant());
ProteinColumn = Array.IndexOf(split, "protein id".ToLowerInvariant());
QValueColumn = Array.IndexOf(split, "percolator q-value".ToLowerInvariant());
return PsmFileType.Percolator;
}
// Generic MS/MS input
if (split.Contains("File Name".ToLowerInvariant())
&& split.Contains("Base Sequence".ToLowerInvariant())
&& split.Contains("Full Sequence".ToLowerInvariant())
&& split.Contains("Peptide Monoisotopic Mass".ToLowerInvariant())
&& split.Contains("Scan Retention Time".ToLowerInvariant())
&& split.Contains("Precursor Charge".ToLowerInvariant())
&& split.Contains("Protein Accession".ToLowerInvariant()))
{
FileNameColumn = Array.IndexOf(split, "File Name".ToLowerInvariant());
BaseSeqColumn = Array.IndexOf(split, "Base Sequence".ToLowerInvariant());
FullSeqColumn = Array.IndexOf(split, "Full Sequence".ToLowerInvariant());
MonoisotopicMassColumn = Array.IndexOf(split, "Peptide Monoisotopic Mass".ToLowerInvariant());
MsmsRTColumn = Array.IndexOf(split, "Scan Retention Time".ToLowerInvariant());
ChargeStateColumn = Array.IndexOf(split, "Precursor Charge".ToLowerInvariant());
ProteinColumn = Array.IndexOf(split, "Protein Accession".ToLowerInvariant());
GeneNameColumn = Array.IndexOf(split, "Gene Name".ToLowerInvariant()); // probably doesn't exist
OrganismColumn = Array.IndexOf(split, "Organism Name".ToLowerInvariant());
QValueColumn = Array.IndexOf(split, "Q-Value".ToLowerInvariant());
DecoyColumn = Array.IndexOf(split, "Target/Decoy".ToLowerInvariant());
return PsmFileType.Generic;
}
return type;
}
private static string ApplyRegex(FastaHeaderFieldRegex regex, string line)
{
string result = null;
if (regex != null)
{
var matches = regex.Regex.Matches(line);
if (matches.Count > regex.Match && matches[regex.Match].Groups.Count > regex.Group)
{
result = matches[regex.Match].Groups[regex.Group].Value;
}
}
return result;
}
}
}