Generating random genomic positions or coordinates can be useful in comparing characteristics of a set of genomic loci to that what would be expected from permutations of the underlying genomic distribution. Below is a Python script to aid in selecting random genomic positions. The script chooses a chromosome based on probabilities assigned by chromosome length and then chooses a chromosomal position from a uniform distribution of the chromosome's length. An added gap checking statement is included to ensure the chosen position lies within the accessible genome. You can choose the number of positions you want, the number of permutations to conduct, the size of the genomic positions, and the genomic build of interest. A UNIX shell script is included as a wrapper to automatically download needed chromosomal gap and cytoband files as well as run the Python script. Useage for the UNIX script can be seen by typing ./make_random.sh from the command line after giving the script executable privileges. An example command would be ./make_random 100 10 1000 hg19. This command would make 10 .bed files each with 100 random 1Kb genomic regions from the hg19 genome build. Below are the make_random.sh and make_random.py scripts.
A repository of programs, scripts, and tips essential to
genetic epidemiology, statistical genetics, and bioinformatics
Welcome to the Genome Toolbox! I am glad you navigated to the blog and hope you find the contents useful and insightful for your genomic needs. If you find any of the entries particularly helpful, be sure to click the +1 button on the bottom of the post and share with your colleagues. Your input is encouraged, so if you have comments or are aware of more efficient tools not included in a post, I would love to hear from you. Enjoy your time browsing through the Toolbox.
Showing posts with label region. Show all posts
Showing posts with label region. Show all posts
Sunday, June 1, 2014
Wednesday, August 14, 2013
Download Data Track from UCSC Genome Browser
Did you know you can download tracks you visualize in the UCSC Genome Browser for personal use and analysis? Here's how to do it.
(1) Click on the grey bar on the far left side of the UCSC data track. This will bring you to the track settings page.
(2) Click on the link called View table schema. This will bring up a new page with track information and a description of data fields.
(3) Look for the field called Primary Table and copy the name.
(4) Go to the UCSC FTP site (link) and find the correct genome build you are after. Usually you will want to select hg19 or hg18.
(5) Click on the database link and then search for the name of the field you copied from the Primary Table field in step 3.
(6) There will usually be a .sql and a .txt.gz for most tracks. You are interested in the .txt.gz file. You can click on it to download via your internet web browser or right click on the link to copy the web address and use the wget command to download it. Here's and example script to download the NHGRI GWAS catalog using the wget command:
(7) Extract the compressed .txt.gz file with the following command, where filename is the name of the file you downloaded
This method should work for downloading the majority of the UCSC data tracks. Sometimes it takes a bit of digging around the UCSC FTP site to find the dataset you are looking for, but in most cases I have been successful in finding it on the UCSC FTP site.
One final note: If you are interested in downloading only a small portion of the track (for example, just a region on chromosome 8), you can download this region using the UCSC Table browser. Here's how to do this:
(1) Follow steps (1) and (2) above.
(2) Once on the Table Schema page for the track of interest go to the link bar on the top of the page and select Tools > Table Browser. This will take you to the UCSC Table Browser where all the fields will already be filled in with the track you are interested in.
(3) To download your region of interest click on the radio button next to position and type in your desired coordinates (ex: chr8:128362121-129551294).
(4) Make sure all the filters are cleared and give your output a filename. Select get output and your file will be downloaded. There is no need to unzip unless you chose the gzip compressed option.
Best wishes and good luck analyzing UCSC data tracks!
(1) Click on the grey bar on the far left side of the UCSC data track. This will bring you to the track settings page.
(2) Click on the link called View table schema. This will bring up a new page with track information and a description of data fields.
(3) Look for the field called Primary Table and copy the name.
(4) Go to the UCSC FTP site (link) and find the correct genome build you are after. Usually you will want to select hg19 or hg18.
(5) Click on the database link and then search for the name of the field you copied from the Primary Table field in step 3.
(6) There will usually be a .sql and a .txt.gz for most tracks. You are interested in the .txt.gz file. You can click on it to download via your internet web browser or right click on the link to copy the web address and use the wget command to download it. Here's and example script to download the NHGRI GWAS catalog using the wget command:
(7) Extract the compressed .txt.gz file with the following command, where filename is the name of the file you downloaded
This method should work for downloading the majority of the UCSC data tracks. Sometimes it takes a bit of digging around the UCSC FTP site to find the dataset you are looking for, but in most cases I have been successful in finding it on the UCSC FTP site.
One final note: If you are interested in downloading only a small portion of the track (for example, just a region on chromosome 8), you can download this region using the UCSC Table browser. Here's how to do this:
(1) Follow steps (1) and (2) above.
(2) Once on the Table Schema page for the track of interest go to the link bar on the top of the page and select Tools > Table Browser. This will take you to the UCSC Table Browser where all the fields will already be filled in with the track you are interested in.
(3) To download your region of interest click on the radio button next to position and type in your desired coordinates (ex: chr8:128362121-129551294).
(4) Make sure all the filters are cleared and give your output a filename. Select get output and your file will be downloaded. There is no need to unzip unless you chose the gzip compressed option.
Best wishes and good luck analyzing UCSC data tracks!
Friday, May 24, 2013
Download Nucleotide Sequence for Genomic Region
Sometimes I need the nucleotide sequence for a specific region of the genome to investigate sequence similarity, simple repeats present, or recurring motifs. I know entire chromosomal .fasta files can be downloaded from the UCSC ftp site, but then I would have to go through the entire file and hopefully extract out the correct sequence I needed. Today I came across a very easy way to download a nucleotide sequence for a genomic region using the UCSC DAS server. Simply modify the below web link to include the appropriate genome build and genomic coordinates and you will get a customized XML page generated with the nucleotide sequence for your query. One word of caution: the DAS server uses an index of +1 for the first base. Pretty cool and very simple to do.
http://genome.ucsc.edu/cgi-bin/das/hg19/dna?segment=chr1:100000,200000
http://genome.ucsc.edu/cgi-bin/das/hg19/dna?segment=chr1:100000,200000
Sunday, May 5, 2013
Samtools Coverage Depth for Multiple Regions of Interest
Here's some code to use Samtools to extract the sequencing coverage depth from a BAM file for multiple regions of interest as specified in a BED file. The resulting filename_depth.txt gives coverage data for each base in the region that is in the BAM file.
Samtools Download BAM Region Only
Often times publicly available sequencing data can serve as a useful reference for a sequencing project. The 1000 Genomes project is a great source, especially with their newly released high coverage Complete Genomics data. Here is an example UNIX script that shows how BAM files with genomic regions of interest can be created from a whole-genome BAM file that is hosted on an FTP server, without having to download the entire BAM file first. The bai_file_list.txt file is a file that contains unique identifiers for each BAM file extracted from a previously selected list of BAI files of interest. Here I am just extracting the BRCA1 and BRCA2 regions of the genome. The extracted reads are sorted and then saved as a BAM file and an associated BAI index file is also created. The final step removes excess BAI files that are downloaded and used by Samtools to extract the region of interest from the BAM files on the FTP server.
Subscribe to:
Posts (Atom)