This is a test version of Biostars. For the public version, visit https://www.biostars.org.
rename fasta headers in FastaAlternateReferenceMaker output

Hi,

I would like to create a new fasta file from the original genome fasta and a vcf file. The fasta file will only have full gene sequences included.

I can use the gatk FastaAlternateReferenceMaker to accomplish this:

java -jar -Xmx16g ~/bin/GenomeAnalysisTK-3.6/GenomeAnalysisTK.jar -T FastaAlternateReferenceMaker -R ref_genome.fasta -o sample_SNV.fasta -V sample_SNV_selected.vcf -L ref_gene.bed

But I would like the output fasta to have the gene names as the header. For instance the current fasta output from gatk is:

 >1 chr01:2350
AGAAAGGACAGAAAAAAAGATGGTGAAGTAGAAAGAGGGCGAAATGAAAAAAGGGAAAGC
AAAAGAGATGATGAAAGTCATAGAGAGAGAGATGAAAAAAGGGAAAGCAAAAGAGATGAT

I would like the output to 1) not have a sequential numerical output and 2) to contain the gene name from column 4 of the .bed file.

Is there a way to either modify 1) the input bed file or 2) the output fasta file by giving 'some tool' the fasta and the bed file?

Thanks!

bed fasta gatk fastaalternatereferencemaker header

1 answer

Thanks!

I used this python script and it worked great:

fasta= open('file.fasta')
newnames= open('list.txt')
newfasta= open('file_annot.fasta', 'w')

for line in fasta:
    if line.startswith('>'):
        newname= newnames.readline()
        newfasta.write(newname)
    else:
        newfasta.write(line)

fasta.close()
newnames.close()
newfasta.close()

Log in to answer this question.