-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean the MSA to remove non-standard bases #59
Open
akashbahai
wants to merge
3
commits into
uw-ipd:main
Choose a base branch
from
akashbahai:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/bin/bash | ||
|
||
# Check if a character is a non-standard base, gap, or ambiguous base (N) | ||
function is_non_standard_character() { | ||
local char=$1 | ||
case "$char" in | ||
A|U|G|C|-|N) | ||
return 1 # Standard base, gap, or ambiguous base found | ||
;; | ||
*) | ||
return 0 # Non-standard base, gap, or ambiguous base found | ||
;; | ||
esac | ||
} | ||
|
||
# Check the input file and handle errors | ||
if [ $# -ne 1 ]; then | ||
echo "Usage: $0 <input_file.afa>" | ||
exit 1 | ||
fi | ||
|
||
input_file="$1" | ||
|
||
# Check if the input file exists | ||
if [ ! -f "$input_file" ]; then | ||
echo "Error: The input file '$input_file' does not exist." | ||
exit 1 | ||
fi | ||
|
||
# Extract the directory path from the input file's absolute path | ||
input_dir=$(dirname "$input_file") | ||
|
||
# Create a log file with the same name as the input file but with .log.txt extension | ||
log_file="${input_dir}/$(basename "${input_file%.*}")_log.txt" | ||
|
||
# Create a temporary file to store the new sequences in the same directory | ||
temp_output_file="${input_dir}/$(basename "${input_file%.*}")_temp.afa" | ||
|
||
# Redirect all output to the log file | ||
exec > "$log_file" | ||
|
||
# Initialize variables to store the current header and sequence | ||
current_header="" | ||
current_sequence="" | ||
|
||
# Process the input file line by line | ||
while IFS= read -r line; do | ||
if [[ "$line" =~ ^\> ]]; then | ||
# Process the previous sequence before moving to the new header | ||
if [ -n "$current_header" ] && [ -n "$current_sequence" ]; then | ||
# Check each character in the sequence for non-standard bases, gaps, or ambiguous bases | ||
skip_sequence=false | ||
for (( i=0; i<${#current_sequence}; i++ )); do | ||
char=${current_sequence:i:1} | ||
if is_non_standard_character "$char"; then | ||
echo "Non-standard character '$char' found in the sequence:" | ||
echo "$current_header" | ||
echo "$current_sequence" | ||
skip_sequence=true | ||
break | ||
fi | ||
done | ||
|
||
# Write to the temporary output file if the sequence contains no non-standard characters | ||
if ! $skip_sequence; then | ||
echo "$current_header" >> "$temp_output_file" | ||
echo "$current_sequence" >> "$temp_output_file" | ||
fi | ||
fi | ||
|
||
# Save the new header and reset the current sequence | ||
current_header="$line" | ||
current_sequence="" | ||
else | ||
# Accumulate sequence lines under the same header | ||
current_sequence+="$line" | ||
fi | ||
done < "$input_file" | ||
|
||
# Process the last sequence after reaching the end of the file | ||
if [ -n "$current_header" ] && [ -n "$current_sequence" ]; then | ||
# Check each character in the sequence for non-standard bases, gaps, or ambiguous bases | ||
skip_sequence=false | ||
for (( i=0; i<${#current_sequence}; i++ )); do | ||
char=${current_sequence:i:1} | ||
if is_non_standard_character "$char"; then | ||
echo "Non-standard character '$char' found in the sequence:" | ||
echo "$current_header" | ||
echo "$current_sequence" | ||
skip_sequence=true | ||
break | ||
fi | ||
done | ||
|
||
# Write to the temporary output file if the sequence contains no non-standard characters | ||
if ! $skip_sequence; then | ||
echo "$current_header" >> "$temp_output_file" | ||
echo "$current_sequence" >> "$temp_output_file" | ||
fi | ||
fi | ||
|
||
# Rename the old input file to basename_old.afa in the same directory | ||
mv "$input_file" "${input_dir}/$(basename "${input_file%.*}")_old.afa" | ||
|
||
# Rename the temporary file to the original input file in the same directory | ||
mv "$temp_output_file" "$input_file" | ||
|
||
# Provide a summary message in the log file | ||
echo "Processed $input_file. Removed sequences with non-standard bases and saved the results in $input_file." >> "$log_file" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you revert this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @fdimaio,
I have set the CPU and MEM resources to the default settings.