-
Notifications
You must be signed in to change notification settings - Fork 2
/
20210819-ProForma-formatter-MSPT.cs
115 lines (111 loc) · 4.11 KB
/
20210819-ProForma-formatter-MSPT.cs
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
using System;
using System.IO;
using System.Data;
using System.Text;
namespace ProFormaFormatter {
class Program {
static void Main(string[] args)
{
if (args.Length==0) {
Console.WriteLine("Supply the name of the _IcTarget.tsv file for processing.");
Environment.Exit(1);
}
DataTable datatable = new DataTable();
string FileString = args[0];
StreamReader streamreader = new StreamReader(FileString);
//skip the header
// for (int i=0; i<27; i++) {
// string Header=streamreader.ReadLine();
// Console.WriteLine(Header);
// }
char[] delimiter = new char[] { '\t' };
char[] PathDelimiters = new char[] { '\\','/' };
string FNameTrailer = "_IcTarget.tsv";
string[] columnheaders = streamreader.ReadLine().Split(delimiter);
foreach (string columnheader in columnheaders)
{
datatable.Columns.Add(columnheader);
}
while (streamreader.Peek() > 0)
{
DataRow datarow = datatable.NewRow();
datarow.ItemArray = streamreader.ReadLine().Split(delimiter);
datatable.Rows.Add(datarow);
}
foreach (DataRow row in datatable.Rows) {
// string FName = Convert.ToString(row["Data file name"]);
string OutScan = Convert.ToString(row["Scan"]);
string OutProForma = Convert.ToString(row["Sequence"]);
string OutSequence = OutProForma;
string OutCharge = Convert.ToString(row["Charge"]);
string OutAccession = Convert.ToString(row["ProteinName"]);
int OutMassAdded = 0;
string PTMs = Convert.ToString(row["Modifications"]);
float Probability = Convert.ToSingle(row["Probability"]);
float Evalue = Convert.ToSingle(row["EValue"]);
double OutEVal = -Math.Log(Convert.ToDouble(row["EValue"]));
if ((Probability > 0.5) && (Evalue < 0.01)) {
// string[] FNameChunks = FName.Split(PathDelimiters);
string OutFile = FileString;
if (OutFile.EndsWith(FNameTrailer)) {
OutFile = OutFile.Substring(0,OutFile.Length-FNameTrailer.Length);
}
// Parse out just the second bit of the UniProt accession
string[] AccessionArray = OutAccession.Split('|');
OutAccession = AccessionArray[1];
// Create a decorated sequence by incorporating PTM string data.
string[] PTMArray = PTMs.Split(',');
int CurrentOutProFormaPos = 0;
StringBuilder DecoratedOutProForma = new StringBuilder();
foreach (string ThisPTM in PTMArray) {
if (ThisPTM.Length > 0) {
string[] PTMFields = ThisPTM.Split(' ');
int Pos = Convert.ToInt32(PTMFields[1]);
string PTMID = PTMFields[0];
if (PTMID == "Oxidation")
OutMassAdded += 16;
else if (PTMID == "Methyl")
OutMassAdded += 14;
else if (PTMID == "Acetyl")
OutMassAdded += 42;
else if (PTMID == "Carbamidomethyl")
OutMassAdded += 57;
else if (PTMID == "Phospho")
OutMassAdded += 80;
if (Pos == 0) {
DecoratedOutProForma.Append("[");
DecoratedOutProForma.Append(Convert.ToString(PTMFields[0]));
DecoratedOutProForma.Append("]-");
DecoratedOutProForma.Append(OutProForma.Substring(CurrentOutProFormaPos, Pos-CurrentOutProFormaPos));
}
else {
DecoratedOutProForma.Append(OutProForma.Substring(CurrentOutProFormaPos, Pos-CurrentOutProFormaPos));
DecoratedOutProForma.Append("[");
DecoratedOutProForma.Append(Convert.ToString(PTMFields[0]));
DecoratedOutProForma.Append("]");
}
CurrentOutProFormaPos = Pos;
}
}
DecoratedOutProForma.Append(OutProForma.Substring(CurrentOutProFormaPos));
OutProForma = Convert.ToString(DecoratedOutProForma);
Console.Write(OutFile);
Console.Write("\t");
Console.Write(OutScan);
Console.Write("\t");
Console.Write(OutCharge);
Console.Write("\t");
Console.Write(OutAccession);
Console.Write("\t");
Console.Write(OutSequence);
Console.Write("\t");
Console.Write(OutMassAdded);
Console.Write("\t");
Console.Write(OutProForma);
Console.Write("\t");
Console.WriteLine(OutEVal);
}
}
}
}
}