-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCifWrapperForSecStrAnnot1.cs
More file actions
76 lines (69 loc) · 3.27 KB
/
CifWrapperForSecStrAnnot1.cs
File metadata and controls
76 lines (69 loc) · 3.27 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
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using Cif;
using Cif.Tables;
using Cif.Filtering;
using Cif.Components;
using SecStrAnnotator2.Utils;
namespace SecStrAnnotator2
{
public static class CifWrapperForSecStrAnnot1
{
private const string EXCEPTION_MESSAGE = "Cannot fit CIF data to PDB data model: ";
private const char PDB_DEFAULT_ALT_LOC = ' ';
private const char PDB_DEFAULT_INS_CODE = ' ';
private const double DEFAULT_OCCUPANCY = 1.0;
private const double DEFAULT_TEMP_FACTOR = 0.0;
private const string DEFAULT_CHARGE = " ";
public static Cif.Components.Protein ProteinFromCifFile(string filename, string chainId = null, (int, int)[] resSeqRanges = null)
{
CifPackage package = CifPackage.FromFile(filename);
if (package.BlockNames.Length < 1)
{
throw new FormatException(EXCEPTION_MESSAGE + "CIF file must contain at least one block");
}
CifCategory category = package.Blocks[0].GetCategory(ModelCollection.CATEGORY_NAME);
// int[] rows = category.GetItem(ChainTable.ID_COLUMN).GetRowsWith(chainId.ToString()).ToArray(); // filter rows by chain ID
// int[] seqNumbers = category.GetItem(ResidueTable.SEQ_NUMBER_COLUMN).GetIntegers(rows, 0);
// rows = rows.Where( (r, i) => resSeqRanges.Any(range => range.Item1 <= seqNumbers[i] && seqNumbers[i] <= range.Item2) ).ToArray(); // filter rows by resi
ModelCollection models;
if (chainId != null || resSeqRanges != null)
{
Filter filter;
if (chainId != null && resSeqRanges != null)
filter = Filter.StringEquals(ChainTable.ID_COLUMN, chainId) & Filter.IntegerInRange(ResidueTable.SEQ_NUMBER_COLUMN, resSeqRanges);
else if (chainId != null)
filter = Filter.StringEquals(ChainTable.ID_COLUMN, chainId);
else
filter = Filter.IntegerInRange(ResidueTable.SEQ_NUMBER_COLUMN, resSeqRanges);
int[] rows = filter.GetFilteredRows(category).ToArray();
models = ModelCollection.FromCifCategory(category, rows);
}
else
{
models = ModelCollection.FromCifCategory(category);
}
Model model;
if (models.Count >= 1)
{
model = models.GetModel(0);
}
else
{
string rangeString = String.Join(",", resSeqRanges.Select(range => range.Item1 + ":" + range.Item2));
// throw new FormatException(EXCEPTION_MESSAGE + $"Atom selection given by chain ID '{chainId}' and residue ranges '{rangeString}' is empty");
Lib2.WriteWarning($"Empty model: Atom selection given by chain ID '{chainId}' and residue ranges '{rangeString}' is empty");
model = new ModelBuilder().GetModel();
}
Protein protein = ProteinFromCifModel(model);
return protein;
}
public static Cif.Components.Protein ProteinFromCifModel(Model model)
{
return new Cif.Components.Protein(model);
}
}
}