#! /usr/bin/awk -f # fix_busco_CDS_frame.awk Bernardo for Steganinae phylogeny project 9mar2018 v.10mar2018 # BUSCO produces some CDS with frame +2 or +3 which created problems in the posterior analysis, which are ot well solved by running translatorX with the -t T option. # uses Busco list of single orthologs , both the CDS (fna) and protein (faa) sequences #usage fix_busco_CDSframe.awk mode=detect diptera_odb9.gene_name function usage(dummy){ print "BUSCO produce some CDS with frame +2 or +3 which created problems in the posterior analysis. " print "This script will convert all them to frame +1 by adding N or NN at the begining of the sequence, and will overwrite the wrong CDS" print "usage:" print "fix_busco_CDS_frame.awk diptera_odb9.gene_name" print "fix_busco_CDS_frame.awk mode=detect diptera_odb9.gene_name [mode=detect will only detect tye probem. mode=fix is the default] " print "other options: verbose=0 [no log is printed] verbose=1 [prints total CDS found, total CDS corrected; default] verbose=2 [same as 1 , plus lists each corrected CDS ]" flag_exit=1; exit } BEGIN{ if (ARGC==1){usage(dummy)} total_CDS=0; wrong_frame_CDS=0 ; fixed_CDS=0 } (NR==1){ # n_species=split(species,species_array) # for (i=1; i<=n_species; i++){output_prefix=output_prefix species_array[i] "_"} # Ehians_Git3_nav_ # if (file_extension == ""){file_extension="fna"} if (mode == ""){mode="fix"} if (verbose == ""){verbose="1"} } (NR>=1){ current_ortholog=$1 ortholog_count ++ flag_files_existence = system("test -f " current_ortholog".fna") + system("test -f " current_ortholog".faa") # 0 if the expression is true, 1 if the expression is false #it is normal that some files do not exist: the corresponding ortholog was not annotated by BUSCO in the species. if (flag_files_existence == 0){ total_CDS_found ++ flag_blast_error=0 ; frame=0 # bl2seq -p blastx -i phoEOG0915074U_CDS.fasta -j phoEOG0915074U_prot.fasta -F F -D 1 -e 0.00001 cmd_bl2seq = "bl2seq -p blastx -i " current_ortholog ".fna -j " current_ortholog ".faa -F F -D 1 -e 0.00001 | sed '/^#/d' " flag_blast_error = cmd_bl2seq | getline bl2seq_output #return value from getline: 1 if successful, -1 if there is an error if (flag_blast_error != 1){print "error while performing command " cmd_bl2seq ; exit} close(cmd_bl2seq) # bl2seq Fields: Query id, Subject id, % identity, alignment length, mismatches, gap openings, q. start, q. end, s. start, s. end, e-value, bit score split(bl2seq_output,a) identity=a[3] ; query_start=a[7] frame = (query_start -1 )%3 +1 #alignment start with 1,4,7... frame +1 alignment start with 2,5,10... frame +2 alignment start with 3,6,11... frame +3 if (frame != 1){ wrong_frame_CDS ++ flag_fix_frame_error=0 ; if (verbose >=2) {print current_ortholog "CDS is on frame +" frame } addedN="nnn" #just a mark; should not be used if (frame==2){addedN="nn"} if (frame==3){addedN="n"} cmd_fix_frame = "sed -e '/>/{s/$/\\n" addedN "/}' " current_ortholog ".fna " "> temp.fna ;" " mv temp.fna " current_ortholog ".fna " # print cmd_fix_frame if (mode=="fix"){ flag_fix_frame_error = system(cmd_fix_frame) fixed_CDS ++ if (flag_fix_frame_error == -1){print "error while performing command " cmd_fix_frame ; exit} } } } } END{ if (verbose >=1){print "CDS listed in input file: " ortholog_count, "total CDS found: " total_CDS_found, "wrong frame CDS: " wrong_frame_CDS, "fixed CDS: ", fixed_CDS } } # EOG09150006 # EOG09150009 # EOG0915000C # EOG0915000S # EOG0915000X # awk 'BEGIN {print getline < "file" < 0 ? "not exists" : "exists"}' # if (system("test -f " FILE)) { ... } # awk 'BEGIN{print (system("test -f " FILE))}' # awk 'BEGIN{print (system("test -f coloc.data"))}' # awk 'BEGIN { # cmd = "date -j -f %s" # cmd | getline mydate # close(cmd) # }'