This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Convert a cram file to fasta

How can I go from a cram file to a fasta without having to convert to a .bam, index and map?

At the moment I'm trying to pass bam, but I'm not succeeding either

I already tried with this line

samtools view -b -T /media/SSD1/reference.fasta -o 15132.bam 15132_657.cram

but it throws me this error

[W::find_file_url] Failed to open reference "https://www.ebi.ac.uk/ena/cram/md5/17d0aca68c27ef37c9f0ebbd12de292b": Protocol not supported
[E::cram_get_ref] Failed to populate reference for id 1
[E::cram_decode_slice] Unable to fetch reference #1 206..211482
[E::cram_next_slice] Failure to decode slice
[main_samview] truncated file.
cram fasta samtools

Something like this may be simpler:

samtools view -b -T /media/SSD1/reference.fasta 15132_657.cram | samtools sort -n - | samtools fasta ...option

That said it appears that you may be using incorrect reference.See: Failed to populate reference for id 1?

You may be able to simply use

$ samtools fasta
Usage: samtools fasta [options...] <in.bam>

Description:
Converts a SAM, BAM or **CRAM** to FASTA format.

what is your ultimate goal in "converting CRAM to FASTA"

To do my selection and linkage disequilibrium assays

You will likely not be closer to your goal by converting CRAM to FASTA. Instead you likely want to do variant calling on your CRAM file(s) to generate a VCF, and do population analysis and things on that. see linkage disequilibrium analysis for an example of linkage disequilibrium analysis on a VCF. It is often important to be clear about what your end goal is when asking a question because "converting CRAM to FASTA" is sort of a non-sense operation (the answer given above converts each individual read to a line in the FASTA, which is rarely what you want), it's much more common to analyze your variants in VCF/PLINK style workflows. see also https://pixy.readthedocs.io/en/latest/

0 answers

No answers yet.

Log in to answer this question.