<p>Dear all,</p>

<p>I have WES bam files from tumour samples and a normal sample of one patient, and I would like to estimate the tumour purity of the tumour samples with <a href="http://www.broadinstitute.org/cancer/cga/absolute_run">ABSOLUTE</a>. They say that &quot;you can supply a tab delimited segmentation file (e.g. from array CGH or massively parralel sequencing experiments) - this file must contain the columns &quot;Chromosome&quot;, &quot;Start&quot;, &quot;End&quot;, &quot;Num_Probes&quot; and &quot;Segment_Mean&quot;.&quot;.</p>

<p>I have read similar questions <a href="https://www.biostars.org/p/92536/#92649">here</a> and <a href="https://www.biostars.org/p/93067/">here</a>, but I still haven&#39;t understood how to create the segmentation file.</p>

<p>I have already analysed copy number alterations (CNAs) using <a href="https://github.com/PeeperLab/CopywriteR">CopywriteR</a> and it gives me a read_counts file with &quot;Chromosomes&quot;, &quot;Start&quot;, &quot;End&quot; and the read counts for the samples but I don&#39;t see where to get the &quot;Num_probes&quot; and the &quot;Segment_Mean&quot; information.</p>

<p>I would highly appreciate your help</p>

If you've run all 3 phases of the CopywriteR pipeline (the functions `preCopywriteR`, `CopywriteR`, and `plotCNA`) according to the tutorial/vignette/manual, then in the output folder, under the `CNAprofiles` subdirectory where you find `read_counts.txt` and all the other output files, there will be a file called `segment.Rdata` -- this is generated by `plotCNA`.

If you load `segment.Rdata` in R, you get a list with an `$output` field that contains the dataframe you need, essentially in SEG format. Here's my script for loading that file and converting it to SEG:

```r
#!/usr/bin/env Rscript
# Usage: Rscript copywriter2seg.R <in_fname.Rdata> <out_fname.seg>

(args = commandArgs(TRUE))

in_fname = args[1]  # e.g. segment.Rdata
out_fname = args[2]  # e.g. sample.seg
cat("Loading", in_fname, "\n")
load(in_fname)
seg = segment.CNA.object$output
seg$loc.start = floor(seg$loc.start)  # force coordinates to be integers
seg$loc.end = floor(seg$loc.end)
write.table(seg, out_fname, quote=FALSE, sep="\t", row.names=FALSE, col.names=TRUE)
cat("Wrote", out_fname, "\n")
```