-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
190 lines (168 loc) · 11.1 KB
/
Program.cs
File metadata and controls
190 lines (168 loc) · 11.1 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
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using Cif;
using Cif.Tables;
using Cif.Filtering;
using SecStrAnnotator2.Utils;
namespace SecStrAnnotator2
{
class Program
{
static int Main(string[] args)
{
return protein.MainClass.Main_SecStrAnnot1(args);
}
static int TestingMain(string[] args)
{
if (args.Length == 0)
{
args = new string[] { "../SecStrAnnot2_data/1tqn_updated.cif" };
}
foreach (string filename in args)
{
// Console.Error.WriteLine("\n" + filename);
Cif.Components.Protein p = CifWrapperForSecStrAnnot1.ProteinFromCifFile(filename);
// p.Save(filename + "-converted.pdb");
Lib2.WriteLineDebug("Read and pseudoconverted " + filename);
// continue;
try
{
string text = "";
DateTime t0 = DateTime.Now;
using (StreamReader r = new StreamReader(filename))
{
text = r.ReadToEnd();
}
DateTime t1 = DateTime.Now;
CifPackage pack = CifPackage.FromString(text);
string blockName = pack.BlockNames[0];
CifBlock block = pack[blockName];
DateTime t2 = DateTime.Now;
CifCategory category = block["_atom_site"];
// CifItem item = category["label_atom_id"];
// int[] cAlphas = block.GetItem("_atom_site.label_atom_id").GetRowsWith("CA"); // or item.GetRowsWith("CA");
// AtomTable atoms = new AtomTable(block, cAlphas); // or new AtomTable(category, cAlphas);
// if (block.ContainsCategory("_pdbx_struct_sheet_hbond")){
// CifCategory sheetCategory = block["_pdbx_struct_sheet_hbond"];
// CifItem sheetId = sheetCategory["sheet_id"];
// int[] sheetIdB = sheetId.GetRowsWith("B");
// Table table = sheetCategory.MakeTable(sheetIdB, ("sheet_id", CifValueType.Char), ("range_1_label_comp_id", CifValueType.String), ("range_1_label_seq_id", CifValueType.Integer));
// }
// int[] startsOfEntities;
// int[] startsOfChains;
// int[] startChainsOfEntities;
// int[] groupedRows = Enumerable.Range(0, category.RowCount).ToArray();
// groupedRows = category["label_entity_id"].GetRowsGroupedByValue(groupedRows, out startsOfEntities);
// Lib.LogList("Grouped rows", groupedRows);
// Lib.LogList("Starts of entities", startsOfEntities);
// groupedRows = category["label_asym_id"].GetRowsGroupedByValueInEachRegion(groupedRows, startsOfEntities, out startsOfChains, out startChainsOfEntities);
// Lib.LogList("Starts of chains", startsOfChains);
// Lib.LogList("Start chains of entities", startChainsOfEntities);
// return;
ModelCollection mc = ModelCollection.FromCifBlock(block/*, block["_atom_site"]["label_atom_id"].GetRowsWith("CA")*/);
foreach (Model model in mc.GetModels())
{
// Lib.WriteLineDebug("Model " + model.ModelNumber + " (" + model.Atoms.Count + " atoms)\n");
// Lib.WriteLineDebug(model.Print() + "\n");
}
DateTime t3 = DateTime.Now;
Filter filter1 = Filter.IntegerInRange("label_seq_id", (100, 105), (200, 202))
// & Filter.StringEquals("label_comp_id", new string[]{"TRP","CYS"})
& Filter.StringEquals("label_atom_id", new string[] { "CA", "N" })
& Filter.StringEquals("label_asym_id", new string[] { "A" });
Filter filter2 = Filter.IntegerInRange("label_seq_id", (100, 105))
| Filter.StringEquals("label_comp_id", new string[] { "TRP", "CYS" })
| Filter.StringEquals("label_atom_id", new string[] { "CA" });
Filter filter3 = !Filter.IntegerInRange("label_seq_id", (0, 390)) & !Filter.IsNull("label_seq_id");
Filter filter4 = Filter.TheseRows(new int[] { 0, 1, 2, 5 });
Filter filter5 = Filter.Where("label_seq_id", str => str.Contains('5')) & Filter.StringEquals("label_atom_id", new string[] { "CA" });
int[] filteredRows = filter5.GetFilteredRows(category).ToArray();
string[] atomIds = category["id"].GetStrings(filteredRows);
string[] atomNames = category["label_atom_id"].GetStrings(filteredRows);
string[] seqIds = category["label_seq_id"].GetStrings(filteredRows);
string[] compIds = category["label_comp_id"].GetStrings(filteredRows);
string[] asymIds = category["label_asym_id"].GetStrings(filteredRows);
string[] entityIds = category["label_entity_id"].GetStrings(filteredRows);
Console.WriteLine("row \tatom \ta.name\t comp seq\tasym \tentity");
for (int iRow = 0; iRow < atomIds.Length; iRow++)
{
Console.WriteLine($"{iRow}:\t {atomIds[iRow]}\t {atomNames[iRow]}\t {compIds[iRow]} {seqIds[iRow]} \t {asymIds[iRow]}\t {entityIds[iRow]}");
}
Console.WriteLine(string.Join(" ", filteredRows));
Console.WriteLine(category.MakeCifString(filteredRows));
// string[] atomIds = category["id"].GetStrings();
// string[] atomNames = category["label_atom_id"].GetStrings();
// string[] seqIds = category["label_seq_id"].GetStrings();
// string[] compIds = category["label_comp_id"].GetStrings();
// string[] asymIds = category["label_asym_id"].GetStrings();
// string[] entityIds = category["label_entity_id"].GetStrings();
// Console.WriteLine("row \tatom \ta.name\t comp seq\tasym \tentity");
// for (int iRow = 0; iRow < atomIds.Length; iRow++){
// Console.WriteLine($"{iRow}:\t {atomIds[iRow]}\t {atomNames[iRow]}\t {compIds[iRow]} {seqIds[iRow]} \t {asymIds[iRow]}\t {entityIds[iRow]}");
// }
// Lib.WriteLineDebug("SORTED:");
// Console.WriteLine("row \tatom \ta.name\t comp seq\tasym \tentity");
// foreach (int iRow in groupedRows){
// Console.WriteLine($"{iRow}:\t {atomIds[iRow]}\t {atomNames[iRow]}\t {compIds[iRow]} {seqIds[iRow]} \t {asymIds[iRow]}\t {entityIds[iRow]}");
// }
// Lib.WriteLineDebug(table.GetColumn<char>("sheet_id").Enumerate());
// Lib.WriteLineDebug(table.GetColumn<string>("range_1_label_comp_id").Enumerate());
// Lib.WriteLineDebug(table.GetColumn<int>("range_1_label_seq_id").Enumerate());
//int[] cAlphas = block.GetItem("_atom_site.label_atom_id").GetIndicesWhere(name => name == "CA");
//int[] cAlphas = block.GetItem("_atom_site.label_atom_id").GetIndicesWhere((txt,i,j) => j-i == 2 && txt[i] == 'C' && txt[i+1] == 'A');
//int[] cAlphas = block.GetItem("_atom_site.label_atom_id").GetIndicesWith("CA");
/*double[] xs = block.GetItem("_atom_site.Cartn_x").GetDoubles(cAlphas);
double[] ys = block.GetItem("_atom_site.Cartn_y").GetDoubles(cAlphas);
double[] zs = block.GetItem("_atom_site.Cartn_z").GetDoubles(cAlphas);
string[] names = block.GetItem("_atom_site.auth_atom_id").GetStrings(cAlphas);*/
/*for (int i = 0; i < 10; i++)
{
int[] cAlphas = block.GetItem("_atom_site.label_atom_id").GetIndicesWith("CA");
// double[] xs = block.GetItem("_atom_site.Cartn_x").GetDoubles();
// double[] ys = block.GetItem("_atom_site.Cartn_y").GetDoubles();
// double[] zs = block.GetItem("_atom_site.Cartn_z").GetDoubles();
// int[] resis = block.GetItem("_atom_site.auth_seq_id").GetIntegers();
// Lib.WriteLineDebug(xs.Length + " xs: " + xs.Enumerate());
// Lib.WriteLineDebug(resis.Length + " resis: " + resis.Enumerate());
}*/
//Lib.WriteLineDebug(cAlphas.Length + " CAs: " + cAlphas.Enumerate());
//Lib.WriteLineDebug(" resis: " + atoms.labelResSeq.Enumerate());
//Lib.WriteLineDebug(" Xs: " + atoms.X.Enumerate());
Func<TimeSpan, string> Format = span => span.TotalSeconds.ToString("0.000");
Lib2.WriteLineDebug("Read: " + Format(t1 - t0));
Lib2.WriteLineDebug("Parse: " + Format(t2 - t1));
Lib2.WriteLineDebug(" Set text: " + Format(pack.Parser.TimeStamps.SetTextDone - t1));
Lib2.WriteLineDebug(" Lexical: " + Format(pack.Parser.TimeStamps.LexicalAnalysisDone - pack.Parser.TimeStamps.SetTextDone));
Lib2.WriteLineDebug(" Names: " + Format(pack.Parser.TimeStamps.ExtractNamesDone - pack.Parser.TimeStamps.LexicalAnalysisDone));
Lib2.WriteLineDebug(" Syntactic: " + Format(pack.Parser.TimeStamps.SyntacticAnalysisDone - pack.Parser.TimeStamps.ExtractNamesDone));
Lib2.WriteLineDebug(" ?: " + Format(t2 - pack.Parser.TimeStamps.SyntacticAnalysisDone));
Lib2.WriteLineDebug("Extract: " + Format(t3 - t2));
}
catch (CifException e)
{
Lib2.WriteErrorAndExit(e.Message);
}
}
return 0;
}
private static bool CmpStr(string text, int index, string sample)
{
for (int i = 0; i < sample.Length; i++)
{
if (text[index + i] != sample[i]) return false;
}
return true;
}
private static bool CmpStr(string text, int index, string sample, int textLength, int sampleLength)
{
if (index + sampleLength > textLength) return false;
for (int i = 0; i < sampleLength; i++)
{
if (text[index + i] != sample[i]) return false;
}
return true;
}
}
}