3
$\begingroup$

edit explaining python tag

I would still rather have a solution based on the RSVSim package in R, but while waiting for someone who might have an answer I wanted to look at other solutions as well.

If a result like what metadata(sim) produces can be achieved in python as well, I can do it without RSVSim. I need especially the numbers given there, so I do NOT need "Copied BpSeqA BpSeqB_5prime BpSeqB_3prime". The numbers need to reflect the original position of insert into chr2, because I need to reflect this back to the original (unedited) chr2.

end edit explaining pyton tag

I tried using the BioConductor forums for asking this question Question on BioConductor. However I do not seem to get an answer there and after some help with other tools on this website, i thought I could also ask the question here, in the hope that someone knows something about it.

I have a reference genome, and I need to put in some structural variations. It is really easy to do in RSVSim, and used it quite a lot already.

However, when processing INS, I found out that it just copies a DNA seq from one part, and puts it somewhere else in the same DNA seq (Bascially a DUP then), or if you specify another an extra DNAseq, to cut from, It randomly cuts from either chr1 or chr2 and puts it in the other. This creates deletions in the DNA seq I want to investigate, which is not what I want.

Does anyone know how to get this kind of result?

width seq                                                                                                                           names               
[1]    40 AAAAAAAAAAAAAAAAAAAATTTTTTTTTTTTTTTTTTTT    chr1
[2]    40 GGGGGGGGGGGGGGGGGGGGCCCCCCCCCCCCCCCCCCCC    chr2

to this:

width seq                                                                                                                           names               
[1]    32 AAAAAAAAAAAAAAAATTTTTTTTTTTTTTTT                    chr1
[2]    48 GGGGGGGGGGGGGGAAAATTTTGGGGGGCCCCCCCCCCCCCCCCCCCC    chr2

And do it 30 times, randomly in the genome? (so take a seq from chr1 and put an insertion in chr2.

I tried this and more already for days, and I just cannot figure it out.

    library(RSVSim)    

    seq_random <- readDNAStringSet("/path/random.fasta", "fasta")
    seq_ref <- readDNAStringSet("/path/reference1MB.fasta", "fasta")
    genome2 = DNAStringSet(c(seq_random, seq_ref))
    names(genome2) = c("chr1","chr2")

    y <- c(30, 30, 30, 30, 30, 50, 50, 50, 50, 50, 100, 100, 100, 100, 100, 500, 500, 500, 500, 500, 1000, 1000, 1000, 1000, 1000, 5000, 5000, 5000, 5000, 5000)

    length_seq = width(genome2[2])
    knownInsertion = GRanges(IRanges(0,length_seq), seqnames="chr2")
    knownInsertion = GRanges(IRanges(0,length_seq), seqnames="chr1", chrB="chr2", chrA="chr1")
    knownInsertion = GRanges(seqnames="chr1", chrB="chr2")
    sim = simulateSV(output='/folder/of/output/', genome=genome2, 
                     ins = 30, sizeIns=y, regionsIns=knownInsertion)

EDIT for comment section

The simple genome example:

genome = DNAStringSet(c("AAAAAAAAAAAAAAAAAAAATTTTTTTTTTTTTTTTTTTT","GGGGGGGGGGGGGGGGGGGGCCCCCCCCCCCCCCCCCCCC"))
names(genome) = c("chr1","chr2")

I believe I already tried those parameters. For example:

knownInsertion = GRanges(IRanges(16,25), seqnames="chr1", chrB="chr2")
sim = simulateSV(output=NA, genome=genome, ins = 1, regionsIns=knownInsertion, bpSeqSize=6, random=TRUE)

results in:

> sim
  A DNAStringSet instance of length 2
    width seq                                                                                                                           names               
[1]    40 AAAAAAAAAAAAAAAAAAAATTTTTTTTTTTTTTTTTTTT                                                                                      chr1
[2]    40 GGGGGGGGGGGGGGGGGGGGCCCCCCCCCCCCCCCCCCCC                                                                                      chr2
> metadata(sim)
$insertions
         Name ChrA StartA EndA ChrB StartB EndB Size Copied BpSeqA BpSeqB_5prime BpSeqB_3prime
1 insertion_1 chr1      3   12 chr1      6   15   10  FALSE  AAAAA        AAAAAA        AAAAAA

so nothing happened at all. If I keep it simple, you get the result I mentioned before, where it is sometimes chr1->chr2 and sometimes chr2<-chr1

sim = simulateSV(output=NA, genome=genome, ins = 3, sizeIns = 5, bpSeqSize=6, random=TRUE)

> sim
  A DNAStringSet instance of length 2
    width seq                                                                                                                           names               
[1]    40 AAAAAACCCCCAAAAATTTTTTTTTTTTTTAAAATTTTTT                                                                                      chr1
[2]    40 GGGGGGGGAAAAAGGGGGGGGGGGGCCCCCCCCCCCCCCC                                                                                      chr2
> metadata(sim)
$insertions
         Name ChrA StartA EndA ChrB StartB EndB Size Copied BpSeqA BpSeqB_5prime BpSeqB_3prime
1 insertion_1 chr1     17   21 chr1     36   40    5  FALSE AAATTT        TTTAAA        AATTTT
2 insertion_2 chr1      1    5 chr2      9   13    5  FALSE               GGGAAA        AAAGGG
3 insertion_3 chr2     33   37 chr1     12   16    5  FALSE CCCCCC        AAACCC        CCCAAA

In this case I dont even know what happened exactly, because an uneven number of Ins, should make one of the chromosomes shorter or longer?

Finally, when setting copy on (so no cut/paste)

sim = simulateSV(output=NA, genome=genome, ins = 3, sizeIns = 5, bpSeqSize=6, random=TRUE, percCopiedIns=1.00)
sim
metadata(sim)

> sim
  A DNAStringSet instance of length 2
    width seq                                                                                                                           names               
[1]    50 AAAATTTTTAAAAAAAAAAAAAAAATTTTTTATTTTTTTTTTTTTTTTTT                                                                            chr1
[2]    45 GGGGGGGGGGGGGGGGGAAAAAGGGCCCCCCCCCCCCCCCCCCCC                                                                                 chr2
> metadata(sim)
$insertions
         Name ChrA StartA EndA ChrB StartB EndB Size Copied BpSeqA BpSeqB_5prime BpSeqB_3prime
1 insertion_1 chr1     36   40 chr1      5    9    5   TRUE               AAATTT        TTTAAA
2 insertion_2 chr1     20   24 chr1     27   31    5   TRUE               TTTATT        TTTTTT
3 insertion_3 chr1     13   17 chr2     18   22    5   TRUE               GGGAAA        AAAGGG

Again. all the examples above have random chrA and chrB. Setting these specifically, only seems possible with the GRanges and IRanges, for which I tried tons of versions already.

It should be a very simple thing according to the manual, but actually doing it doesn't seem to get the desired results, while my version of Insertions is just the normal one in my opinion? (why would you want to create extra DELS or DUPS while making insertions?).

On their own support page, it is only possible to ask a question on the forums, but they never answer it (only look at it)

$\endgroup$
  • 1
    $\begingroup$ What is the problem when using the simulateSV? You don't get the desired result or something else? From the manual it seems to be possible. BTW knownInsertion should be chromosome 2 if you want all the insertions to be into the chromosome 2. But perhaps you are missing the option random = TRUE $\endgroup$ – llrs Oct 24 '18 at 15:12
  • $\begingroup$ see my updated question. I really think it is weird that this very simple and logical thing isn't working. I already looked extensively at all the available manuals out there, but there are only 2. $\endgroup$ – Fini Oct 26 '18 at 6:28
  • $\begingroup$ If someone is able to make the result I want with python, it is also fine, but then I need the exact numbers where on the chromosome the edits WERE made (so not the numbers afterwards, so that I can reflect back to the original reference genome) $\endgroup$ – Fini Oct 26 '18 at 6:34
2
$\begingroup$

Answer eventually found on the BioConductor post: https://support.bioconductor.org/p/114354/#114585

It basically comes down to not using RSVSim, but other R packages.

Final code snippit:

genome = DNAStringSet(
  c(chr1 = "AAAAAAAAAAAAAAAAAAAATTTTTTTTTTTTTTTTTTTT",
    chr2 = "GGGGGGGGGGGGGGGGGGGGCCCCCCCCCCCCCCCCCCCC"))

sampleFromGenome <- function(genome, wd) {
  chrProb <- width(genome) / sum(width(genome))
  chr <- sample(names(genome), n, TRUE, prob = chrProb)
  start <- runif(n, 1, nchar(genome[chr]) - wd)
  GRanges(IRanges(start, width = wd), seqnames = chr)
}

n <- 2
wd <- sample(5:10, n, TRUE)
insertFrom <- sampleFromGenome(genome[1], wd)
insertAt <- sampleFromGenome(genome[2], 0)

#writeTable(insertFrom, stdout()) . # replace stdout with a file name

sequence <- genome[insertFrom]
at <- split(insertAt, seqnames(insertAt))[names(genome[2])]
atSequence <- split(sequence, seqnames(insertAt))[names(genome[2])]

replaceAt(genome[2], unname(ranges(at)), atSequence)

  A DNAStringSet instance of length 1
    width seq                                                                                                                           names               
[1]    54 GGGGGGGGGGGGGGGGGGTTTTTTTTTGGCCCCCCCCCCCCTTTTTCCCCCCCC                                                                        chr2

EDIT with RSVSim solution!

Finally found a solution based on RSVSim

genome = DNAStringSet(
  c(chr1 = "AAAAAAAAAAAAAAAAAAAATTTTTTTTTTTTTTTTTTTT",
    chr2 = "GGGGGGGGGGGGGGGGGGGGCCCCCCCCCCCCCCCCCCCC"))

length_seq_chr1 = width(genome[1]) - 10
length_seq_chr2 = width(genome[2]) - 10
sizes <- c(3,3,5,5)
start_chr1 <- c("list", length(sizes))
start_chr2 <- c("list", length(sizes))
end_chr1 <- c("list", length(sizes))
index = 1
for(i in sizes){
  newstartchr1 <- sample(1:length_seq_chr1,1)
  newstartchr2 <- sample(1:length_seq_chr2,1)
  start_chr1[[index]] <- newstartchr1
  start_chr2[[index]] <- newstartchr2
  end_chr1[[index]] <- newstartchr1 + (i-1)
  index <- index + 1}
start_chr1 <- as.integer(start_chr1)
end_chr1 <- as.integer(end_chr1)
start_chr2 <- as.integer(start_chr2)

knownInsertion2 = GRanges(IRanges(c(start_chr1),c(end_chr1)),seqnames="chr1", chrB="chr2", startB=c(start_chr2), copied=TRUE)
knownInsertion2

sim = simulateSV(output=NA, genome=genome, regionsIns=knownInsertion2, bpSeqSize=5, random=FALSE, verbose=FALSE)
sim
metadata(sim)

Gives as an result:

> knownInsertion2
GRanges object with 4 ranges and 3 metadata columns:
      seqnames    ranges strand |        chrB    startB    copied
         <Rle> <IRanges>  <Rle> | <character> <integer> <logical>
  [1]     chr1  [21, 24]      * |        chr2        30      TRUE
  [2]     chr1  [16, 19]      * |        chr2        21      TRUE
  [3]     chr1  [ 6, 11]      * |        chr2        10      TRUE
  [4]     chr1  [ 9, 14]      * |        chr2        27      TRUE
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths
> 
> sim = simulateSV(output=NA, genome=genome, regionsIns=knownInsertion2, bpSeqSize=5, random=FALSE, verbose=FALSE)
> sim
  A DNAStringSet instance of length 2
    width seq                                                                                                                           names               
[1]    40 AAAAAAAAAAAAAAAAAAAATTTTTTTTTTTTTTTTTTTT                                                                                      chr1
[2]    60 GGGGGGGGGAAAAAAGGGGGGGGGGGAAAACCCCCCAAAAAACCCTTTTCCCCCCCCCCC                                                                  chr2
> metadata(sim)
$insertions
  Name ChrA StartA EndA ChrB StartB EndB Size Copied BpSeqA BpSeqB_5prime BpSeqB_3prime
1    1 chr1     21   24 chr2     30   33    4   TRUE                 CCTT          TTCC
2    2 chr1     16   19 chr2     21   24    4   TRUE                 GGAA          AACC
3    3 chr1      6   11 chr2     10   15    6   TRUE                 GGAA          AAGG
4    4 chr1      9   14 chr2     27   32    6   TRUE                 CCAA          AACC

To make this customizable change:

sizes <- c(whatever, numbers, you, like)

output=NA (to a file path prefix to get a .csv file with the metadata)

genome = DNAStringSet() To replace the sample sequence

bpSeqSize = number (to change how many of the flanking region is shown in the metadata)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.