FePhyFoFum / phyx

phylogenetics tools for linux (and other mostly posix compliant) computers
blackrim.org
GNU General Public License v3.0
111 stars 17 forks source link

pxrms .txt file using wildcard #183

Open luizmchado opened 5 months ago

luizmchado commented 5 months ago

Hi, is it possible to use a wildcard in the .txt specified file to remove i.e every taxon starting with the name Pilosocereus*.

This is the command I'm using:

for i in *.fasta; do pxrms -s "$i" -f /mnt/c/users/gabit/linux2/3.Combined_paralogs/reduced/taxa_to_delete_multiple.txt -o /mnt/c/users/gabit/linux2/3.Combined_paralogs/reduced/reduced2/"${i%.fasta}.fasta"; done

I've tried it multiple times unsuccessfully, even using -n and specifying the name as Pilosocereus. Any help would be appreciated.

taxa_to_delete_multiple.txt

josephwb commented 5 months ago

Hi @luizmchado. pxrms has a regex option (-r). This should do what you like:

pxrms -s TEST/test.fa -r Pilosocereus*

At the moment, the regex (-r) is separate from the -f and -n options. Combining them would require a significant restructuring. At the moment, the best I can suggest is doing multiple passes for whatever patterns you have. If there is only one pattern, -r should be sufficient.

luizmchado commented 5 months ago

Thanks for the insight @josephwb, would it work if I added multiple names delimited by commas i.e pxrms -s TEST/test.fa -r Pilosocereus,Micranthocereus?

josephwb commented 5 months ago

Unfortunately, no. Or, not yet. The regex bit was implemented independently of the lists, and so only at present assumes a single pattern; that is why I suggested the multiple passes idea. If you are really clever it may be possible to come up with a single regex that matches multiple cases, but this will not work for many scenarios.

luizmchado commented 5 months ago

Hello Joseph, after some work I came up with a solution. Wrote a bash script that uses a 'for' loop to iterate through every fasta file in the directory appointed (my biggest problem was the large volume of 577 .fasta files, and 92 taxons to be removed from them).

Here's the script I used:

!/bin/bash

Define the list of taxon names for each pass

taxon_names=( "Melocactus" "Another_Taxon" "Yet_Another_Taxon*"

Add more taxon names for additional passes as needed

)

Define initial directory for the first pass

initial_dir="/mnt/c/users/gabit/linux2/3.Combined_paralogs/reduced/reduced2"

Iterate over each taxon name and run pxrms command

for (( pass=0; pass<${#taxon_names[@]}; pass++ )); do

Determine the directory for the current pass

pass_dir="$initial_dir/pass_$((pass+1))"
mkdir -p "$pass_dir"

Process files using results from previous pass if available

if (( pass > 0 )); then
    prev_pass_dir="$initial_dir/pass_$pass"
    for input_file in "$prev_pass_dir"/*.fasta; do
        output_file="$pass_dir/$(basename "$input_file")"
        pxrms -s "$input_file" -r "${taxon_names[pass]}" -o "$output_file"
    done

Process files from initial directory for the first pass

else
    for input_file in *.fasta; do
        output_file="$pass_dir/$input_file"
        pxrms -s "$input_file" -r "${taxon_names[pass]}" -o "$output_file"
    done
fi
done

multi_pass_pxrms.txt

detailed explanation provided by chatgpt:

"In this modified script:

Each pass creates a new directory (pass_1, pass_2, etc.) where the output files are stored. For each pass after the first one, the script processes the output files from the previous pass, located in the directory of the previous pass. For the first pass, the script processes the initial .fasta files directly from the initial directory. The pxrms command processes each input file and generates an output file in the current pass directory.

This script ensures that each pass aggregates the results from the previous pass while maintaining the integrity of the original data."

Hope this helps anybody in a similar situation!

josephwb commented 5 months ago

Nicely done :) I'll see how difficult it will be to ingest a list of regexes to make things run more smoothly.

On Fri., Mar. 15, 2024, 16:49 Luiz Machado, @.***> wrote:

Hello Joseph, after some work I came up with a solution. Wrote a bash script that uses a 'for' loop to iterate through every fasta file in the directory appointed (my biggest problem was the large volume of 577 .fasta files, and 92 taxons to be removed from them).

Here's the script I used:

!/bin/bash

Define the list of taxon names for each pass

taxon_names=( "Melocactus" "Another_Taxon" "Yet_Another_Taxon*"

Add more taxon names for additional passes as needed

) Define initial directory for the first pass

initial_dir="/mnt/c/users/gabit/linux2/3.Combined_paralogs/reduced/reduced2" Iterate over each taxon name and run pxrms command

for (( pass=0; pass<${#taxon_names[@]}; pass++ )); do

Determine the directory for the current pass

pass_dir="$initialdir/pass$((pass+1))" mkdir -p "$pass_dir"

Process files using results from previous pass if available

if (( pass > 0 )); then prev_pass_dir="$initialdir/pass$pass" for input_file in "$prev_pass_dir"/*.fasta; do output_file="$pass_dir/$(basename "$input_file")" pxrms -s "$input_file" -r "${taxon_names[pass]}" -o "$output_file" done else

Process files from initial directory for the first pass

for input_file in *.fasta; do
    output_file="$pass_dir/$input_file"
    pxrms -s "$input_file" -r "${taxon_names[pass]}" -o "$output_file"
done

fi

done

detailed explanation provided by chatgpt:

"In this modified script:

Each pass creates a new directory (pass_1, pass_2, etc.) where the output files are stored. For each pass after the first one, the script processes the output files from the previous pass, located in the directory of the previous pass. For the first pass, the script processes the initial .fasta files directly from the initial directory. The pxrms command processes each input file and generates an output file in the current pass directory.

This script ensures that each pass aggregates the results from the previous pass while maintaining the integrity of the original data."

Hope this helps anybody in a similar situation!

— Reply to this email directly, view it on GitHub https://github.com/FePhyFoFum/phyx/issues/183#issuecomment-2000421317, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGFMM2JKHICPG2Y3BUXBO3YYNNE7AVCNFSM6AAAAABEXEDZAGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBQGQZDCMZRG4 . You are receiving this because you were mentioned.Message ID: @.***>

josephwb commented 5 months ago

Reopening bc it seems doable.