<?xml version='1.0'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
	<title><![CDATA[BOL: Extract sequence from UCSC]]></title>
	<link>https://bioinformaticsonline.com/snippets/view/27354/extract-sequence-from-ucsc?</link>
	<atom:link href="https://bioinformaticsonline.com/snippets/view/27354/extract-sequence-from-ucsc?" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/27354/extract-sequence-from-ucsc</guid>
	<pubDate>Tue, 17 May 2016 08:08:26 -0500</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/27354/extract-sequence-from-ucsc</link>
	<title><![CDATA[Extract sequence from UCSC]]></title>
	<description><![CDATA[<code>#!/usr/bin/env perl

use strict;
use warnings;
use LWP::Simple;
use XML::XPath;
use XML::XPath::XMLParser;

# Use DAS of UCSC to fetch specific sequence by its given chromosome position
# From here: https://www.biostars.org/p/6156/

my $chr  = shift;
my $pos  = shift;
my $size = shift;

my $usage = &quot;Example: perl extract_seq_from_ucsc.pl 14 482780 1000\n&quot;;

if (! $size) {
	die &quot;ERROR: You must pass three arguments: chr. num., position, and size.\n$usage&quot;;
	
}

chomp $size;

my $start = $pos - ($size/2);
my $end   = $pos + ($size/2);

# Figure out URL for the DAS server. Example:
# http://genome.ucsc.edu/cgi-bin/das/calJac3/dna?segment=chr14:482280,483280

my $URL_gene =&quot;http://genome.ucsc.edu/cgi-bin/das/papAnu2/dna?segment=chr&quot;;
$URL_gene .= $chr . &quot;:&quot; . $start . &quot;,&quot; . $end;

my $xml = get($URL_gene);

my $xp = XML::XPath-&gt;new(xml=&gt;$xml);

my $nodeset = $xp-&gt;find(&#039;/DASDNA/SEQUENCE/DNA/text()&#039;); # find all sequences
# there should be only one node, anyway:    
foreach my $node ($nodeset-&gt;get_nodelist) {

	my $seq = $node-&gt;getValue;
	$seq =~ s/\s//g; # remove white spaces
	print &quot;&gt;papAnu2_chr&quot; . $chr . &quot;:&quot; . $start . &quot;-&quot; . $end . &quot;\n&quot;;
	print $seq, &quot;\n&quot;;
	
}</code>]]></description>
	<dc:creator>Jit</dc:creator>
</item>

</channel>
</rss>