Biology and bioinformatics-oriented data cleaning functions.
join_fasta(df: pandas.core.frame.DataFrame, filename: str, id_col: str, column_name: str) → pandas.core.frame.DataFrame¶
Convenience method to join in a FASTA file as a column.
This allows us to add the string sequence of a FASTA file as a new column of data in the dataframe.
This method only attaches the string representation of the SeqRecord.Seq object from Biopython. Does not attach the full SeqRecord. Alphabet is also not stored, under the assumption that the data scientist has domain knowledge of what kind of sequence is being read in (nucleotide vs. amino acid.)
This method mutates the original DataFrame.
For more advanced functions, please use phylopandas.
Functional usage example:
import pandas as pd import janitor.biology df = pd.DataFrame(...) df = janitor.biology.join_fasta( df=df, filename='fasta_file.fasta', id_col='sequence_accession', column_name='sequence', )
Method chaining usage example:
import pandas as pd import janitor.biology df = pd.DataFrame(...) df = df.join_fasta( filename='fasta_file.fasta', id_col='sequence_accession', column_name='sequence', )
df – A pandas DataFrame.
filename – Path to the FASTA file.
id_col – The column in the DataFrame that houses sequence IDs.
column_name – The name of the new column.
A pandas DataFrame with new FASTA string sequence column.