
These 4 perl scripts are written to combine CNV calls made with Birdsuite and PennCNV, and 
detect pre- and post-twinning CNVs in monozygotic twins. The scripts were written and used for: 
- Erik Ehli, Abdel Abdellaoui et al (2012). "De novo and inherited CNVs in MZ twin pairs selected 
  for discordance and concordance on Attention Problems". European Journal of Human Genetics.

For questions/comments about these scripts, please contact Abdel Abdellaoui at a.abdellaoui@vu.nl.


A NOTE ON SUBJECT IDs:

The subject/individual IDs must be in a specific format in order for the scripts to work:
The ID must consist of a family ID (5 nrs) and a person ID (2 nrs), separated by a dash (-). 
The family ID can be any combination of five numbers, and the person ID is either 01 or 02 
if the individual is a twin member, 31 if it is the father, and 41 if it is the mother. 
A family with the family ID 12345 for example would have the following IDs:
Twin 1: 12345-01
Twin 2: 12345-02
Father: 12345-31
Mother: 12345-41


THE SCRIPTS:

	--- Birdsuite_vs_PennCNV_to_plink.pl ---
Usage:
perl Birdsuite_vs_PennCNV_to_plink.pl <.birdseye_calls file> <.rawcnv file> <minimum overlap size (bp)> <output file>

The Birdsuite_vs_PennCNV_to_plink.pl script combines Birdsuite calls and PennCNV calls. The output
consists of CNV calls that agree between Birdsuite and PennCNV and have an overlap of at least X bp,
where X is a number that can be given as input to the program. 
This script also filters out all centromere regions (NOTE: this option only works well if the
coordinates are from build hg18!).

Input-files:
* Birdseye output file from Birdsuite (with extension .birdseye_calls). The format of the first
  column must be: familyID-personID.CEL (for example: 12345-01.CEL). This file must be sorted
  numerically, which can be achieved simply by using the Unix sort command (sort -n filename).
* PennCNV output file (with extension .rawcnv). The fifth columns containing information about
  the input file must contain the individual ID in the format: 12345_01.txt (note that the 
  family ID and the person ID are separated with an underscore here instead of a dash).

Output-file:
The output of this script is a .cnv file in Plink format. The SCORE and SITE columns will all have a 
value of 100, which do not reflect the actual confidence score or number of probes. To be able to use 
the file in Plink, an additional .map file has to be created with the Plink command 
"plink --cnv-list file.cnv --cnv-make-map". See for more information on the Plink format: 
http://pngu.mgh.harvard.edu/~purcell/plink/cnv.shtml.


	--- Birdsuite_vs_PennCNV.pl ---
Usage:
perl Birdsuite_vs_PennCNV.pl <.birdseye_calls file> <.rawcnv file> <minimum overlap size in bp> <output file>

The Birdsuite_vs_PennCNV_to_plink.pl script combines Birdsuite calls and PennCNV calls. The output
consists of CNV calls that agree between Birdsuite and PennCNV and have an overlap of at least X kb,
where X is a number that can be given as input to the program. The output in a format suited for the 
scripts that detect pre- and post-twinning de novo CNVs (pre_twinning_de_novos.pl & 
post_twinning_de_novos.pl respectively).
This script also filters out all centromere regions (NOTE: this option only works well if the
coordinates are from build hg18!).

Input-files:
* Birdseye output file from Birdsuite (with extension .birdseye_calls). The format of the first
  column must be: familyID-personID.CEL (for example: 12345-01.CEL). This file must be sorted
  numerically, which can be achieved simply by using the Unix sort command (sort -n filename).
* PennCNV output file (with extension .rawcnv). The fifth columns containing information about
  the input file must contain the individual ID in the format: 12345_01.txt (note that the 
  family ID and the person ID are separated with an underscore here instead of a dash).

Output-file:
The output file of this script consists of the following 19 tab-delimited columns:
- perID:		person ID - must be in format: 00001-01 -> family ID (5 nrs) + "-" + person ID (2 nrs)
- overlap_prop:	proportion overlap (Birdsuite & PennCNV)
- overlap_size:	size overlap (Birdsuite & PennCNV)
- start:		segment start (overlap Birdsuite & PennCNV)
- end:			segment end (overlap Birdsuite & PennCNV)
- chr_BS: 		chr (Birdsuite)
- start_BS:		segment start (Birdsuite)
- end_BS:		segment end (Birdsuite)
- size_BS:		size of CNV (Birdsuite)
- num_probes_BS:	number of loci (CN or SNP probes) in the segment (Birdsuite)
- cn_BS:		CN call (Birdsuite)
- chr_PC: 		chr (PennCNV)
- start_PC:		segment start (PennCNV)
- end_PC:		segment end (PennCNV)
- size_PC:		size of CNV (PennCNV)
- num_probes_PC:	number of loci (CN or SNP probes) in the segment (PennCNV)
- cn_PC:		CN call (PennCNV)
- lod_score_BS:	LOD score of the probability of the segment being the stated copy number versus the 
			copy number of the flanking segments
- cn_agreement: 	Has to be 1 for all CNVs (means Birdsuite & PennCNV call is the same) or -1 (means 
			that there were no losses or gains and comes from Birdsuite)


	--- pre_twinning_de_novos.pl ---
Usage:
perl pre_twinning_denovos <output file from Birdsuite_vs_PennCNV.pl> <output file>

This script compares CNVs between MZ twins and their parents, and writes an output file containing 
the CNVs that show a discordant copy number (CN) between the twins and their parents. In order to 
judge whether a CNV is inherited or de novo, allele specific CN information would needed from the 
parents. Since allele specific CN calls are not made by Birdsuite or PennCNV, the allele specific 
CNs was assumed to be as follows: if CN = 2, each allele is assumed to have a CN of 1 (1-1), if CN = 3, 
1-2 is assumed, if CN = 4, 2-2 is assumed, if CN = 1, 1-0 is assumed, if CN = 0, 0-0 is assumed. 
NOTE: This script may take between 3 and 4 hours to run for about 50 MZ twin pairs.

Input-file:
* The input-file must be in the format of the outputfile of Birdsuite_vs_PennCNV.pl 

Output-file:
The output file of this script consists of a CNV that differs between the twins and the parents on 
each row, and the following 13 tab-delimited columns:
- famID:		family ID - in format: 00001 (5 nrs)
- chr:			chromosome
- start:		start bp
- end:			end bp
- size:		size of the overlapping segment	
- tw1_cn:		CN - twin 1
- tw1_lod_score:	Lod score (measure from Birdsuite) - twin 1 
- tw2_cn		CN - twin 2
- tw2_lod_score	Lod score (measure from Birdsuite) - twin 2 
- father_cn		CN - father
- father_lod_score	Lod score (measure from Birdsuite) - father 
- mother_cn		CN - mother
- mother_lod_score	Lod score (measure from Birdsuite) - mother 


	--- post_twinning_de_novos.pl ---
Usage:
perl post_twinning_de_novos.pl <output file from Birdsuite_vs_PennCNV.pl> <output file>

This script compares CNVs between MZ twins, and writes an output file containing the CNVs that show
a discordant copy number (CN) between the twins. 
NOTE: This script may take between 3 and 4 hours to run for about 50 MZ twin pairs.

Input-file:
* The input-file must be in the format of the outputfile of Birdsuite_vs_PennCNV.pl 

Output-file:
The output file of this script consists of a CNV that differs between the twins on each row, and the 
following 21 tab-delimited columns:
- famID			family ID - in format: 00001 (5 nrs)
- tw1_chr			chromosome - twin 1
- tw1_start			start bp - twin 1
- tw1_end			end bp - twin 1
- tw1_size			CNV size - twin 1
- tw1_num_probes_BS		Nr of probes in Birdsuite call - twin 1
- tw1_num_probes_PC		Nr of probes in PennCNV call - twin 1
- tw1_cn			CN - twin 1
- tw1_lod_score		Lod score - twin 1
- tw2_chr			chromosome - twin 2 (must be the same as twin 1)
- tw2_start			start bp - twin 2
- tw2_end			end bp - twin 2
- tw2_size			CNV size - twin 2
- tw2_num_probes_BS		Nr of probes in Birdsuite call - twin 2
- tw2_num_probes_PC		Nr of probes in PennCNV call - twin 2
- tw2_cn			CN - twin 2
- tw2_lod_score		Lod score - twin 2
- tw1tw2_cnv_overlap		size of the overlapping part
- tw1tw2_cnv_overlap_start	start bp position of the overlapping part
- tw1tw2_cnv_overlap_end	end bp position of the overlapping part
- tw1tw2_cnv_overlap_prop	proportion of both CNVs (i.e., size of CNV twin 1 & CNV twin 2 combined) that overlaps 
				between the twins

