Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Bugs & Fixes 2 years ago
Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
I have 29 fasta files (.fa as extension) named and stored sequences according to their genes.
(Example: ribosomal protein L1, ribosomal protein L6P/L9E,...)
There were a total of 722 species existed among all those 29 fasta files. Each sequence has their genes and species name labelled in the first line and second line was filled with its sequence.
There will be more than 1 gene sequence for 1 species.
I want to transfer the 722 species from 29 fasta files sorted according to genes into separate 722 files (sort them under species instead of genes).
The name of the species in the parent file were enclosed by square brakets [ ].
[ ]
How can I use for loops to extract the 722 files and name the files according to its sequence name?
Example from Ribosomal Protein L1.fa:
Ribosomal Protein L1.fa
>gi|103486926|ref|YP_616487.1| 50S ribosomal protein L1 [Sphingopyxis alaskensis RB2256] MAKLTKKQKALEGKVDAQKLHGVDEAIKLVRELATAKFDETLEIAMNLGVDPRHADQMVRGVVTLPAGTGKDVKVAVFAR
Example from Ribosomal Protein L6PL9E.fa:
Ribosomal Protein L6PL9E.fa
>gi|410479108|ref|YP_006766745.1| ribosomal protein L6P/L9E [Leptospirillum ferriphilum ML-04] MGFTHTVEFTLPSLIKASIEKQTIITLSSPDKELLGQFAADVRSIRPPEPYKGKGIKYSGEKILRKEGKTGKK
For the first example,
Species name: Sphingopyxis alaskensis RB2256
Gene sequence: MAKLTKKQKALEGKVDAQKLHGVDEAIKLVRELATAKFDETLEIAMNLGVDPRHADQMVRGVVTLPAGTGKDVKVAVFA
I wanted to name the file as Sphingopyxis alaskensis RB2256.fa and insert all sequences with this species name into this file.
Sphingopyxis alaskensis RB2256.fa
I am using bash shell to do this. I can use grep to have things done:
grep
grep -A+1 "Sphingopyxis alaskensis RB2256" *.fa >> Sphingopyxis alaskensis RB2256.fa
But I will need to do it 722 times to get my sequences sorted according to species.
Is grep in for loops can be used to simplify the work? Or there are alternative methods to do so?
The Fasta format doesn't require that all sequences be on a single line. In fact, that isn't even common, since most biological sequences are long. So your grep will fail in any cases where there's more than one line of sequence for the ID. Also, your grep command will create a file called Sphingopyxis and not a file called Sphingopyxis alaskensis RB2256.fa.
Sphingopyxis
In any case, you can do something like this to get each sequence into a file names after the species:
awk -F'[][]' '/>/{n=$2}; {print >> n".fa"}' *.fa
However, I strongly urge you not to use spaces in your file names since that will only make your life harder. A safer approach would be:
awk -F'[][]' '/>/{n=$2; gsub(/ /,"_",n)}; {print >> n".fa"}' *.fa
The gsub replaces all spaces in the species name with _, resulting in these files:
gsub
_
Leptospirillum_ferriphilum_ML-04.fa Sphingopyxis_alaskensis_RB2256.fa
Note that both approaches above can deal with multi-line sequences.
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 9 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.