Note that this method will NOT fix indels. It will simple make the sequence lowercase around them.
What might be a little simpler is to make a vcf from the .bam and the original reference sequence, figure out what SNPs you believe, and then correct that reference based on the SNPs from the vcf.
Dear Upendra Kumar,
I would like to extract a gene sequence for 30 viral samples and planning to build a phylogenetic tree. For example, this is reference gene of interest for me NC_026434 which is NA Neuraminidase. For this gene, the CDS starts at1 and ends at 1410. How do I extract the same gene for all the 30 viral samples. I have the fastq files and reference aligned bam files.