This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Retrieving nucleotide sequence based on chromosome location offline

I have downloaded whole genome file from this link (ftp://ftp.broadinstitute.org/pub/genepattern/rna_seq/whole_genomes/Homo_sapiens_UCSC_hg19.fa). Now I need a program in Perl or Python to retrive nucleotide (user defined position) sequnce from the whole genome. I need to perform this offline The user input can be 1. Enter the chromosome number 2. Enter start position 3.Enter end position

The genome file i downloaded looks like

chrM

GATCGGTCTGACGTGCTgaTGATGATA GATCGGTCTGACGTGCTGATGATGATA

chr1

NNNNNNNNNNNNNNNNNNNNNNNNNNtggGGAATTttaag

genome sequence gene python perl

3 answers

You can simply use samtools to index the FASTA file, and then query the indexed FASTA file with your interval of interest.

  1. Generate the index: samtools faidx in.fasta
  2. Query via: samtools faidx in.fasta chrN:X-Y

Replace chrN:X-Y with the chromosome name (chrN), start position (X) and stop position (Y) of interest.

Look at the Biopython cookbook. Especially Sections 2.4 and 3.3

look at 3rd answer here

Log in to answer this question.