in Education by
I am trying to replace all characters that are not C, T, A or G with an N in the sequence part of a fasta file - i.e. every 2nd line I think some combination of awk and tr is what I would need... To print every other line: awk '{if (NR % 2 == 0) print $0}' myfile To replace these characters with an N tr YRHIQ- N ...but I don't know how to combine them so that the character replacement is only on every 2nd line but it prints every line this is the sort of thing I have >SEQUENCE_1 AGCYGTQA-TGCTG >SEQUENCE_2 AGGYGTQA-TGCTC and I want it to look like this: >SEQUENCE_1 AGCNGTNANTGCTG >SEQUENCE_2 AGGNGTNANTGCTC but not like this: >SENUENCE_1 AGCNGTNANTGCTG >SENUENCE_2 AGGNGTNANTGCTC JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The question you have is easy to answer but will not help you when you handle generic fasta files. Fasta files have a sequence header followed by one or multiple lines which can be concatenated to represent the sequence. The Fasta file-format roughly obeys the following rules: The description line (defline) or header/identifier line, which begins with character (>), gives a name and/or a unique identifier for the sequence, and may also contain additional information. Following the description line is the actual sequence itself in a standard one-letter character string. Anything other than a valid character would be ignored (including spaces, tabulators, asterisks, etc...). The sequence can span multiple lines. A multiple sequence FASTA format would be obtained by concatenating several single sequence FASTA files in a common file, generally by leaving an empty line in between two subsequent sequences. To answer the OP's question, If you just want to process every second line, you want to do: awk '!(NR%2){gsub(/[^CTAG]/, "N")}1' file.fasta This method will, however, fail on any of the following cases: fasta file with a multi-line sequence multi-fasta file with a possible blank-line between subsequent sequences A better way would be to exclude the header line and process all other lines: awk '!/^>/{gsub(/[^CTAG]/, "N")}1' file.fasta

Related questions

0 votes
    I want to truncate a string in Smarty This is the scenario: The string is "Test!abc". Maximum ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    Every circuit is a network, but all networks are not circuits. (a) True (b) False I have been asked this ... for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 20, 2021 in Education by JackTerrance
0 votes
    Every circuit is a network, but all networks are not circuits. (a) True (b) False I have been asked this ... in division Circuit Elements and Kirchhoff's Laws of Network Theory...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    Today I found out that putting strings in a resource file will cause them to be treated as literals, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Today I found out that putting strings in a resource file will cause them to be treated as literals, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Today I found out that putting strings in a resource file will cause them to be treated as literals, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I have a REACTSjs application and am trying to solve a problem with localization. I receive some text from ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    recently i'm working on some project with arm but no OS in it. Now when i compile it, i must ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I have some website which requires a logon and shows sensitive information. The person goes to the page, is ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    Say I have input like {"DESCRIPTION": "Need to run script to do stuff", "PRIORITY": "Medium"} ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    Say I have input like {"DESCRIPTION": "Need to run script to do stuff", "PRIORITY": "Medium"} ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Say I have input like {"DESCRIPTION": "Need to run script to do stuff", "PRIORITY": "Medium"} ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Which design pattern suggests multiple classes through which request is passed and multiple but only relevant classes carry ... of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    State the appropriate concept for the given statement: Cases can be heard for the first time only in certain courts. Please answer the above question....
asked Aug 4, 2022 in Education by JackTerrance
...