This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Learning how to use Samtools

Hello.

I am working with narrowpeak and bed files. I want to use samtools in order to index( tabix) the files.

I want to use it also in order to conduct queries on my files.

The documentation in the website is not so informative and doesn't refer my type of files directly. How can I learn how to use samtools in a clear way? Is there any apaproachable tutorial? Thanks

samtools

Some common uses:

Coordinate sorting and indexing for display of alignment data

samtools sort -o sorted.bam in.bam
samtools index sorted.bam

Name sorting (essential) and converting aligned data back to fastq/fasta

samtools sort -n in.bam | samtools fastq -1 R1.fastq.gz -2 R2.fastq.gz -

Indexing fasta files for retrieval of sequence data

samtools faidx reference.fasta
samtools faidx reference.fasta chr10:1-108

Does the OP have bam files? It's not clear to me that narrowpeak files are bams.

I was only going on the "Learning how to use" title but reading the first line it does look the like the question is about narrowpeak and bed files. So will delete my comment.

1 answer

What exactly is unclear? The problem with the files in your previous questions was that they were not in BED format because they had a header. BED format is chr-start-end at minimum in a tab-separated file. If you have a strand information it must be in column 6, all other columns can contain any value. narrowPeak is in fact a BED 6+4 file and follows the same conventions.

Querying can be done with tabix:

$ cat test.bed
chr1    1   10  .   dump    +
chr1    100 200 .   trump   -
chr2    1000    2000    .   chicken +

$ bgzip test.bed 
$ tabix -p bed test.bed.gz
$ tabix test.bed.gz chr1
  chr1  1   10  .   dump    +
  chr1  100 200 .   trump   -

In general: tabix your.file.gz chr:start-end

You can also query other file types such as VCF and GFF, please see the manual and you can provide a file that lists the query regions rather than providing them directly with the above command. Type tabix into the console and the help pops up.

Log in to answer this question.