Skip to content

Commit 582e659

Browse files
committed
add cli flags to ft2 treebuilder
1 parent 98e1ed6 commit 582e659

6 files changed

Lines changed: 1986 additions & 1697 deletions

File tree

foldtree2/ft2treebuilder.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ def __init__ ( self , model , decoder_model = None, mafftmat = None , submat = N
3535
self.raxmlng_path = raxml_path
3636
self.modelname = model.split('/')[-1].split('.')[0]
3737

38+
if 'bs' in kwargs:
39+
self.bs = kwargs['bs']
40+
else:
41+
self.bs = False
42+
if 'redo' in kwargs:
43+
self.redo = kwargs['redo']
44+
else:
45+
self.redo = False
46+
3847
if charmaps is None:
3948
self.rev_replace_dict_ord = { ord(v):ord(k) for k,v in self.replace_dict.items() }
4049
self.raxml_path = raxml_path
@@ -48,6 +57,7 @@ def __init__ ( self , model , decoder_model = None, mafftmat = None , submat = N
4857
self.nchars = len(self.alphabet)
4958
self.map = { c:i for i,c in enumerate(self.alphabet)}
5059
self.revmap = { i:c for i,c in enumerate(self.alphabet)}
60+
5161
else:
5262
print('loading charmaps from', charmaps)
5363

@@ -357,16 +367,20 @@ def read_textaln(self, aln_hexfile , outfile = None):
357367
f.write('>' + i + '\n' + alndf.loc[i].remap_symbols + '\n')
358368
return outfile
359369

360-
def run_raxml_ng(self, fasta_file, matrix_file, nsymbols, output_prefix , iterations = 10 , cores = 8 , bs =False):
370+
def run_raxml_ng(self, fasta_file, matrix_file, nsymbols, output_prefix , iterations = 10 , cores = 8 ):
361371
raxmlng_path = self.raxml_path
362372
if raxmlng_path == None:
363373
raxmlng_path = 'raxml-ng'
364-
raxml_cmd = raxmlng_path + ' --model MULTI'+str(self.nchars)+'_GTR{'+matrix_file+'} --redo --all --bs-trees '+str(iterations)+' --seed 12345 --threads auto{' + str(self.ncores) + '} --workers auto --msa '+fasta_file+' --prefix '+output_prefix + ' --force perf_threads'
365-
#raxml_cmd =raxmlng_path + ' --model MULTI'+str(nsymbols)+'_GTR+I+G --redo --all --bs-trees '+str(iterations)+' --seed 12345 --threads 8 --msa '+fasta_file+' --prefix '+output_prefix
374+
raxml_cmd = raxmlng_path + ' --model MULTI'+str(self.nchars)+'_GTR{'+matrix_file+'} --seed 12345 --threads auto{' + str(self.ncores) + '} --workers auto --msa '+fasta_file+' --prefix '+output_prefix
375+
if self.bs == True:
376+
raxml_cmd += ' --force perf_threads --bs-trees '+str(iterations)+' --bs-metric fbp'
377+
if self.redo == True:
378+
raxml_cmd += ' --redo'
366379
print(raxml_cmd)
367380
subprocess.run(raxml_cmd, shell=True)
368381
return output_prefix + '.raxml.bestTree'
369382

383+
370384
#ancestral reconstruction
371385
#raxml-ng --ancestral --msa ali.fa --tree best.tre --model HKY --prefix ASR
372386

@@ -623,6 +637,9 @@ def main():
623637
parser.add_argument("--raxmlpath", default='raxml-ng', help="Path to RAxML-NG executable")
624638
parser.add_argument("--verbose", action="store_true", help="Enable verbose output")
625639
parser.add_argument("--device", default=None, help="Device to run the model on (default: None, uses CPU or GPU if available)")
640+
parser.add_argument( "--bs", action="store_true", help="Enable bootstrapping in RAxML-NG" )
641+
parser.add_argument( "--redo", action="store_true", help="Enable --redo flag in RAxML-NG to overwrite existing results" )
642+
626643
# Ancestral reconstruction options
627644
parser.add_argument("--ancestral", action="store_true", help="Perform ancestral reconstruction")
628645

@@ -685,7 +702,7 @@ def main():
685702

686703
# Create an instance of treebuilder
687704
tb = treebuilder(model=encoder_path, mafftmat=args.mafftmat, decoder_model=decoder_path, submat=args.submat , raxml_path=args.raxmlpath,
688-
aapropcsv=args.aapropcsv, maffttext2hex=args.maffttext2hex, maffthex2text=args.maffthex2text, ncores=args.ncores , charmaps=args.charmaps , device=args.device)
705+
aapropcsv=args.aapropcsv, maffttext2hex=args.maffttext2hex, maffthex2text=args.maffthex2text, ncores=args.ncores , charmaps=args.charmaps , device=args.device, bs=args.bs, redo=args.redo , verbose=args.verbose)
689706

690707
# Generate tree from structures using the provided options
691708
tb.structs2tree(structs=args.structures, outdir=args.outdir, ancestral=args.ancestral, raxml_iterations=args.raxml_iterations , raxml_path=args.raxmlpath , output_prefix=args.output_prefix

foldtree2/learn_monodecoder.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,29 @@ def decode_batch_reconstruction(encoder, decoder, z_batch, device, converter, ve
497497
writer = SummaryWriter(log_dir=tensorboard_log_dir)
498498

499499

500+
'''
501+
'geometry_transformer': {
502+
'in_channels': {'res': args.embedding_dim},
503+
'concat_positions': False,
504+
'hidden_channels': {('res','backbone','res'): [hidden_size], ('res','backbonerev','res'): [hidden_size]},
505+
'layers': 2,
506+
'nheads': 10,
507+
'RTdecoder_hidden': [hidden_size, hidden_size, hidden_size//2],
508+
'ssdecoder_hidden': [hidden_size,hidden_size, hidden_size//2],
509+
'anglesdecoder_hidden': [hidden_size, hidden_size,hidden_size//2],
510+
'dropout': 0.001,
511+
'normalize': False,
512+
'residual': False,
513+
'learn_positions': True,
514+
'use_cnn_decoder':True,
515+
'concat_positions': False,
516+
'output_rt': False, # Enable if you want rotation-translation
517+
'output_ss': True, # Secondary structure prediction
518+
'output_angles': True # Bond angles prediction
519+
},
520+
521+
'''
522+
500523
# Initialize or load model
501524
encoder_path = os.path.join(modeldir, modelname + '_best_encoder.pt')
502525
decoder_path = os.path.join(modeldir, modelname + '_best_decoder.pt')
@@ -575,27 +598,6 @@ def decode_batch_reconstruction(encoder, decoder, z_batch, device, converter, ve
575598
'concat_positions': False
576599
},
577600

578-
'geometry_transformer': {
579-
'in_channels': {'res': args.embedding_dim},
580-
'concat_positions': False,
581-
'hidden_channels': {('res','backbone','res'): [hidden_size], ('res','backbonerev','res'): [hidden_size]},
582-
'layers': 2,
583-
'nheads': 10,
584-
'RTdecoder_hidden': [hidden_size, hidden_size, hidden_size//2],
585-
'ssdecoder_hidden': [hidden_size,hidden_size, hidden_size//2],
586-
'anglesdecoder_hidden': [hidden_size, hidden_size,hidden_size//2],
587-
'dropout': 0.001,
588-
'normalize': False,
589-
'residual': False,
590-
'learn_positions': True,
591-
'use_cnn_decoder':True,
592-
'concat_positions': False,
593-
'output_rt': False, # Enable if you want rotation-translation
594-
'output_ss': True, # Secondary structure prediction
595-
'output_angles': True # Bond angles prediction
596-
},
597-
598-
599601
'geometry_cnn': {
600602
'in_channels': {'res': args.embedding_dim, 'godnode4decoder': ndim_godnode, 'foldx': 23, 'fft2r': ndim_fft2r, 'fft2i': ndim_fft2i},
601603
'concat_positions': False,

0 commit comments

Comments
 (0)