Skip to content

Outputting fasta files from tree sequences #338

Closed

Description

@maz-mckellar

From msprime created by marianne-aspbury: tskit-dev/msprime#802

This is a pretty basic file format to output, I have something that works for me but I don't know how to integrate it within tskit, and that'd be nice to do so noting it here for the future. (I'm also happy to do this, but with some direction).
This is what I'm doing for my personal use at the moment:

# the actual haplotype strings
haps = []
for i in ts.haplotypes():
    haps.append(i)

# The ">ID" parts of the fasta format. Don't know what best info to include is, 
# I'm just using sample index and the population because that's relevant for me. 
# Possibly people could choose what to include for ID strings in a fasta output function call
sequence_IDs = []
for i in range(len(haps)):
    sequence_IDs.append(f'sample_{ts.samples()[i]}_pop_{ts.node(i).population}')

# saving the file
with open('Sim_fasta_file.txt', 'w') as f:
    for i in range(len(haps)):
        f.write(f'>{sequence_IDs[i]}\n{haps[i]}\n') 

Activity

  1. maz-mckellar commented on Aug 23, 2019

    @maz-mckellar
    MemberAuthor

    Note - @petrelharp asked why we need a fasta file of variant sites. The response is that we're using some phylogeny inference software that needs fasta files as input. We're actually making a fasta file that included all the sites, not just the variant ones, since we're first making a table that includes the invariant sites as well (making a tree sequence from that table, ts, then doing this fasta output)

  2. petrelharp commented on Aug 23, 2019

    @petrelharp
    Contributor

    If you'd like to contribute this, we could help walk you through; the place to start might be to look at how VCF output is done, and copy that?

  3. jeromekelleher commented on Aug 26, 2019

    @jeromekelleher
    Member

    Thanks for this @marianne-aspbury, I'm happy to help you with the details here. Let's talk about it this week.

    Note also we would like to close #50 as well by adding a CLI option (an easy addition).

  4. jeromekelleher commented on Sep 29, 2020

    @jeromekelleher
    Member

    Closing in favour of #353

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions