-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pfam/tigrfam): Add PFAM/TIGRFAM output parsers.
- Loading branch information
1 parent
625c597
commit 35c0755
Showing
5 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
**** | ||
PFAM | ||
**** | ||
|
||
Helper functions | ||
---------------- | ||
|
||
.. autofunction:: magna.pfam.read_pfam | ||
|
||
|
||
.. autofunction:: magna.pfam.read_pfam_tophit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
******* | ||
TIGRFAM | ||
******* | ||
|
||
|
||
Helper functions | ||
---------------- | ||
|
||
.. autofunction:: magna.tigrfam.read_tigrfam | ||
|
||
|
||
.. autofunction:: magna.tigrfam.read_tigrfam_tophit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import numpy as np | ||
import pandas as pd | ||
|
||
|
||
def read_pfam(path: str) -> pd.DataFrame: | ||
"""Read the PFAM file. | ||
Args: | ||
path: The path to the PFAM file. | ||
""" | ||
dtype = { | ||
'seq_id': object, | ||
'aln_start': np.uintc, | ||
'aln_end': np.uintc, | ||
'env_start': np.uintc, | ||
'env_end': np.uintc, | ||
'hmm_acc': object, | ||
'hmm_name': object, | ||
'type': object, | ||
'hmm_start': np.uintc, | ||
'hmm_end': np.uintc, | ||
'hmm_length': np.float64, | ||
'bit_score': np.float64, | ||
'e_value': np.float64, | ||
'significance': np.float64, | ||
'clan': object | ||
} | ||
lines = list() | ||
with open(path, 'r') as f: | ||
for line in f.readlines(): | ||
line = line.strip() | ||
if line.startswith('#') or line == '': | ||
continue | ||
lines.append(line.split()) | ||
return pd.DataFrame(lines, columns=dtype) | ||
|
||
|
||
def read_pfam_tophit(path: str) -> pd.DataFrame: | ||
"""Read the PFAM tophit file. | ||
Args: | ||
path: The path to the PFAM tophit file. | ||
""" | ||
dtype = { | ||
'seq_id': object, | ||
'pfam_acc': object, | ||
'e_value': np.float64, | ||
'bit_score': np.uintc, | ||
} | ||
lines = list() | ||
with open(path, 'r') as f: | ||
f.readline() | ||
for line in f.readlines(): | ||
line = line.strip() | ||
gene_id, hits = line.split('\t') | ||
for hit in hits.split(';'): | ||
pfam_acc, e_val, bit_score = hit.split(',') | ||
lines.append([gene_id, pfam_acc, e_val, bit_score]) | ||
return pd.DataFrame(lines, columns=dtype) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import numpy as np | ||
import pandas as pd | ||
|
||
|
||
def read_tigrfam(path: str) -> pd.DataFrame: | ||
"""Read the TIGRFAM file. | ||
Args: | ||
path: The path to the TIGRFAM file. | ||
""" | ||
dtype = { | ||
'seq_id': object, | ||
'hmm_acc': object, | ||
'full_seq_e_value': np.float64, | ||
'full_seq_score': np.float64, | ||
'full_seq_bias': np.float64, | ||
'best_domain_e_value': np.float64, | ||
'best_domain_score': np.float64, | ||
'best_domain_bias': np.float64, | ||
'exp': np.float64, | ||
'reg': np.float64, | ||
'clu': np.float64, | ||
'ov': np.float64, | ||
'env': np.float64, | ||
'dom': np.float64, | ||
'rep': np.float64, | ||
'inc': np.float64, | ||
'description': object, | ||
} | ||
lines = list() | ||
with open(path, 'r') as f: | ||
for line in f.readlines(): | ||
line = line.strip() | ||
if line.startswith('#') or line == '': | ||
continue | ||
cols = line.split() | ||
cur_line = [cols[0], cols[3]] | ||
cur_line.extend(cols[4:18]) | ||
cur_line.append(' '.join(cols[18:])) | ||
lines.append(cur_line) | ||
return pd.DataFrame(lines, columns=dtype) | ||
|
||
|
||
def read_tigrfam_tophit(path: str) -> pd.DataFrame: | ||
"""Read the TIGRFAM tophit file. | ||
Args: | ||
path: The path to the TIGRFAM tophit file. | ||
""" | ||
dtype = { | ||
'seq_id': object, | ||
'pfam_acc': object, | ||
'e_value': np.float64, | ||
'bit_score': np.uintc, | ||
} | ||
lines = list() | ||
with open(path, 'r') as f: | ||
f.readline() | ||
for line in f.readlines(): | ||
line = line.strip() | ||
gene_id, hits = line.split('\t') | ||
for hit in hits.split(';'): | ||
pfam_acc, e_val, bit_score = hit.split(',') | ||
lines.append([gene_id, pfam_acc, e_val, bit_score]) | ||
return pd.DataFrame(lines, columns=dtype) |