dcatoolkit 0.1.6__tar.gz → 0.1.7__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
1
  Metadata-Version: 2.1
2
2
  Name: dcatoolkit
3
- Version: 0.1.6
3
+ Version: 0.1.7
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.1.6"
7
+ version = "0.1.7"
8
8
  description = "Collection of useful modules and representations for managing DCA output data."
9
9
  keywords = ["dca", "toolkit", "DI", "coevolution"]
10
10
 
@@ -1,4 +1,4 @@
1
1
 
2
- __version__ = "0.1.6"
2
+ __version__ = "0.1.7"
3
3
  from .representation import Pairs, DirectInformationData, StructureInformation, ResidueAlignment
4
4
  from .analytics import MSATools
@@ -1,7 +1,7 @@
1
1
  import re
2
2
  from collections import Counter
3
- from typing import Optional
4
- import string
3
+ from typing import Optional, Union
4
+ import string, io
5
5
 
6
6
  class MSATools:
7
7
  """
@@ -16,23 +16,31 @@ class MSATools:
16
16
  self.MSA = MSA
17
17
 
18
18
  @staticmethod
19
- def load_from_file(msa_filepath: str) -> 'MSATools':
19
+ def load_from_file(msa_source: Union[str, io.IOBase]) -> 'MSATools':
20
20
  """
21
21
  Generates MSATools object from an MSA file in ".afa" format.
22
22
 
23
23
  Parameters
24
24
  ----------
25
- msa_filepath : str
26
- Filepath of the MSA in ".afa" format that is provided.
25
+ msa_source : str or io.IOBase
26
+ Filepath or IOBase of the MSA in ".afa" format that is provided.
27
27
 
28
28
  Returns
29
29
  -------
30
30
  MSATools
31
31
  An MSATools instance with the appropriate list of (header, sequence) tuples where sequences are simplified and converted to single line format.
32
32
  """
33
+ data = ""
33
34
  msa_entries: list[tuple[str, str]] = []
34
- with open(msa_filepath, 'r') as fs:
35
- data = fs.read()
35
+ if isinstance(msa_source, str):
36
+ with open(msa_source, 'r') as fs:
37
+ data = fs.read()
38
+ elif isinstance(msa_source, io.BytesIO):
39
+ data = msa_source.getvalue().decode()
40
+ elif isinstance(msa_source, io.StringIO):
41
+ data = msa_source.getvalue()
42
+ else:
43
+ raise Exception("msa_file is not bytesIO, stringIO, or a filepath.")
36
44
  split_data = data.split(">")[1:]
37
45
  for entry in split_data:
38
46
  line_split_entry = entry.split("\n")
@@ -113,25 +121,32 @@ class MSATools:
113
121
  kept_entries.append((header, sequence))
114
122
  return kept_entries
115
123
 
116
- def write(self, filepath: str) -> None:
124
+ def write(self, destination: Union[str, io.IOBase]) -> None:
117
125
  """
118
- Writes this MSA's headers and sequences to the filepath specified.
126
+ Writes this MSA's headers and sequences to the destination specified.
119
127
 
120
128
  Parameters
121
129
  ----------
122
- filepath : str
123
- Filepath to write the MSA supplied to.
130
+ destination : str or io.IOBase
131
+ Filepath or IO to write the MSA supplied to.
124
132
 
125
133
  Returns
126
134
  -------
127
135
  None
128
136
  """
129
- with open(filepath, 'w') as fs:
137
+ if isinstance(destination, str):
138
+ with open(destination, 'w') as fs:
139
+ for header, sequence in self.MSA:
140
+ fs.write(header)
141
+ fs.write("\n")
142
+ fs.write(sequence)
143
+ fs.write("\n")
144
+ elif isinstance(destination, io.IOBase):
130
145
  for header, sequence in self.MSA:
131
- fs.write(header)
132
- fs.write("\n")
133
- fs.write(sequence)
134
- fs.write("\n")
146
+ destination.write(header)
147
+ destination.write("\n")
148
+ destination.write(sequence)
149
+ destination.write("\n")
135
150
 
136
151
  def __len__(self):
137
152
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dcatoolkit
3
- Version: 0.1.6
3
+ Version: 0.1.7
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>
File without changes
File without changes
File without changes