The meaning of every parameter used here will be explained in Step by Step part. Users should only specify the paths of fasta file and log file.
python
1from ACEP import Args, PreProcessor, Fileprepare, Simulators, Embedding, ConvStat
23# specify the MSA fasta file and log file path4workfile ="./ACEP/examples/ENSG00000000003.fasta"5logpath ="./ACEP/examples/ACEP.log"6# specify the foreground species by list7case_sps1 =['Physeter_catodon','Lipotes_vexillifer','Delphinapterus_leucas','Orcinus_orca','Tursiops_truncatus']8case_sps2 =['Miniopterus_natalensis','Myotis_davidii','Myotis_brandtii','Myotis_lucifugus','Eptesicus_fuscus','Hipposideros_armiger','Rhinolophus_sinicus','Rousettus_aegyptiacus']9args = Args(workfile, logpath, case_sps1=case_sps1, case_sps2=case_sps2)10# specify the foreground species in ./examples/case_sps.txt11args = Args(workfile, logpath)1213# preprocessing of raw MSA file14pp = PreProcessor(args)15pp.Clean()16# prepare the file for paml inference17fp = Fileprepare(args)18fp.Infer()19# simulating the null sequences based on paml inferred files20simer = Simulators(args)21simer.GenerateNull()22# embedding the sequences based on pretrained protein models23embeder = Embedding(args)24embeder.embedding()25# calculate the empirical P value26ConvS = ConvStat(args)27ConvS.Pval()
Asides from the above, users can simply use the Acep_test function from script example.py in package. The Acep_test function can redo the whole process or start from the breakpoint.
Step by step
Parameters prepare
workfile: the path of MSA fasta file logpath: the path of log file case_sps: default value, the txt file of foreground species, the first line is group 1 and the second line is group 2, separated by comma case_sps1: default value, list of foreground species in group 1, specify the case_sps or this case_sps2: default value, list of foreground species in group 2, specify the case_sps or this sps_tree: default value, the path of species tree without branch length ctl_file: default value, the path of control file pattern for paml inference subs_mat: default value, the type of substitution model for paml inference gap_prop: default value, the threshold of gap proportion of a deleted sequence freq_mode: default value, amino acid frequency across gene or site in simulation process_name: default value, name the process by yourself sim_repeats: default value, number of simulation repeats pretrained_esm: choose esm-msa-1b or esm-2, default value if esm-msa-1b device: default value is cuda:0 batch: specify the number of sequence send into model in one batch encoder: specify the type of bottleneck encoder, choose mammal or plant onlyForeground: default value is True, only calculate the embeddings of foreground species redo: if use the exmaple.py for ACEP test, redo means delete all cache file then redo the whole process\
[!WARNING]Important note: Must specify the onlyForeground parameter as False when using Permulation test.
python
1from ACEP import Args
23# specify the MSA fasta file and log file path4workfile ="ACEP/ACEP/examples/ENSG00000000003.fasta"5logpath ="ACEP/ACEP/examples/ACEP.log"6# specify the foreground species by list7case_sps1 =['Physeter_catodon','Lipotes_vexillifer','Delphinapterus_leucas','Orcinus_orca','Tursiops_truncatus']8case_sps2 =['Miniopterus_natalensis','Myotis_davidii','Myotis_brandtii','Myotis_lucifugus','Eptesicus_fuscus','Hipposideros_armiger','Rhinolophus_sinicus','Rousettus_aegyptiacus']9args = Args(workfile, logpath, case_sps1=case_sps1, case_sps2=case_sps2)10# specify the foreground species in ./examples/case_sps.txt11args = Args(workfile, logpath)
Preprocess of raw protein sequences and codon sequences
If the sequence length is greater than 1024 after gaps cleaning, then the fasta file will be split into multiple pieces.
Output will be multiple directories named by id of genes each contains a fasta file with suffix .clean.
Inference of evolutionary parameters and ancestral sequence reconstruction by PAML
Evolutionary rates and ancestral sequences are crucial parameters for simulating null sequences which represent the case that protein sequences evolve under neutral circumstances.
Output will be directory with suffix pamlparas containing control file, partial tree file and specified control file in each gene's corresponding directory.
We will obtain constructed ancestral sequence and tree topology with inferred branch lengths in rst file. In addition, every site's evolutionary rate is deposited in rates file. These parameters will be transferred for simulating null sequences in next step.
Simulation of null sequences under neutral circumstance
This step will simulate null protein sequences from constructed ancestral protein sequence in root node under neutral circumstance along the fixed tree topology with inferred branch length by PAML in former step.
There will be a new directory within each gene's directory ending with inferred_tree which contains tree nwk file with inferred branch lengths. And the simulated sequences is stored in seqid_sim100.fasta with default 100 times of simulation.
Protein sequences embedding calculation based on ESM-MSA-1b and bottleneck
The script of this step intends to calculate the embeddings of protein sequences based on pretrained protein model and bottleneck full linear layer with parameters we obtain after training.
After this step, there will be four new files in each gene's directory. One with suffix embedding_real.npy save the original protein sequences' embeddings, another with suffix embedding_sim.npy contains all simulated sequences' corresponding embeddings. File with suffix embindex_real.json save the label of corresponding sequence in embedding_real.npy. File with suffix embindex_sim.json is the same.
1. Statistical test of convergence by distances comparison
This script will calculate the distribution of distances of two focus species groups pair by pair using simulated MSAs and real MSA. And the species pairs are stored in file with suffix PairIndices.json.
Finally, file with suffix pvalues.json contains empirical P values of cosine distance and Euclidean distance.
The P value will be presented in the following form.
{"cos_pvalue": 0.32, "euc_pvalue": 0.39}
2. Statistical test of convergence by permutation with trait simulation (Permulation)
Permulation test, which based on RERconverge, will permutate binary traits in phylogenetic tree by macroevolution simulation, two foreground groups will be generated during each simulation. Mean / Minimum distance between two groups will be used as null distribution for empirical P value calculation.
Details of permulation test script is Permtest_example.sh in PermTest directory. Meanings of each parameter are show below.
shell
1# Permulation2Rscript Perm.R Seqid
3 Times of permulation
4 Path of species tree
5 Output path
6 Foreground species file7 Inferred gene tree path
8 Whether maintain the permulation result overlapped with original one
910Rscript Perm.R ENSG00000000003_0
1110012 ./SpeciesAged.nwk
13 ./
14 ./case_sps.txt
15../ACEP/examples/ENSG00000000003/ENSG00000000003_0/ENSG00000000003_0_inferred_tree/tree_inferred_branch.nwk
16 TRUE
shell
1# Statistical test based on permulation results2python PermTest.py Seqid
3 Times of permulation
4 Path of permulation result
5 Path of species tree
6 Foreground species file7 Inferred gene tree path
8 The path of directory which contain original sequence embedding
9 Output path
10 Calculate the mean or minimum distance between foreground groups1112python PermTest.py ENSG00000000003_0
1310014 ./ENSG00000000003_0/ENSG00000000003_0_100Permulated.txt
15 ./case_sps.txt
16../ACEP/examples/ENSG00000000003/ENSG00000000003_0/ENSG00000000003_0_inferred_tree/tree_inferred_branch.nwk
17../ACEP/examples/ENSG00000000003/ENSG00000000003_0/ENSG00000000003_0_alter_Embedding
18 ./
19 Min
The empirical P value result will be stored in output path in json file and the P value will be presented in the following form.