This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How To Modify Contig Format:

Hi everyone I need co change a contig file format : can any one help me out using awk or perl

Input file:

>NODE_411_length_76_cov_325.381_ID_5152754
AAGAAGCAAATAtAAACAGCATTAAAGATATACACATAAAAATGAAGTACTAAA
>NODE_412_length_75_cov_54.1_ID_5146650
CCCTAAATTGAGAAAATAACTTTAGGGAATATATCAATGTACAGTGCCCGCTTCGTTAT
>NODE_413_length_74_cov_63.8947_ID_373286
GTATTGATCCAAAATCGGTGTAAATATTACCCTTTTTAGGTGTATTAGGTGTTAAATGTA

Out put should be like :

>Contig0.1
AAGAAGCAAATtAtAAACtAGCATTAAAGATATACACATAAAAATGAAGTACTAAA    
>Contig0.2
CCCTAAATTGAGAAAAaTAACTTTAGGGAATATATCAATGTACAGTGCCCGCTTCGTTAT
>Contig0.3
GTATTGATCCAAAATCGGTGTAAATATTACCCTTTTTAGGTGTATTAGGTGTTAAATGTA

Thank you advance .

perl awk fasta

Your output format is awkward, why would you want that? It's not even fasta format because of the extra whitespace before >. What do you need the extra line break for? Please be more specific about what you want to change, as your examples do not match each other.

Do you just need the names ("NODE_411...", etc.) changed or is something supposed to be done with the sequences as well? How are we to know what bases should be made lower case or is that already done? I have a feeling that you don't actually know what you would like to do (you're certainly not providing enough information for anyone to help you).

Hello, i have modify the above question please have a look.

2 answers

Given the update:

awk 'BEGIN{i=1; OFS=""}{if(substr($0,1,1) == ">") { print ">Contig0.",i; i+=1}else{print $0}}' foo.fa

Thank you so much . Its working fine.

Another awk option:

awk '{/^>/ && sub(/>.+/,">Contig0."++i); print}' foo.fa

Nice, that's rather more concise than mine!

With Perl:

perl -lne 's/^>.+/">Contig0.".++$i/e;print' foo.fa

Log in to answer this question.