SEQanswers

Go Back   SEQanswers > General



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I convert one file into several multifasta fasta files using perl iMarcelo Bioinformatics 10 05-06-2016 07:54 AM
sam files convert to bam files error awayihaha Bioinformatics 7 03-11-2014 09:03 AM
Convert 1000-Genomes-proje BAM to FASTA (aligned to reference, grouped by chromosome) ce.log Bioinformatics 17 01-13-2014 11:35 PM
Is it possible to convert FASTQ/FASTA files in HDF5 format? vincebaby6 Pacific Biosciences 5 08-30-2012 06:30 AM
Convert from baf to bam files Mercutio Bioinformatics 2 12-07-2010 10:45 AM

Reply
 
Thread Tools
Old 08-27-2019, 11:31 AM   #1
Manuelly
Junior Member
 
Location: Brazil

Join Date: Aug 2019
Posts: 7
Default how convert several bam files to fasta?

Hello!
I have 1979 mtDNA bam files and I need to convert these files to individual fastas. Since there are so many files, I would like to do this conversion faster or even once. I have no idea how to do that.
Can someone help me?
Manuelly is offline   Reply With Quote
Old 08-27-2019, 03:52 PM   #2
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,979
Default

Use reformat.sh from BBMap suite. Take a look at BAM processing options in in-line help to decide if you want to keep primary reads etc.

Code:
 for i in *.bam; do reformat.sh in=${i} out=${i}.fa add_options_you_need; done
Above would get you individual reads.

If your "convert bam to fasta" need is for consensus fasta sequence then check this tutorial on Biostars.

Last edited by GenoMax; 09-12-2019 at 08:22 AM.
GenoMax is online now   Reply With Quote
Old 08-28-2019, 07:11 AM   #3
Manuelly
Junior Member
 
Location: Brazil

Join Date: Aug 2019
Posts: 7
Default

so using reformat.sh command can I convert multiple bam to fasta at once? for this i need to open the folder with all bam and run the command?
Sorry, if the question is too obvious, but I'm still very lay.
I have difficulty understanding the command options in the terminal, is there any online manual that I help with BBmap?
Manuelly is offline   Reply With Quote
Old 08-28-2019, 08:30 AM   #4
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,979
Default

Yes you can convert multiple files at once. If your data came from paired-end reads then be aware that the "out=" files will contain data in interleaved format. You will need to separate R1/R2 reads. Again reformat.sh can be used for that as well.

Here is a guide for reformat.sh.
GenoMax is online now   Reply With Quote
Old 09-11-2019, 07:44 AM   #5
Manuelly
Junior Member
 
Location: Brazil

Join Date: Aug 2019
Posts: 7
Default

I tried to execute the command and the following message appeared. Do you know how I can solve this?
/media/lucasmalzoni/Seagate Backup Plus Drive1/Joao/MT/02-Bam$ reformat.sh in=${i}.bam out=${i}.fa
java -ea -Xms300m -cp /home/lucasmalzoni/anaconda3/opt/bbmap-38.67-0/current/ jgi.ReformatReads in=.bam out=.fa
Executing jgi.ReformatReads [in=.bam, out=.fa]

Exception in thread "main" java.lang.RuntimeException: Can't read file '.bam'
at shared.Tools.testInputFiles(Tools.java:1157)
at jgi.ReformatReads.<init>(ReformatReads.java:337)
at jgi.ReformatReads.main(ReformatReads.java:50)
(base) lucasmalzoni@galton:/media/lucasmalzoni/Seagate Backup Plus Drive1/Joao/MT/02-Bam$
Manuelly is offline   Reply With Quote
Old 09-11-2019, 10:58 AM   #6
SNPsaurus
Registered Vendor
 
Location: Eugene, OR

Join Date: May 2013
Posts: 501
Default

Can you copy what you did as a command and paste it here, and then list the directory as well and paste a few filenames as well? It looks like it didn't find any bam files. Are there files ending in .bam in that directory?
__________________
Providing nextRAD genotyping and PacBio sequencing services. http://snpsaurus.com
SNPsaurus is offline   Reply With Quote
Old 09-12-2019, 05:48 AM   #7
Manuelly
Junior Member
 
Location: Brazil

Join Date: Aug 2019
Posts: 7
Default

1.I opened the directory with the files in the terminal.
2. Then I used the following command:
reformat.sh in=${i}.bam out=${i}.fa
3. I received the following message:
java -ea -Xms300m -cp /home/lucasmalzoni/anaconda3/opt/bbmap-38.67-0/current/ jgi.ReformatReads in=.bam out=.fa
Executing jgi.ReformatReads [in=.bam, out=.fa]

Exception in thread "main" java.lang.RuntimeException: Can't read file '.bam'
at shared.Tools.testInputFiles(Tools.java:1157)
at jgi.ReformatReads.<init>(ReformatReads.java:337)
at jgi.ReformatReads.main(ReformatReads.java:50)
4.file extensions contained in the directory
/home/lucasmalzoni/Documentos/DOC/1-file_aligned_SortSam_MarkDuplicates.bai
/home/lucasmalzoni/Documentos/DOC/1-file_aligned_SortSam_MarkDuplicates.bam
/home/lucasmalzoni/Documentos/DOC/1-file_aligned_SortSam_MarkDuplicates.metrics.txt

I don't understand why it's not working.
Manuelly is offline   Reply With Quote
Old 09-12-2019, 08:11 AM   #8
SNPsaurus
Registered Vendor
 
Location: Eugene, OR

Join Date: May 2013
Posts: 501
Default

You should do the entire command as Genomax listed (with a change, I think, I'll mention below):

for i in *.bam; do reformat.sh in=${i}.bam out=${i}.fa; done

The first part (for i in *.bam) finds all the files ending in .bam in the directory, then passes them to the "do" command. So you should change the command to the below which removes the .bam from the in= name, since $i should already have the .bam at the end.

for i in *.bam; do reformat.sh in=$i out=${i}.fa; done

The output file will be named something like
filename.bam.fa
__________________
Providing nextRAD genotyping and PacBio sequencing services. http://snpsaurus.com
SNPsaurus is offline   Reply With Quote
Old 09-12-2019, 08:23 AM   #9
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,979
Default

Good catch SNPsaurus. I have updated my original command. There was an additional ".bam" in there.

@Manuelly: Use
Code:
for i in *.bam; do reformat.sh in=$i out=${i}.fa; done
If you are trying to run this for just one file then you should do:

Code:
 reformat.sh in=your.bam out=file.fa
GenoMax is online now   Reply With Quote
Old 09-14-2019, 11:14 AM   #10
RobertWood90
Junior Member
 
Location: California, USA

Join Date: Sep 2019
Posts: 2
Default

Convert several bam files to fasta? I had no idea about this before. I got full ideas from this article. Looks like I can do it myself. Thank you.
RobertWood90 is offline   Reply With Quote
Old 09-17-2019, 10:39 AM   #11
Manuelly
Junior Member
 
Location: Brazil

Join Date: Aug 2019
Posts: 7
Default

thank you very much for all the help. I realize that I have difficulty understanding the syntax of some commands and I don't know how to overcome this difficulty. Like "for i in *.bam". Is there any material I can read and improve my understanding?
Manuelly is offline   Reply With Quote
Old 09-17-2019, 11:50 AM   #12
Manuelly
Junior Member
 
Location: Brazil

Join Date: Aug 2019
Posts: 7
Default

1.after extracting the consensus in fasta format, I opened fasta and came across this:
>E00382:156:HMFJCCCXX:1:1102:7659:38315/2
TTCCCCTTAAATAAGACATCACGATGGATCACAGGTCTATCACCCTATTAACCACTCACGGGAGCTCTCCATGCATTTGGTATTTTCGTCTGGGGGGTATGCACGCGATAGCATTGCGAGACGCTGGAGCCGGAGCACCCTATGTCGCAGT
>E00382:156:HMFJCCCXX:1:1105:22019:53803/1
ATGGATCACAGGTCTATCACCCTATTAACCACTCACGGGAGCTCTCCATGCATTTGGTATTTTCGTCTGGGGGGTATGCACGCGATAGCATTGCGAGACGCTGGAGCCGGAGCACCCTATGTCGCAGTATCTGTCTTTGATTCCTGCCCCA
2.I think my fasta is separated by reads. and to solve this I used the following command:
for i in *.fa; do reformat.sh in1=$i in2=$i out=${i}.fa ; done
3. I believe it is not this command or something went wrong in the command. Can anyone help me?

I want uninterrupted fastas. it is possible?

Last edited by Manuelly; 09-17-2019 at 11:58 AM.
Manuelly is offline   Reply With Quote
Old 09-17-2019, 12:00 PM   #13
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,979
Default

Output fasta reads were interleaved (put in one file) since you had paired-end reads to begin with. To separate them into two files you should use the command below.

Code:
for i in *.fa; do name=$(basename $(i} .fa); reformat.sh in=${name}.fa out1=${name}_R1.fa out=${name}_R2.fa ; done
You could also do the original conversion by providing "out1=" and "out2=" separate file names during BAM conversion to avoid this step.
GenoMax is online now   Reply With Quote
Old 09-17-2019, 12:46 PM   #14
Manuelly
Junior Member
 
Location: Brazil

Join Date: Aug 2019
Posts: 7
Default

I think I did not express myself well. I need a single fasta per sample and not interleaved. like that:
>1 NC_012920.1:1-16569
GATCACAGGTCTATCACCCTATTAACCACTCACGGGAGCTCTCCATGCATTTGGTATTTT
CGTCTGGGGGGTGTGCACGCGATAGCATTGCGAGACGCTGGAGCCGGAGCACCCTATGTC
GCAGTATCTGTCTTTGATTCCTGCCTCATCCTATTATTTATCGCACCTACGTTCAATATT
ACAGGCGAACATACTTACTAAAGTGTGTTAATTAATTAATGCTTGTAGGACATAATAATA
ACAATTGAATGTCTGCACAGCCGCTTTCCACACAGACATCATAACAAAAAATTTCCACCA
AACCCCCCCTCCCCCCGCTTCTGGCCACAGCACTTAAACACATCTCTGCCAAACCCCAAA
AACAAAGAACCCTAACACCAGCCTAACCAGATTTCAAATTTTATCTTTTGGCGGTATGCA
CTTTTAACAGTCACCCCCCAACTAACACATTATTTTCCCCTCCCACTCCCATACTACTAA
Manuelly is offline   Reply With Quote
Old 09-17-2019, 03:03 PM   #15
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,979
Default

Then we have been on wrong track all along. You should have said you need a consensus fasta file from the BAM alignment.

What you need is: https://www.biostars.org/p/367960/

I had posted this in post #2 in this thread above.

Last edited by GenoMax; 09-17-2019 at 04:00 PM.
GenoMax is online now   Reply With Quote
Reply

Tags
convert files

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 04:28 AM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO