Replies: 2 comments 1 reply
-
Welcome!
from cogent3 import load_aligned_seqs
aln = load_aligned_seqs("sequence_analyses/GC_PIA-ntAligned.fasta", moltype="dna")
dists = aln.distance_matrix(calc="jc69", show_progress=False)
dists.write("sequence_analyses/data.csv") will write a csv formatted file. (The output format is derived from the filename suffix.) The truncated display is to reduce the volume of output in a notebook. You can control the amount of displayed data better if you convert the distance matrix to a cogent3 table table = dists.to_table()
table.head(1000) # in a notebook, display the top 1000 rows You can convert the table to a pandas data frame df = table.to_dataframe() And a final note, Hope that helps! |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks so much for your quick response. This worked a treat and I’m delighted with the results. Is there a way to calculate dN/dS ratios using Cogent3? And doing that per codon? Thanks againOdileOn 3 Dec 2022, at 06:40, GavinHuttley ***@***.***> wrote:
Welcome!
DistanceMatrix object has a write method, modifying your code as follows
dists.write("sequence_analyses/data.csv")
will write a csv formatted file. (The output format is derived from the filename suffix.)
The truncated display is to reduce the volume of output in a notebook. You can control the amount of displayed data better if you convert the distance matrix to a cogent3 table
table = dists.to_table()
table.head(1000) # in a notebook, display the top 1000 rows
You can convert the table to a pandas data frame
df = table.to_dataframe()
And a final note, cogent3 tables have lots of capabilities, See the cookbook about the Table for details.
Hope that helps!
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello - I'm using cogent3 to analyse sequence data and so far so good. I would like to export the resulting data as a csv file so I can visualise it but can't work out how to do this. Any suggestions? I've tried pandas DataFrame but not having much luck.
In addition, I'm comparing ~220 sequences but the output only prints 5 or so.
Thanks for your help.
Here is my code:
from cogent3 import load_aligned_seqs
from pandas import pandas as pd
aln = load_aligned_seqs("sequence_analyses/GC_PIA-ntAligned.fasta", moltype="dna")
dists = aln.distance_matrix(calc="jc69", show_progress=False)
df = pd.Dataframe(dists=data)
df.to_csv("sequence_analyses/data.csv")
df = pd.read_csv("data.csv")
Beta Was this translation helpful? Give feedback.
All reactions