<p>Simple question - I need to create a GTF file to use in HTSeq-count that contains gene regions plus 3kb upstream. (Background: doing a MeDIP-seq experiment, want to look for differential methylation in genic and 3kb promoter regions using count based method like edgeR/DESeq).</p>

<p>I was planning on making one myself from the UCSC hg19 refFlat table. The refFlat table has gene coordinates, but I need to extend this 3kb upstream to capture promoter regions.</p>

<p>Column 3 contains the strand (+/-) and columns 4-5 contain the transcription start (txStart) and end (txEnd) positions. </p>

<p>If I want to capture 3kb upstream of the TSS, I was planning on adding 3000 to txStart, but is only for genes on the + strand, correct? If I want 3kb upstream of the TSS for genes on the - strand, should I add this 3000 to txEnd?</p>

<p>E.g. the <a href='http://genome.ucsc.edu/cgi-bin/hgTracks?hgsid=299873535'>DENND1B gene</a> is on the - strand at chr1:197,473,879-197,744,623. However, <a href='http://genome.ucsc.edu/cgi-bin/hgTracks?hgsid=299873535'>looking at it in the browser</a>, it's transcribed "right to left", so I presume I would want to add 3000 to the txEnd number, 197,744,623, even though this is really where transcription starts.</p>

<p>Am I thinking about this correctly?</p>

>  "If I want 3kb upstream of the TSS for genes on the - strand, should I add this 3000 to txEnd?"

yes.

the position are always ordered from the 5' of the chromosome to the 3' and named xxStart and xxEnd (with xxStart<=xxEnd)  whatever the value of "strand".

    $ mysql --user=genome --host=genome-mysql.cse.ucsc.edu -A -D hg19 -e 'select count(*) from refFlat where txStart>txEnd or cdsStart>cdsEnd'
    +----------+
    | count(*) |
    +----------+
    |        0 |
    +----------+
    
    $ mysql --user=genome --host=genome-mysql.cse.ucsc.edu -A -D hg19 -e 'select txStart,txEnd from refFlat where strand="-" limit 4'
    +-----------+-----------+
    | txStart   | txEnd     |
    +-----------+-----------+
    |  62929370 |  62937380 |
    |     34610 |     36081 |
    | 153270337 | 153283194 |
    | 113235158 | 114449242 |
    +-----------+-----------+

So you'll only have to :

    newStart=(start<3000?0:start-3000);
    newEnd=end+3000;

**EDIT:** I was too fast. My pseudo-code extends the sequence on both side.  If you want to extend **upstream** sequence :

    newStart=(strand=='+'?start<3000?0:start-3000:start);
    newEnd=(strand=='+'?end:end+3000);

to fetch the (positive strand) sequence; See 

[How to get the sequence of a genomic region from UCSC?][1]

and

[Extract sequence from the genome?][2]

 [1]: /p/56/
 [2]: /p/3137