# Coordinates to Genome R Studio Script?

I have a very, very long list of genome coordinates of areas. I need to gather a sequence in order to compare it to another database of sequences that I have. How do I produce the genome sequences from these coordinates in R?

I am very new to this and need a detailed answer.

• What genome? Namely, is it one for which there's already a BSgenome package? – Devon Ryan Dec 1 '17 at 22:06
• The genome was given to me, it is not on there. My problem, more specifically I suppose, is that I was given a couple files. The genome was run through RepeatMasker to obtain coordinates of transposable elements. So, I have the coordinates from the map file that was produced from RepeatMasker and I would like to identify the sequences of these coordinates from my genome (which is too big to view). After I obtain the sequences, I will need to compare those sequences to a library of known elements that was also given to me in another file. So, I am lost especially since I am very new to this – Noob Dec 1 '17 at 22:36
• OK, does this really have to be done in R? This particular task is a bit better done on the command line than in R. – Devon Ryan Dec 1 '17 at 22:39
• Do you know what type of commands this would consist of? – Noob Dec 27 '17 at 3:30

This doesn't use R, but a simple and quite convenient method is to use bedtools getfasta with your fasta file. You'll need to make a BED file out of the RepeatMasker output:

awk 'BEGIN{OFS="\t"}{name=sprintf("%s_%s", $10,$11); strand="+"; if($9 == "C"){strand="-"}; print$5,$6-1,$7,name,".", strand}' repeatmasker.output > rmsk.bed


Then, given that and your genome.fa fasta:

bedtools getfasta -name -s -fi genome.fa -bed rmsk.bed -fo output.fa


This will produce a multiline fasta file names like AluSx_SINE/Alu (due to the -name option) where the sequences are reverse complemented if appropriate.

You can install bedtools either via conda (conda install -c bioconda bedtools) or github.