yes you are correct, now I know what to do.
2 answers
You don't seem to understand what you are doing. You index the reference genome with bwa. You align your fastq to the indexed genome with bwa. The .sai file is an intermediate file, it (or the two .sai files from a paired end experiment) are converted into a .sam file
Samtools doesn't do any of that.
Though piping that .sam file straight into samtools for compression into .bam format is a smart thing to do.
Also note that indexing the reference genome with bwa, and indexing a .bam file with samtools are two entirely different things. You might not even need the .bam file index.
Before you use samtools you need to map your reads first. Then you get a sam/bam file based on your aligning tool. Only after that you use that bam/sam file to index it.
To index it, first you sort the bam/sam files.
samtools sort sample.bam sample_sorted
sample.bam here is your input file and sample_sorted here is the output file in the bam format too. Notice you don't mention the .bam extension in the output file name.
Then, you index it using the following command.
samtools index sample_sorted.bam
Thank you very much !
why do we need to index reference files...
You should focus on reading some tutorials and papers related to the whole NGS pipeline. You should have a clear picture of the workflow before you start.
I fully agree with you Ashutosh, when I enrolled for a course in bioinformatics NGS was not in curriculum, it was introduced for 2 weeks and now got a big assignment really confusing and after 2 weeks i have my finals so totally lost between java, perl ,R and NGS. Thanks for your advise unfortunately I can't go deep in NGS now.
Log in to answer this question.
that is not samtools, that's bwa. And your mapping quality will be off if you only map to one chromosome.
yes first i made a bwa index .how to go for samtools index,
before you go for samtools index, you need a bam file. is it single-end or paired-end ? use samse or sampe depending. Then samtools sort then samtools index