dcatoolkit 0.2.0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: dcatoolkit
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Collection of useful modules and representations for managing DCA output data.
5
5
  Author-email: Raheel Syed Ahmed <raheelsyedahmed@gmail.com>
6
6
  Maintainer-email: Raheel Syed Ahmed <raheelsyedahmed@gmail.com>
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "dcatoolkit"
7
- version = "0.2.0"
7
+ version = "0.2.2"
8
8
  description = "Collection of useful modules and representations for managing DCA output data."
9
9
  keywords = ["dca", "toolkit", "DI", "coevolution"]
10
10
 
@@ -1,5 +1,5 @@
1
1
 
2
- __version__ = "0.1.9"
2
+ __version__ = "0.2.2"
3
3
  from .representation import Pairs, DirectInformationData, StructureInformation, ResidueAlignment, MMCIFInformation, PDBInformation
4
4
  from .analytics import MSATools
5
5
 
@@ -546,7 +546,7 @@ class DirectInformationData:
546
546
  return results
547
547
 
548
548
  @staticmethod
549
- def get_dist_commands(model1: str | int, model2: str | int, chain1: str, chain2: str, pairs: npt.NDArray, ca_only: bool=True, auth_res_ids=False) -> list[str]:
549
+ def get_dist_commands(model1: str | int, model2: str | int, chain1: str, chain2: str, pairs: npt.NDArray, ca_only: bool=True, auth_res_ids: bool=False) -> list[str]:
550
550
  """
551
551
  Get UCSF Chimera commands for displaying distance commands for usage in displaying distances between residue pairs. Options are present for alpha-carbon to alpha-carbon distance or for specified atom to specified atom distance.
552
552
 
@@ -624,7 +624,7 @@ class StructureInformation:
624
624
  """
625
625
  @overload
626
626
  @staticmethod
627
- def fetch_pdb(pdb_id: str, struc_format: Literal["mmcif"]="mmcif", model_num: int=1) -> 'MMCIFInformation':
627
+ def fetch_pdb(pdb_id: str, struc_format: Literal["mmcif"], model_num: int=1) -> 'MMCIFInformation':
628
628
  ...
629
629
 
630
630
  @overload
@@ -787,32 +787,15 @@ class MMCIFInformation(StructureInformation):
787
787
  if len(self.pdbx_file.keys()) > 0:
788
788
  self.first_block = list(self.pdbx_file)[0]
789
789
  self.atom_site_category = self.pdbx_file[self.first_block].get('atom_site')
790
- self.chain_auth_dict = {}
791
- self.auth_chain_dict = {}
792
- self.res_auth_dict = {}
790
+ self.chain_auth_dict: dict[str, str] = {}
791
+ self.auth_chain_dict: dict[str, str] = {}
792
+ self.res_auth_dict: dict[str, tuple[int, int]] = {}
793
+
793
794
  if self.atom_site_category:
794
- group_pdbs = []
795
- seq_ids = []
796
- asym_ids = []
797
- auth_seq_ids = []
798
- auth_asym_ids = []
799
- model_nums = []
800
- for col_name, col in self.atom_site_category.items():
801
- if col_name == 'group_PDB':
802
- group_pdbs = col.as_array()
803
- elif col_name == 'label_seq_id':
804
- seq_ids = col.as_array()
805
- elif col_name == 'label_asym_id':
806
- asym_ids = col.as_array()
807
- elif col_name == 'auth_seq_id':
808
- auth_seq_ids = col.as_array()
809
- elif col_name == 'auth_asym_id':
810
- auth_asym_ids = col.as_array()
811
- elif col_name == 'pdbx_PDB_model_num':
812
- model_nums = col.as_array()
813
-
814
- atom_site_data = np.unique(np.column_stack((group_pdbs, seq_ids, asym_ids, auth_seq_ids, auth_asym_ids, model_nums)), axis=0)
815
- atom_site_data = atom_site_data[atom_site_data[:,5] == str(self.model_num)]
795
+ categories = ['group_PDB', 'label_seq_id', 'label_asym_id', 'auth_seq_id', 'auth_asym_id', 'pdbx_PDB_model_num']
796
+ atom_site_data = np.column_stack([self.atom_site_category[category].as_array() for category in categories])
797
+ _, idx = np.unique(atom_site_data, axis=0, return_index=True)
798
+ atom_site_data = atom_site_data[np.sort(idx)]
816
799
  self.atom_data = atom_site_data[atom_site_data[:,0] == "ATOM"]
817
800
  self.het_atom_data = atom_site_data[atom_site_data[:,0] == "HETATM"]
818
801
  self.unique_chains = np.unique(self.atom_data[:,2])
@@ -824,6 +807,31 @@ class MMCIFInformation(StructureInformation):
824
807
  else:
825
808
  self.atom_site_category = None
826
809
 
810
+ def get_start_res_id(self, chain_id: str, auth_res_ids: bool=False, auth_chain_id_supplied: bool=False) -> int:
811
+ """
812
+ Gets starting residue id of the specified chain excluding heteroatom group entries.
813
+
814
+ Parameters
815
+ ----------
816
+ chain_id : str
817
+ The chain id supplied and selected for from the structure.
818
+ auth_res_ids : bool
819
+ True if you want alt_ids for residues indices, False if cif residue indexing is needed.
820
+ auth_chain_id_supplied : bool
821
+ If True, the chain_id supplied is the auth chain id found on the RCSB website.
822
+
823
+ Returns
824
+ -------
825
+ int
826
+ The residue id of the first atom in the chain provided.
827
+ """
828
+ if auth_chain_id_supplied:
829
+ chain_id = self.auth_chain_dict[chain_id]
830
+ if auth_res_ids:
831
+ return self.res_auth_dict[chain_id][1]
832
+ else:
833
+ return self.res_auth_dict[chain_id][0]
834
+
827
835
  def get_full_sequence(self, chain_id: str, auth_chain_id_supplied: bool=False) -> str:
828
836
  """
829
837
  Get full sequence, including missing residues, from the specified chain off of RCSB.
@@ -1067,6 +1075,26 @@ class PDBInformation(StructureInformation):
1067
1075
  self.non_missing_sequences = {str(chain): str(sequence) for (chain, sequence) in list(zip(struc.get_chains(non_hetero_structure), struc.to_sequence(non_hetero_structure)[0]))}
1068
1076
  self.unique_chains = struc.get_chains(non_hetero_structure)
1069
1077
 
1078
+ def get_start_res_id(self, chain_id: str) -> int:
1079
+ """
1080
+ Gets starting residue id of the specified chain excluding heteroatom group entries.
1081
+
1082
+ Parameters
1083
+ ----------
1084
+ chain_id : str
1085
+ The chain id supplied and selected for from the structure.
1086
+
1087
+ Returns
1088
+ -------
1089
+ int
1090
+ The residue id of the first atom in the chain provided.
1091
+ """
1092
+ non_hetero_structure = self.structure[self.structure.hetero == False]
1093
+ if chain_id in self.unique_chains:
1094
+ return non_hetero_structure[non_hetero_structure.chain_id == chain_id][0].res_id
1095
+ else:
1096
+ raise ValueError("Chain supplied not found in structure.")
1097
+
1070
1098
  def get_non_missing_sequence(self, chain_id: str) -> str:
1071
1099
  """
1072
1100
  Get sequence, including only non-missing residues, from the specified chain.
@@ -1159,6 +1187,8 @@ class PDBInformation(StructureInformation):
1159
1187
  if chain1 in self.unique_chains and chain2 in self.unique_chains:
1160
1188
  shift1 = non_hetero_structure[non_hetero_structure.chain_id == chain1][0].res_id - 1
1161
1189
  shift2 = non_hetero_structure[non_hetero_structure.chain_id == chain2][0].res_id - 1
1190
+ shift1 *= -1
1191
+ shift2 *= -1
1162
1192
  return shift1, shift2
1163
1193
  else:
1164
1194
  return shift1, shift2
@@ -1195,8 +1225,8 @@ class PDBInformation(StructureInformation):
1195
1225
  ind = np.unravel_index(np.argmin(dist_matrix), dist_matrix.shape)
1196
1226
  # Use the indices to access the atom in the atom array and get the correct atom name.
1197
1227
  # Generate the auth ids of the residues in the pairs ndarray
1198
- orig_res_id1 = row['residue1'] - shift1
1199
- orig_res_id2 = row['residue2'] - shift2
1228
+ orig_res_id1 = row['residue1'] + shift1
1229
+ orig_res_id2 = row['residue2'] + shift2
1200
1230
  min_dist_pairs_atoms.append((orig_res_id1, orig_res_id2, row['residue1'], row['residue2'], chain1_res1_structure[ind[0]].atom_name, chain2_res2_structure[ind[1]].atom_name))
1201
1231
  min_dist_pairs_atoms_arr = np.array(min_dist_pairs_atoms, dtype={'names': ['residue1','residue2','auth_residue1','auth_residue2','atom_name1','atom_name2'], 'formats': [int,int,int,int,'<U10','<U10']})
1202
1232
  return min_dist_pairs_atoms_arr
@@ -1235,7 +1265,7 @@ class PDBInformation(StructureInformation):
1235
1265
  if not(chain1==chain2 and res1 >= res2):
1236
1266
  if not auth_contacts:
1237
1267
  shift1, shift2 = self.get_shift_values(chain1, chain2)
1238
- contacts_set.add((res1 - shift1, res2 - shift2))
1268
+ contacts_set.add((res1 + shift1, res2 + shift2))
1239
1269
  else:
1240
1270
  contacts_set.add((res1, res2))
1241
1271
  return contacts_set
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: dcatoolkit
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Collection of useful modules and representations for managing DCA output data.
5
5
  Author-email: Raheel Syed Ahmed <raheelsyedahmed@gmail.com>
6
6
  Maintainer-email: Raheel Syed Ahmed <raheelsyedahmed@gmail.com>
@@ -59,9 +59,9 @@ def check_contacts(test_CA: bool, threshold: float):
59
59
 
60
60
  cif_file_contacts = read_contacts(corresponding_file)
61
61
  chain1, auth_chain1, chain2, auth_chain2 = pdb_id_chain_map[pdb_id]
62
- fetch_cif_contacts = {(int(x[0]), int(x[1])) for x in MMCIFInformation.fetch_pdb(pdb_id).get_contacts(test_CA, threshold, chain1, chain2, auth_contacts=True)}
62
+ fetch_cif_contacts = {(int(x[0]), int(x[1])) for x in MMCIFInformation.fetch_pdb(pdb_id, 'mmcif').get_contacts(test_CA, threshold, chain1, chain2, auth_contacts=True)}
63
63
  read_cif_contacts = {(int(x[0]), int(x[1])) for x in MMCIFInformation.read_mmCIF_file(str(cif_file)).get_contacts(test_CA, threshold, chain1, chain2, auth_contacts=True)}
64
- fetch_authchain_cif_contacts = {(int(x[0]), int(x[1])) for x in MMCIFInformation.fetch_pdb(pdb_id).get_contacts(test_CA, threshold, auth_chain1, auth_chain2, auth_contacts=True, auth_chain_id_supplied=True)}
64
+ fetch_authchain_cif_contacts = {(int(x[0]), int(x[1])) for x in MMCIFInformation.fetch_pdb(pdb_id, 'mmcif').get_contacts(test_CA, threshold, auth_chain1, auth_chain2, auth_contacts=True, auth_chain_id_supplied=True)}
65
65
  read_authchain_cif_contacts = {(int(x[0]), int(x[1])) for x in MMCIFInformation.read_mmCIF_file(str(cif_file)).get_contacts(test_CA, threshold, auth_chain1, auth_chain2, auth_contacts=True, auth_chain_id_supplied=True)}
66
66
  fetch_pdb_contacts = {(int(x[0]), int(x[1])) for x in PDBInformation.fetch_pdb(pdb_id, struc_format="pdb").get_contacts(test_CA, threshold, auth_chain1, auth_chain2, auth_contacts=True)}
67
67
  read_pdb_contacts = {(int(x[0]), int(x[1])) for x in PDBInformation.read_pdb_file(f"tests/pdb_info/{pdb_id.lower()}.pdb").get_contacts(test_CA, threshold, auth_chain1, auth_chain2, auth_contacts=True)}
File without changes
File without changes
File without changes