Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions phylopandas/seqio/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from Bio.Blast import NCBIXML
import Bio.Alphabet

# Import Phylopandas DataFrame
import pandas as pd
Expand Down Expand Up @@ -38,7 +37,6 @@ def _read(
filename,
schema,
seq_label='sequence',
alphabet=None,
use_uids=True,
**kwargs):
"""Use BioPython's sequence parsing module to convert any file format to
Expand All @@ -50,19 +48,6 @@ def _read(
- description
- sequence
"""
# Check Alphabet if given
if alphabet is None:
alphabet = Bio.Alphabet.Alphabet()

elif alphabet in ['dna', 'rna', 'protein', 'nucleotide']:
alphabet = getattr(Bio.Alphabet, 'generic_{}'.format(alphabet))

else:
raise Exception(
"The alphabet is not recognized. Must be 'dna', 'rna', "
"'nucleotide', or 'protein'.")

kwargs.update(alphabet=alphabet)

# Prepare DataFrame fields.
data = {
Expand Down Expand Up @@ -95,7 +80,6 @@ def func(
self,
filename,
seq_label='sequence',
alphabet=None,
combine_on='uid',
use_uids=True,
**kwargs):
Expand All @@ -105,7 +89,6 @@ def func(
filename=filename,
schema=schema,
seq_label=seq_label,
alphabet=alphabet,
use_uids=use_uids,
**kwargs
)
Expand All @@ -122,15 +105,13 @@ def _read_function(schema):
def func(
filename,
seq_label='sequence',
alphabet=None,
use_uids=True,
**kwargs):
# Use generic write class to write data.
return _read(
filename=filename,
schema=schema,
seq_label=seq_label,
alphabet=alphabet,
use_uids=use_uids,
**kwargs
)
Expand Down
28 changes: 2 additions & 26 deletions phylopandas/seqio/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from Bio import SeqIO
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
import Bio.Alphabet


def _write_doc_template(schema):
Expand Down Expand Up @@ -36,7 +35,6 @@ def pandas_df_to_biopython_seqrecord(
id_col='uid',
sequence_col='sequence',
extra_data=None,
alphabet=None,
):
"""Convert pandas dataframe to biopython seqrecord for easy writing.

Expand All @@ -54,9 +52,6 @@ def pandas_df_to_biopython_seqrecord(
extra_data : list
extra columns to use in sequence description line

alphabet :
biopython Alphabet object

Returns
-------
seq_records :
Expand All @@ -70,7 +65,7 @@ def pandas_df_to_biopython_seqrecord(
# sequence data and therefore the row is ignored.
try:
# Get sequence
seq = Seq(row[sequence_col], alphabet=alphabet)
seq = Seq(row[sequence_col])

# Get id
id = row[id_col]
Expand All @@ -97,7 +92,6 @@ def pandas_series_to_biopython_seqrecord(
id_col='uid',
sequence_col='sequence',
extra_data=None,
alphabet=None
):
"""Convert pandas series to biopython seqrecord for easy writing.

Expand All @@ -121,7 +115,7 @@ def pandas_series_to_biopython_seqrecord(
List of biopython seqrecords.
"""
# Get sequence
seq = Seq(series[sequence_col], alphabet=alphabet)
seq = Seq(series[sequence_col])

# Get id
id = series[id_col]
Expand All @@ -148,7 +142,6 @@ def _write(
id_col='uid',
sequence_col='sequence',
extra_data=None,
alphabet=None,
**kwargs):
"""General write function. Write phylopanda data to biopython format.

Expand All @@ -167,17 +160,6 @@ def _write(
id_only : bool (default=False)
If True, use only the ID column to label sequences in fasta.
"""
# Check Alphabet if given
if alphabet is None:
alphabet = Bio.Alphabet.Alphabet()

elif alphabet in ['dna', 'rna', 'protein', 'nucleotide']:
alphabet = getattr(Bio.Alphabet, 'generic_{}'.format(alphabet))

else:
raise Exception(
"The alphabet is not recognized. Must be 'dna', 'rna', "
"'nucleotide', or 'protein'.")

# Build a list of records from a pandas DataFrame
if type(data) is pd.DataFrame:
Expand All @@ -186,7 +168,6 @@ def _write(
id_col=id_col,
sequence_col=sequence_col,
extra_data=extra_data,
alphabet=alphabet,
)

# Build a record from a pandas Series
Expand All @@ -196,7 +177,6 @@ def _write(
id_col=id_col,
sequence_col=sequence_col,
extra_data=extra_data,
alphabet=alphabet,
)

# Write to disk or return string
Expand All @@ -216,7 +196,6 @@ def method(
id_col='uid',
sequence_col='sequence',
extra_data=None,
alphabet=None,
**kwargs):
# Use generic write class to write data.
return _write(
Expand All @@ -226,7 +205,6 @@ def method(
id_col=id_col,
sequence_col=sequence_col,
extra_data=extra_data,
alphabet=alphabet,
**kwargs
)
# Update docs
Expand All @@ -244,7 +222,6 @@ def func(
id_col='uid',
sequence_col='sequence',
extra_data=None,
alphabet=None,
**kwargs):
# Use generic write class to write data.
return _write(
Expand All @@ -254,7 +231,6 @@ def func(
id_col=id_col,
sequence_col=sequence_col,
extra_data=extra_data,
alphabet=alphabet,
**kwargs
)
# Update docs
Expand Down