when i get the mapped sam file, i use samtools view to transfer this
sam file to bam file, then i use samtools sort this bam file
Based on your explanation you do, the following, or something similar:
samtools view myfile.sam -o myfile.bam
samtools sort myfile.bam -o myfile_sorted.bam
That's not wrong, but it's also not necessary. Note that you can do the following in one go:
samtools sort myfile.sam -o myfile_sorted.bam
Finally, often you can also have your aligner write directly to samtools sort:
bwa mem genome.fa reads.fastq | samtools sort -o myfile_sorted.bam
As such you can avoid quite some wasted time and intermediate files.
Depending on your reply, if i do not index the bam file it will not
effect my later analysis( first condition), do i understand right?
A bam is a binary (compressed) format. For some applications, e.g. visualization in IGV or variant calling the tool needs 'random access' to the bam file, it needs to be able to find reads without iterating through the entire file. That's what the index is for.
We don't know what your "later analysis" is (please try to be as informative as possible when asking questions), but either it will work (no index required) or it will fail (and tell you it needs an index). Index files are generally small and created quickly, so there is no need to worry about them. Just index your bam.
How to define " coordinate sorted"?
A bam is coordinate sorted if the reads are sorted by coordinates. So reads from the beginning of the first chromosome are first in the file. That's what
samtools sort is for. The opposite would be 'sorted by name' in which reads are sorted by their read ID. Aligners also generate unsorted bams.