Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to append two fasta files? Post 303035986 by yifangt on Tuesday 11th of June 2019 02:32:15 PM
Old 06-11-2019
combine and upgrade by the second fasta file

I put my answer back as I met the scenarios:
1) when file2.fasta contains more entries than in file1.fasta and vice versa. and
2) when the sequence part can have more than one row;
Code:
awk 'BEGIN{RS=">";FS="\n"} {A[$1]=$2} END{for (i in A) {if (i) print ">"i,FS,A[i]}}' file1.fasta file2.fasta

This only works for 2-line fasta sequence files (i.e. each entry has two lines, One starts with ">" as the header, the other is the DNA sequence. @vgersh99, could you please elaborate your code for scenario 2)? Thanks!
Code:
file1.fasta
>Contig_1:90600-91187
GACCGTCATCAATTCCTGTTCCTTGCCCTTGACGACCTCATCCACGTCCTTGATGGCCTT 
>Contig_24:26615-28387
TTCGCCGCGCTCCAAACGGGCGATCTCCTCGGCGCGGGCCGCCAGGATCAGCGCCG
>Contig_98:35323-35886
GACGAAGCGCTCGCCAAGGCCGAAGAAGAAGGCCTGGATCTGGTCGAAATCCAGCCGCAG               
AAGGCCATCAAGGACGTGGATGAGGTCGTCAAGGGCAAGGA

file2.fasta:
>Contig_1:90600-91187 
AAGGCCATCAAGGACGTGGATGAGGTCGTCAAGGGCAAGGAACAGGAATTGATGACGGTC
AAGGCCATCAAGGACGTGGATGAGGTCGTCAAGGGCAAGGAACAGG
AAGGCCATCAAGGACGTGGATGAGGTCGTCAAGGGCAAGGA
>Contig_24:26615-28387
GCTGCGGCGCTGATCCTGGCGGCCCGCGCCGAGGAGATCGCCCGTTTGGAGCGCGGCGAA

output:
>Contig_1:90600-91187 
AAGGCCATCAAGGACGTGGATGAGGTCGTCAAGGGCAAGGAACAGGAATTGATGACGGTC
AAGGCCATCAAGGACGTGGATGAGGTCGTCAAGGGCAAGGAACAGG
AAGGCCATCAAGGACGTGGATGAGGTCGTCAAGGGCAAGGA
>Contig_24:26615-28387
GCTGCGGCGCTGATCCTGGCGGCCCGCGCCGAGGAGATCGCCCGTTTGGAGCGCGGCGAA
>Contig_98:35323-35886
GACGAAGCGCTCGCCAAGGCCGAAGAAGAAGGCCTGGATCTGGTCGAAATCCAGCCGCAG               
AAGGCCATCAAGGACGTGGATGAGGTCGTCAAGGGCAAGGA

This User Gave Thanks to yifangt For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

append two files

Hi, I have two files where 1 contains data and the other contains strings eg file 1 -0.00000 0.00000 0.00000 0.00000 0.00000 0.80000 0.50000 0.50000 0.60000 0.50000 0.50000 0.20000 -0.00000 0.00000 0.40000 file 2 F F F F F F T T T T T T T T T How to I append file2 to file 1 to... (1 Reply)
Discussion started by: princessotes
1 Replies

2. UNIX for Dummies Questions & Answers

grep FASTA files

I would like to extract the sequences larger than 10 bases but shorter than 18 along with the identifier from a FASTA file that looks like this: > Seq I ACGACTAGACGATAGACGATAGA > Seq 2 ACGATGACGTAGCAGT > Seq 3 ACGATACGAT I know I can extract the IDs alone with the following code grep... (3 Replies)
Discussion started by: Xterra
3 Replies

3. UNIX for Dummies Questions & Answers

renaming (renumbering) fasta files

I have a fasta file that looks like this: >Noname ACCAAAATAATTCATGATATACTCAGATCCATCTGAGGGTTTCACCACTTGTAGAGCTAT CAGAAGAATGTCAATCAACTGTCCGAGAAAAAAGAATCCCAGG >Noname ACTATAAACCCTATTTCTCTTTCTAAAAATTGAAATATTAAAGAAACTAGCACTAGCCTG ACCTTTAGCCAGACTTCTCACTCTTAATGCTGCGGACAAACAGA ... I want to... (2 Replies)
Discussion started by: Oyster
2 Replies

4. Shell Programming and Scripting

append to two files

I tried to write a script ( not working) to append first value from mylist to a file called my myfirstResult and to another called mysecondResult awk ' {print $1} >> myfirsResult ' < mylist awk ' {print $1} >> mysecondResult ' < mylist $ cat mylist A 02/16/2012 B 02/19/2012 C... (3 Replies)
Discussion started by: Sara_84
3 Replies

5. UNIX for Dummies Questions & Answers

Breaking a fasta formatted file into multiple files containing each gene separately

Hey, I've been trying to break a massive fasta formatted file into files containing each gene separately. Could anyone help me? I've tried to use the following code but i've recieved errors every time: for i in *.rtf.out do awk '/^>/{f=++d".fasta"} {print > $i.out}' $i done (1 Reply)
Discussion started by: Ann Mc Cartney
1 Replies

6. UNIX for Dummies Questions & Answers

Append Files

Hi All, I have to append 2 lines at the end of a text file. If those 2 lines are already there then do not append else append the 2 lines to the text file. Eg: I have a text file, file.txt This text file might look like this, /home/kp/make.jsp /home/pk/model.jsp I have to append... (1 Reply)
Discussion started by: pavan_test
1 Replies

7. UNIX for Dummies Questions & Answers

Append file name to fasta file headers in Linux

How do we append the file name to fasta file headers in multiple fasta-files in Linux? (10 Replies)
Discussion started by: Mauve
10 Replies

8. Shell Programming and Scripting

Unzip all the files with subdirectories present and append a part of string from the main .zip files

Hi frnds, My requirement is I have a zip file with name say eg: test_ABC_UH_ccde2a_awdeaea_20150422.zip within that there are subdirectories on each directory we again have .zip files and in that we have files like mama20150422.gz and so on. Iam in need of a bash script so that it unzips... (0 Replies)
Discussion started by: Ravi Kishore
0 Replies

9. Shell Programming and Scripting

Append string to all the files inside a directory excluding subdirectories and .zip files

Hii, Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories. Eg. file1: test1.log file2: test2.log file3 test.zip After running the script file1: string_test1.log file2: string_test2.log file3:... (4 Replies)
Discussion started by: Ravi Kishore
4 Replies

10. Shell Programming and Scripting

Help with reformat single-line multi-fasta into multi-line multi-fasta

Input File: >Seq1 ASDADAFASFASFADGSDGFSDFSDFSDFSDFSDFSDFSDFSDFSDFSDFSD >Seq2 SDASDAQEQWEQeqAdfaasd >Seq3 ASDSALGHIUDFJANCAGPATHLACJHPAUTYNJKG ...... Desired Output File >Seq1 ASDADAFASF ASFADGSDGF SDFSDFSDFS DFSDFSDFSD FSDFSDFSDF SD >Seq2 (4 Replies)
Discussion started by: patrick87
4 Replies
BP_BULK_LOAD_GFF(1p)					User Contributed Perl Documentation				      BP_BULK_LOAD_GFF(1p)

NAME
bulk_load_gff.pl - Bulk-load a Bio::DB::GFF database from GFF files. SYNOPSIS
% bulk_load_gff.pl -d testdb dna1.fa dna2.fa features1.gff features2.gff ... DESCRIPTION
This script loads a Bio::DB::GFF database with the features contained in a list of GFF files and/or FASTA sequence files. You must use the exact variant of GFF described in Bio::DB::GFF. Various command-line options allow you to control which database to load and whether to allow an existing database to be overwritten. This script differs from bp_load_gff.pl in that it is hard-coded to use MySQL and cannot perform incremental loads. See bp_load_gff.pl for an incremental loader that works with all databases supported by Bio::DB::GFF, and bp_fast_load_gff.pl for a MySQL loader that supports fast incremental loads. NOTES If the filename is given as "-" then the input is taken from standard input. Compressed files (.gz, .Z, .bz2) are automatically uncompressed. FASTA format files are distinguished from GFF files by their filename extensions. Files ending in .fa, .fasta, .fast, .seq, .dna and their uppercase variants are treated as FASTA files. Everything else is treated as a GFF file. If you wish to load -fasta files from STDIN, then use the -f command-line swith with an argument of '-', as in gunzip my_data.fa.gz | bp_fast_load_gff.pl -d test -f - The nature of the bulk load requires that the database be on the local machine and that the indicated user have the "file" privilege to load the tables and have enough room in /usr/tmp (or whatever is specified by the $TMPDIR environment variable), to hold the tables transiently. Local data may now be uploaded to a remote server via the --local option with the database host specified in the dsn, e.g. dbi:mysql:test:db_host The adaptor used is dbi::mysqlopt. There is currently no way to change this. About maxfeature: the default value is 100,000,000 bases. If you have features that are close to or greater that 100Mb in length, then the value of maxfeature should be increased to 1,000,000,000. This value must be a power of 10. Note that Windows users must use the --create option. If the list of GFF or fasta files exceeds the kernel limit for the maximum number of command-line arguments, use the --long_list /path/to/files option. COMMAND-LINE OPTIONS Command-line options can be abbreviated to single-letter options. e.g. -d instead of --database. --database <dsn> Database name (default dbi:mysql:test) --adaptor Adaptor name (default mysql) --create Reinitialize/create data tables without asking --user Username to log in as --fasta File or directory containing fasta files to load --long_list Directory containing a very large number of GFF and/or FASTA files --password Password to use for authentication (Does not work with Postgres, password must be supplied interactively or be left empty for ident authentication) --maxbin Set the value of the maximum bin size --local Flag to indicate that the data source is local --maxfeature Set the value of the maximum feature size (power of 10) --group A list of one or more tag names (comma or space separated) to be used for grouping in the 9th column. --gff3_munge Activate GFF3 name munging (see Bio::DB::GFF) --summary Generate summary statistics for drawing coverage histograms. This can be run on a previously loaded database or during the load. --Temporary Location of a writable scratch directory SEE ALSO
Bio::DB::GFF, fast_load_gff.pl, load_gff.pl AUTHOR
Lincoln Stein, lstein@cshl.org Copyright (c) 2002 Cold Spring Harbor Laboratory This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See DISCLAIMER.txt for disclaimers of warranty. perl v5.14.2 2012-03-02 BP_BULK_LOAD_GFF(1p)
All times are GMT -4. The time now is 08:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy