Skip to content

Outputting fasta files from tree sequences #802

Closed

Description

@maz-mckellar

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. petrelharp commented on Aug 23, 2019

    @petrelharp
    Contributor

    Very nice. I'm curious, what do you need a fasta of just the variant sites for? We would like to add support for reference sequences but have not.

    And, hm: this should really be over in tskit (which deals with tree sequence manipulations), not msprime (which simulates them). Mind moving this over there?

  2. maz-mckellar commented on Aug 23, 2019

    @maz-mckellar
    MemberAuthor

    Oops! I meant to put this on tskit.... Thanks...
    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 making a table that includes the invariant sites as well.
    @petrelharp I looked up moving issues but I don't have the admin privileges for the repos to do this - should I just copy there and then close this issue? - I have cloned and closed the issue

  3. maz-mckellar commented on Aug 23, 2019

    @maz-mckellar
    MemberAuthor

    Kamino closed and cloned this issue to tskit-dev/tskit

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