| 1 | red=`tputscip-shell system . . tput. setaf 1` |
| 2 | green=`tputscip-shell system . . tput. setaf 2` |
| 3 | cyan=`tputscip-shell system . . tput. setaf 6` |
| 4 | bold=`tputscip-shell system . . tput. bold` |
| 5 | reset=`tputscip-shell system . . tput. sgr0` |
| 6 | underline=`tputscip-shell system . . tput. smul` |
| 7 | no_underline=`tputscip-shell system . . tput. rmul` |
| 8 | |
| 9 | |
| 10 | wraith=false #$4 # set to true if you only want to see commands without executing them |
| 11 | phased_allele_file=$1 |
| 12 | disco_cofa_file=$2 |
| 13 | disco_uncofa_file=$3 |
| 14 | read_set_id=$4 |
| 15 | EDIR=$( python -c "import os.path; print(os.path.dirname(os.path.realpath(\"${BASH_SOURCE[0]}\")))" ) # as suggested by Philippe Bordron |
| 16 | if [scip-shell system . . `[`. -z "$phased_allele_file" ]; then |
| 17 | echoscip-shell system . . echo. "${red} You must provide a phased file name${reset}" |
| 18 | echoscip-shell system . . echo. "${red} Usage: $0 phased_allele_file disco_coherent.fa disco_uncoherent.fa read_set_id${reset}" |
| 19 | exit 1 |
| 20 | fi |
| 21 | |
| 22 | if [scip-shell system . . `[`. -z "$disco_cofa_file" ]; then |
| 23 | echoscip-shell system . . echo. "${red} You must provide a disco (coherent) file (\"...coherent.fa\")${reset}" |
| 24 | echoscip-shell system . . echo. "${red} Usage: $0 phased_allele_file disco_coherent.fa disco_uncoherent.fa read_set_id${reset}" |
| 25 | exit 1 |
| 26 | fi |
| 27 | |
| 28 | if [scip-shell system . . `[`. -z "$disco_uncofa_file" ]; then |
| 29 | echoscip-shell system . . echo. "${red} You must provide a disco (uncoherent) file (\"...uncoherent.fa\")${reset}" |
| 30 | echoscip-shell system . . echo. "${red} Usage: $0 phased_allele_file disco_coherent.fa disco_uncoherent.fa read_set_id${reset}" |
| 31 | exit 1 |
| 32 | fi |
| 33 | |
| 34 | if [scip-shell system . . `[`. -z "$read_set_id" ]; then |
| 35 | echoscip-shell system . . echo. "${red} You must provide a read set id (integer value from 1 to the number of read set used to create file $disco_cofa_file ${reset}" |
| 36 | echoscip-shell system . . echo. "${red} Usage: $0 phased_allele_file disco_coherent.fa disco_uncoherent.fa read_set_id${reset}" |
| 37 | exit 1 |
| 38 | fi |
| 39 | |
| 40 | |
| 41 | |
| 42 | # Creating a file where simple paths are compacted |
| 43 | |
| 44 | echoscip-shell system . . echo. "${green}${bold} ### EXPLOITATION OF PHASING INFORMATION OBTAINED FROM DISCOSNP${reset}" |
| 45 | echoscip-shell system . . echo. "${green} ### Input phased_allele_file: `sha1sumscip-shell system . . sha1sum. ${phased_allele_file}`${reset}" |
| 46 | echoscip-shell system . . echo. "${green} ### Input disco_cofa_file: `sha1sumscip-shell system . . sha1sum. ${disco_cofa_file}`${reset}" |
| 47 | echoscip-shell system . . echo. "${green} ### Input disco_uncofa_file: `sha1sumscip-shell system . . sha1sum. ${disco_uncofa_file}`${reset}" |
| 48 | echoscip-shell system . . echo. "${green} ### Input read_set_id: ${read_set_id}${reset}" |
| 49 | echoscip-shell system . . echo. "" |
| 50 | |
| 51 | # Prefiltering: removing non perfectly overlapping facts |
| 52 | echoscip-shell system . . echo. "${green} ### Removing non perfectly overlapping facts" |
| 53 | cmd="python3 ${EDIR}/K3000_filter_badly_overlapping_variants.py ${disco_cofa_file} ${disco_uncofa_file} ${phased_allele_file}" |
| 54 | echoscip-shell system . . echo. " "$cmd "> filtered_${phased_allele_file}${cyan}" |
| 55 | if [[ "$wraith" == "false" ]]; then |
| 56 | eval $cmd > filtered_${phased_allele_file} |
| 57 | fi |
| 58 | if [scip-shell system . . `[`. $? -ne 0 ] |
| 59 | then |
| 60 | echoscip-shell system . . echo. "${red} ###Problem detected, check logs.${reset}" |
| 61 | exit 1 |
| 62 | fi |
| 63 | |
| 64 | |
| 65 | |
| 66 | # Determining working zones: |
| 67 | echoscip-shell system . . echo. "${green} ### Determining working zones" |
| 68 | cmd="python3 ${EDIR}/K3000_working_zone_no_redundant_edges.py filtered_${phased_allele_file}" |
| 69 | echoscip-shell system . . echo. " "$cmd " > wz_filtered_${phased_allele_file}${cyan}" |
| 70 | if [[ "$wraith" == "false" ]]; then |
| 71 | eval $cmd > wz_filtered_${phased_allele_file} |
| 72 | fi |
| 73 | if [scip-shell system . . `[`. $? -ne 0 ] |
| 74 | then |
| 75 | echoscip-shell system . . echo. "${red} ###Problem detected, check logs.${reset}" |
| 76 | exit 1 |
| 77 | fi |
| 78 | |
| 79 | |
| 80 | # Creating a file where simple paths are compacted |
| 81 | echoscip-shell system . . echo. "${green} ### Creating a file where simple paths are compacted" |
| 82 | cmd="python3 ${EDIR}/K3000.py wz_filtered_${phased_allele_file}" |
| 83 | echoscip-shell system . . echo. " "$cmd "> compacted_facts_int_${read_set_id}.txt${cyan}" |
| 84 | if [[ "$wraith" == "false" ]]; then |
| 85 | eval $cmd > compacted_facts_int_${read_set_id}.txt |
| 86 | fi |
| 87 | if [scip-shell system . . `[`. $? -ne 0 ] |
| 88 | then |
| 89 | echoscip-shell system . . echo. "${red} ###Problem detected, check logs.${reset}" |
| 90 | exit 1 |
| 91 | fi |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | # Creating a file with sequences of the compacted paths and removing uncoherent compactions |
| 97 | echoscip-shell system . . echo. "${green} ### Creating a fasta file from compacted facts" |
| 98 | cmd="python3 ${EDIR}/K3000_paths_to_fa.py ${disco_cofa_file} ${disco_uncofa_file} compacted_facts_int_${read_set_id}.txt" |
| 99 | echoscip-shell system . . echo. " "$cmd "> compacted_facts_${read_set_id}.fa${cyan}" |
| 100 | if [[ "$wraith" == "false" ]]; then |
| 101 | eval $cmd > compacted_facts_${read_set_id}.fa |
| 102 | fi |
| 103 | if [scip-shell system . . `[`. $? -ne 0 ] |
| 104 | then |
| 105 | echoscip-shell system . . echo. "${red} ###Problem detected, check logs.${reset}" |
| 106 | exit 1 |
| 107 | fi |
| 108 | |
| 109 | echoscip-shell system . . echo. "${green} ### Select only valid facts and add their positions" |
| 110 | # /usr/bin/grep ">" compacted_facts.fa | cut -d ">" -f 2 | cut -d " " -f 1 > compacted_facts_int.txt |
| 111 | cmd="/usr/bin/grep \">\" compacted_facts_${read_set_id}.fa | cut -d \">\" -f 2" |
| 112 | echoscip-shell system . . echo. " "$cmd "> compacted_facts_int_${read_set_id}.txt${cyan}" |
| 113 | if [[ "$wraith" == "false" ]]; then |
| 114 | eval $cmd > compacted_facts_int_${read_set_id}.txt |
| 115 | fi |
| 116 | if [scip-shell system . . `[`. $? -ne 0 ] |
| 117 | then |
| 118 | echoscip-shell system . . echo. "${red} ###Problem detected, check logs.${reset}" |
| 119 | exit 1 |
| 120 | fi |
| 121 | |
| 122 | |
| 123 | ### Creating a GFA graph |
| 124 | echoscip-shell system . . echo. "${green} ### Creating a GFA graph" |
| 125 | # python3 ${EDIR}/K3000_facts_to_gfa.py compacted_facts_int.txt > compacted_facts.gfa |
| 126 | cmd="python3 ${EDIR}/K3000_facts_to_gfa.py compacted_facts_int_${read_set_id}.txt" |
| 127 | echoscip-shell system . . echo. " "$cmd "> compacted_facts_${read_set_id}.gfa${cyan}" |
| 128 | if [[ "$wraith" == "false" ]]; then |
| 129 | eval $cmd > compacted_facts_${read_set_id}.gfa |
| 130 | fi |
| 131 | if [scip-shell system . . `[`. $? -ne 0 ] |
| 132 | then |
| 133 | echoscip-shell system . . echo. "${red} ###Problem detected, check logs.${reset}" |
| 134 | exit 1 |
| 135 | fi |
| 136 | |
| 137 | |
| 138 | |
| 139 | # Adding paired edges and counting of compacted facts |
| 140 | echoscip-shell system . . echo. "${green} ### Adding paired edges and counting of compacted facts" |
| 141 | cmd="python3 ${EDIR}/K3000_enhance_gfa.py compacted_facts_${read_set_id}.gfa wz_filtered_${phased_allele_file} ${disco_cofa_file} ${disco_uncofa_file} ${read_set_id}" |
| 142 | echoscip-shell system . . echo. " "$cmd" > graph_${read_set_id}.gfa${cyan}" |
| 143 | if [[ "$wraith" == "false" ]]; then |
| 144 | eval $cmd > graph_${read_set_id}.gfa |
| 145 | fi |
| 146 | if [scip-shell system . . `[`. $? -ne 0 ] |
| 147 | then |
| 148 | echoscip-shell system . . echo. "${red} ###Problem detected, check logs.${reset}" |
| 149 | exit 1 |
| 150 | fi |
| 151 | |
| 152 | |
| 153 | # Detecting snp succesion |
| 154 | echoscip-shell system . . echo. "${green} ### Detecting snp succession" |
| 155 | # python3 ${EDIR}/find_unitig_connected_pairs_of_facts.py graph.gfa ${disco_cofa_file} > graph_plus.gfa |
| 156 | cmd="python3 ${EDIR}/K3000_find_unitig_connected_pairs_of_facts.py graph_${read_set_id}.gfa ${disco_cofa_file} ${disco_uncofa_file}" |
| 157 | echoscip-shell system . . echo. " "$cmd" > graph_plus_${read_set_id}.gfa${cyan}" |
| 158 | if [[ "$wraith" == "false" ]]; then |
| 159 | eval $cmd > graph_plus_${read_set_id}.gfa |
| 160 | fi |
| 161 | if [scip-shell system . . `[`. $? -ne 0 ] |
| 162 | then |
| 163 | echoscip-shell system . . echo. "${red} ###Problem detected, check logs.${reset}" |
| 164 | exit 1 |
| 165 | fi |
| 166 | |
| 167 | |
| 168 | echoscip-shell system . . echo. "${green} ### Create final graph with sequence content" |
| 169 | # python3 ${EDIR}/K3000_node_ids_to_node_sequences.py graph_plus.gfa compacted_facts.fa > graph_final.gfa |
| 170 | cmd="python3 ${EDIR}/K3000_node_ids_to_node_sequences.py graph_plus_${read_set_id}.gfa compacted_facts_${read_set_id}.fa" |
| 171 | echoscip-shell system . . echo. " "$cmd" > graph_final_${read_set_id}.gfa${cyan}" |
| 172 | if [[ "$wraith" == "false" ]]; then |
| 173 | eval $cmd > graph_final_${read_set_id}.gfa |
| 174 | fi |
| 175 | if [scip-shell system . . `[`. $? -ne 0 ] |
| 176 | then |
| 177 | echoscip-shell system . . echo. "${red} ###Problem detected, check logs.${reset}" |
| 178 | exit 1 |
| 179 | fi |
| 180 | |
| 181 | echoscip-shell system . . echo. "${green} ### Create stats (requires mathplotlib)" |
| 182 | cmd="python3 ${EDIR}/stats.py graph_plus_${read_set_id}.gfa graph_final_${read_set_id}.gfa ${read_set_id}" |
| 183 | echoscip-shell system . . echo. " "$cmd"${cyan}" |
| 184 | if [[ "$wraith" == "false" ]]; then |
| 185 | eval $cmd |
| 186 | fi |
| 187 | if [scip-shell system . . `[`. $? -ne 0 ] |
| 188 | then |
| 189 | echoscip-shell system . . echo. "${red} ### Non critical problem detected, check logs.${reset}" |
| 190 | echoscip-shell system . . echo. "${green} ### You may remove useless files: rm -f compacted_facts_int_${read_set_id}.txt compacted_facts_${read_set_id}.gfa graph_${read_set_id}.gfa compacted_facts_${read_set_id}.fa " |
| 191 | echoscip-shell system . . echo. "${green}${bold} ### EXPLOITATION OF PHASING INFORMATION OBTAINED FROM DISCOSNP ENDED, the final graph is $(tputscip-shell system . . tput. blink)${underline}graph_final_${read_set_id}.gfa${no_underline}${reset} " |
| 192 | exit 0 |
| 193 | fi |
| 194 | |
| 195 | # cleanup |
| 196 | echoscip-shell system . . echo. echo "${green} ### You may remove useless files: rm -f compacted_facts_int_${read_set_id}.txt compacted_facts_${read_set_id}.gfa graph_${read_set_id}.gfa compacted_facts_${read_set_id}.fa " |
| 197 | #rm -f compacted_facts_int.txt compacted_facts.gfa graph.gfa compacted_facts.fa graph_plus.gfa |
| 198 | |
| 199 | echoscip-shell system . . echo. "${green}${bold} ### EXPLOITATION OF PHASING INFORMATION OBTAINED FROM DISCOSNP ENDED, the final graph is ${underline}graph_final_${read_set_id}.gfa${no_underline}${green}${reset} ${green}${bold} stats are available in ${underline}distributions_${read_set_id}.png${no_underline}${reset}" |