Short description of scripts accompanying the manuscript 
"Y chromosome-coded HSATII repeats may contribute to higher incidence of cancer in men"
by Hedi Hegyi and Matej Lexa

Note: some of the scripts call another script - so it is best to keep all of them
in the same directory as well as the data

- 1 -
remove_selfhics.sh - The shell script will remove those HiC pairs that overlap ('intersect' in bedtools parlance)
with the same repeat as defined by RepeatMasker
#One needs as input the HiC-TE output files, such as
SRR15458782_chm13_genomic_fragments_annotated2_toHiC_All.bed
SRR15458782_chm13_genomic_fragments_annotated2_toHiC_All.tab

The script will prompt the user for the SRA (Sequence Read Archive) identifier, in the above case this is
SRR15458782
#The output files will be
SRR15458782_chm13_genomic_fragments_annotated3_toHiC_All.bed
SRR15458782_chm13_genomic_fragments_annotated3_toHiC_All.tab
#There are 5 other SRA samples we tackled, two more untreated:
SRR15458780
SRR15458783

#two treated samples:
SRR15458768
SRR15458784

#and one knockout sample:
SRR15458769

One has to run remove_selfhics.sh for each identifier separately.
#The remove_selfhics.sh shell script will call 3 perl scripts:
globalsubstitution.pl
insbcolN.pl
select-col-toexclude.pl
#They have to be placed in the same directory or one has to give the correct path to them.

- 2 -
./run_anything_inthisdir_forfilesinlist.pl tabfiles ./table6rep_distances.pl tab chr_reppairs

#To generate the intrachromosomal distances for repeat pairs one has to run
./run_anything_inthisdir_forfilesinlist.pl tabfiles ./table6rep_distances.pl tab chr_reppairs
To get the same results we got in the paper one has to at first generate the
SRR..._chm13_genomic_fragments_annotated3_toHiC_All.tab files as described before.
These .reppairs files will be the basis for the Fig3 figures in the manuscript.
This one command will perform the calculations for all 6 samples listed in the
tabfiles file.

- 3 -
#The scripts

s68_gapbarplotHSATII.R
s69_gapbarplotHSATII.R
s80_gapbarplotHSATII.R

will generate figures Fig3[abc].

One needs to call them 
Rscript s68_gapbarplotHSATII.R
#etc
#One needs the .chr_reppairs files (see above) as input to generate the distribution (histogram) figures like in Fig3 in the manuscript.

- 4 -
#By calling
Rscript histogram4hsatii_writeoutvalues_nolimit_transpose.R

a summary table will be generated similar as above but here
the full length of intrachromosomal distances are recorded
(while in the s68_gapbarplotHSATII.R, etc. scripts the distances will be
counted only up to 20 million basepairs).

The script will generate a transposed table, transposed_hist_nolimit.tsv
which can be used to generate the dendrogram shown in Fig4 in the manuscript.

- 5 -
#To generate the dendrogram in Fig 4 call 

Rscript dendrogram_hclust_nolimit.R

and the output file dendrogram_transposed_hist_nolimit.png
will be generated.

- 6 -
To generate interchromosomal paircounts files:
one needs the files listed in the file "tabfiles": 
./run_anything_inthisdir_forfilesinlist.pl tabfiles ./table7_count_reppairs_on_diffchroms.pl tab paircounts

- 7 -
To sum up interchromosomal paircounts for chr1 and chrY:
./run_anything_inthisdir_forfiles_w_matchingext.pl ./table6calcave_paircounts_chr16cont_sumups.pl paircounts chr16sum
./run_anything_inthisdir_forfiles_w_matchingext.pl ./table6calcave_paircounts_chrYcont_sumups.pl paircounts chrYsum
#after that read in chrYsum files and count pairs where one of the pairs is on chrY and one of them maps to a HSATII (or any other) repeat

#these three shell scripts will generate 3 tables that contain the counts for chrY- and HSATII-containing pairs:
c2_chrY.sh
#counts for chrY- and Alu-containing pairs:
c2_chrY_Alu.sh
#counts for chr16- and HSATII-containing pairs:
c2_chr16.sh
#These shell scripts call perl script ./unify-table1-table2-zerostring.pl that have to be placed also in the directory where the input files are

- 8 -
#After we generated the 3 .tsv8 files that contain the counts for the treated and uptreated samples
#we can generate Fig5a figure by calling:
Rscript Fig5a_chrY.R
#Fig 5b:
Rscript Fig5b_chrY_Alu.R
#Fig 5c:
Rscript Fig5c_chr16.R

- 9 -
#To calculate the p-value of a t-test between treated and untreated samples for chrY-containing repeats between a specific repeat type
#and any other:
Rscript ttest_columns_selectrows_clever.R

- 10 -
To itaretively unite overlapping repeats of the same type as determined by RepeatMasker:

./iterate_repeat_concat.pl sample.bed

#one can replace sample.bed with any bed formatted file
concat_bedfile_identreps.pl and select_bed5p_new.pl have to be in the same directory
