Showing posts with label bam. Show all posts
Showing posts with label bam. Show all posts
Sunday, 13 August 2017
demo bam file Ion Torrent 314 chip of E. coli 400 bp run for download
BAM file of B22-730 (314v2 E. coli 400 bp run)
Ion Torrent PGM 314v2 run with a mode read length of 400bp and per-base raw read accuracy >99%.
https://s3.amazonaws.com/ion-torrent/pgm/B22-730/B22-730.bam
Source: https://apps.thermofisher.com/apps/publiclib/#/datasets
Wednesday, 2 August 2017
Creating filtered fastq files of ONLY mapped reads from a BAM file
Filtering BAM files for mapped or unmapped reads
samtools view -f 4 file.bam > unmapped.sam, the output will be in sam
To get only the mapped reads use the parameter 'F', which works like -v of grep and skips the alignments for a specific flag.
samtools view -b -F 4 file.bam > mapped.bam
Source: https://www.biostars.org/p/56246/ Sukhdeep Singh
reformat.sh in=reads.sam out=mapped.fq mappedonly
Also, BBMap has a lot of options designed for filtering, so it can output in fastq format and separate mapped from unmapped reads, preventing the creation of intermediate sam files. This approach also keeps pairs together, which is not very easy using samtools for filtering.
bbmap.sh ref=reference.fa in=reads.fq outm=mapped.fq outu=unmapped.fq
Source: https://www.biostars.org/p/127992/ Brian Bushnell
Thursday, 22 March 2012
Multi-threaded BAM compression and sorting The multi-threaded sort/merge/view is available at the "mt" branch:
---------- Forwarded message ----------
From: Heng Li
Date: Thu, Mar 22, 2012 at 11:32 AM
Subject: [Samtools-help] Multi-threaded BAM compression and sorting
To convert coordinated sorted BAM back to FASTQ, the recommended way is to sort BAM by name and then convert the name sorted BAM to fastq. This is important because some mapper such as BWA assumes the input is random. They may have some troubles if we directly convert a coordinate sorted BAM with Picard's bam2fastq. While novosort, it does not sort by name. As I need to do BAM=>FASTQ for some huge BAMs, I added multi-threading to "sort", "merge" and "view".
This is not a full parallelization in that not all the steps are parallelized. Thus the efficiency is not scaled linearly with the number of threads. It is not recommended to use more than 8 threads. With 4 threads, time on sorting is reduced to 40% according to limited test. It may save you half a day if you have a huge BAM.
All my changes are naive and simple. It is possible to speed up sorting and compression further, but so far as I can see, this needs quite a lot of code restructuring and development time. For coordinate sorting, novosort scales much better with the number of threads (though I do not know if multi-threaded novosort is free to use beyond 15 days). Nils' multi-threaded bgzip should also do better on compression. These are sophisticated implementations. Mine is not.
The multi-threaded sort/merge/view is available at the "mt" branch:
https://github.com/samtools/samtools/tree/mt
The samtools/bgzf APIs stay the same except a few new functions to enable threading. In addition to multithreading, there are a few other improvements to sorting (some are based on Nils'):
1) @HD-SO tag is properly set (finally).
2) The compression level can be changed on the command line (-l).
3) Coordinate sorting considers strand as part of the key.
4) Improved alpha-numeric comparison between query names. The previous version was slower and did not work when there is a large integer.
5) Supporting "K/M/G" with option "-m". The maximum memory is estimated a little more accurately.
6) I kept claiming samtools sort was stable (i.e. the relative order of two records having the same coordinate are retained), but this was not true. The new sort is truly stable. This also means under the same compression level, sort always produces exactly the same output. For endusers, stable sorting is largely irrelevant. This just makes me feel more comfortable, "in theory".
Heng
--
The Wellcome Trust Sanger Institute is operated by Genome Research
Limited, a charity registered in England with number 1021457 and a
company registered in England with number 2742969, whose registered
office is 215 Euston Road, London, NW1 2BE.
https://lists.sourceforge.net/lists/listinfo/samtools-help
From: Heng Li
Date: Thu, Mar 22, 2012 at 11:32 AM
Subject: [Samtools-help] Multi-threaded BAM compression and sorting
To convert coordinated sorted BAM back to FASTQ, the recommended way is to sort BAM by name and then convert the name sorted BAM to fastq. This is important because some mapper such as BWA assumes the input is random. They may have some troubles if we directly convert a coordinate sorted BAM with Picard's bam2fastq. While novosort, it does not sort by name. As I need to do BAM=>FASTQ for some huge BAMs, I added multi-threading to "sort", "merge" and "view".
This is not a full parallelization in that not all the steps are parallelized. Thus the efficiency is not scaled linearly with the number of threads. It is not recommended to use more than 8 threads. With 4 threads, time on sorting is reduced to 40% according to limited test. It may save you half a day if you have a huge BAM.
All my changes are naive and simple. It is possible to speed up sorting and compression further, but so far as I can see, this needs quite a lot of code restructuring and development time. For coordinate sorting, novosort scales much better with the number of threads (though I do not know if multi-threaded novosort is free to use beyond 15 days). Nils' multi-threaded bgzip should also do better on compression. These are sophisticated implementations. Mine is not.
The multi-threaded sort/merge/view is available at the "mt" branch:
https://github.com/samtools/samtools/tree/mt
The samtools/bgzf APIs stay the same except a few new functions to enable threading. In addition to multithreading, there are a few other improvements to sorting (some are based on Nils'):
1) @HD-SO tag is properly set (finally).
2) The compression level can be changed on the command line (-l).
3) Coordinate sorting considers strand as part of the key.
4) Improved alpha-numeric comparison between query names. The previous version was slower and did not work when there is a large integer.
5) Supporting "K/M/G" with option "-m". The maximum memory is estimated a little more accurately.
6) I kept claiming samtools sort was stable (i.e. the relative order of two records having the same coordinate are retained), but this was not true. The new sort is truly stable. This also means under the same compression level, sort always produces exactly the same output. For endusers, stable sorting is largely irrelevant. This just makes me feel more comfortable, "in theory".
Heng
--
The Wellcome Trust Sanger Institute is operated by Genome Research
Limited, a charity registered in England with number 1021457 and a
company registered in England with number 2742969, whose registered
office is 215 Euston Road, London, NW1 2BE.
https://lists.sourceforge.net/lists/listinfo/samtools-help
UPDATE
contributed by iceman (see comments )
relevant links to an alternative implementation:
See: http://seqanswers.com/forums/showthread.php?p=66683
and: https://github.com/nh13/samtools/tree/pbgzip
Thursday, 1 March 2012
Mac (BSD) awk != Linux (GNU) awk, split BED file by chromosomes
To split your BED file by chromosome, this simple GNU AWK script will create "my.chrNNN.bed" file for each chromosome:
awk '{ print >> "my." $1 ".bed" }' my.bed
BSD's AWK
awk '{ file = "TFBS." $1 ".bed" ; print >> file }' TFBS.bed
credit: Assaf Gordon on BedTools mailing list for pointing this out
On a side note,
To split your BAM file by chromosome, you can use "bamtools split" ( bamtools here: https://github.com/
There is a SAMtools filter option as well.
Anyone benchmarked both to see which runs faster?
this discussion arose from someone trying to compute the mean coverage
bedtools coverage -abam my.bam -b my.bed -d | sort -k1,1 -k2,2n | groupby -g 1,2,3,4,5,6 -c 8 -o mean > my.txt
it doesn't scale too well with the no. of entries in the bed file
1,000 lines takes a few minutes
1,200,000 lines " it's been running for 12 hours and still not done yet " on a Mac Pro with speed of 2.66 GHz and 8 GB of Memory.
So splitting the file by chromosome helps to parallelize the process although the job might scale linearly
Wednesday, 22 February 2012
Amazon S3 for temporary storage of large datasets?
Just did a rough calculation on AWS calculator, the numbers are quite scary!
For a hypothetical 50 TB dataset (haven't found out the single S3 object max file size yet, seem to recall it's 1 Gbytes)
it costs $4160.27 to store it for a month!
to transfer it out it costs $4807.11!
For 3 years, the cost of storage is $149,000 which I guess you can pay for an enterprise storage solution and transfer costs are zero.
At this point in time, I guess one can't really use AWS S3 for sequence archival. I wonder if data deduplication can help reduce cloud storage costs ... I am sure in terms of bytes, BAM files should be quite similar .. no?
For a hypothetical 50 TB dataset (haven't found out the single S3 object max file size yet, seem to recall it's 1 Gbytes)
it costs $4160.27 to store it for a month!
to transfer it out it costs $4807.11!
For 3 years, the cost of storage is $149,000 which I guess you can pay for an enterprise storage solution and transfer costs are zero.
At this point in time, I guess one can't really use AWS S3 for sequence archival. I wonder if data deduplication can help reduce cloud storage costs ... I am sure in terms of bytes, BAM files should be quite similar .. no?
Labels:
Amazon Web Services,
AWS,
bam,
big data,
cloud,
costs,
fastq,
Next Generation Sequencing,
storage
Thursday, 31 March 2011
Convert SAM / BAM to fasta / fastq
Probably one of the most freq FAQ
latest thread in biostar
http://biostar.stackexchange.com/questions/6993/convert-bam-file-to-fasta-file
Samtofastq using Picard
http://picard.sourceforge.net/command-line-overview.shtml#SamToFastq
Samtools and awk to make fasta from sam
latest thread in biostar
http://biostar.stackexchange.com/questions/6993/convert-bam-file-to-fasta-file
Samtofastq using Picard
http://picard.sourceforge.net/command-line-overview.shtml#SamToFastq
Samtools and awk to make fasta from sam
samtools view filename.bam | awk '{OFS="\t"; print ">"$1"\n"$10}' - > filename.fasta Biopython and pysam (code contributed by Brad Chapman)http://biostar.stackexchange.com/questions/6993/convert-bam-file-to-fasta-file/6994#6994
Labels:
bam,
convert,
convertors,
FAQ,
fasta,
fastq,
file format,
samtools
Subscribe to:
Posts (Atom)