I have downloaded the COSMIC mutation file based on GRCH38. I have the cosmic mutation ids for each mutation (eg, COSM521,COSM520 etc). If I copy these ids and check in the search box of the website I get all the related information such as its emsembl contig etc. Using these ENSEMBL contigs, I visit the ENSEMBL database and extract the sequence associated with this variant. Is there any way to extract all the cosmic variant sequences from the ENSEMBL database without doing this individually for all? In other words, how to map the COSMIC variants with that of the ENSEMBL ones?
You can get the flanking regions for lists of variants in Ensembl using either BioMart or the Perl API.
BioMart is more suited to short lists of variants. There's a help video on using BioMart here. Use the somatic short variation database then filter by your list of IDs, get flanking sequence as attributes – you can specify how large a flank you need.
Alternatively, you can use the Perl API, which has methods in the Variation module to get the 5' and 3' flanking sequence for a variant.
Let me know if you need any help using either of these.