in reply to Command or Perl script for changing headers of multiple FASTA files in a specific order listed in a txt file

Hi, What have you tried, and how did it not work for you?

Also, please edit your post to use <code></code> tags, as shown in the instruction directly below the Preview button. (Gonna be hard to be a programmer if you don't read the instructions.)

Update: Hm, I missed that you posted anonymously and cannot therefore edit your post. (Thanks hippo.) Better to create a user account, in order to be able to update a post, and for other reasons...)


The way forward always starts with a minimal test.
  • Comment on Re: Command or Perl script for changing headers of multiple FASTA files in a specific order listed in a txt file
  • Download Code

Replies are listed 'Best First'.
Re^2: Command or Perl script for changing headers of multiple FASTA files in a specific order listed in a txt file
by Anonymous Monk on Sep 11, 2017 at 11:45 UTC

    well i have tried the following code:

    i put the following function in linux enviroment: and(i guess problem is here but unbable to fix it )

    function sedinho () { sed -i "s/^.*\]/>$1/g" $2;} export -f sedinho

    create variables of : list of new headers (LIST1) list of input files (LIST2)

    LIST1=($(cat Headers.txt)) LIST2=($(find /folder/with/fasta/files/ -maxdepth 0 -name "*CDS.fasta" + | sort)) parallel --xapply sedinho {1} {2} ::: ${LIST1[@]} ::: ${LIST2[@]}

    ERROR:

    zsh:1: command not found: sedinho

    zsh:1: command not found: sedinho

    zsh:1: command not found: sedinho

    how to put a function in linux environment accurately ??

      This Perl script does the first part reading the filenames and headers into an array using File::Find. How is the order of the lines in Header.txt matched to these filenames/headers ?

      #!/usr/bin/perl use strict; use File::Find; use Data::Dumper; my $folder = '/folder/with/fasta/files'; my @files=(); find( \&process, $folder ); print Dumper \@files; sub process { return unless $_ =~ /CDS\.fasta$/; my $file = $File::Find::name; open my $fh,'<',$file or die $!; my $header = <$fh>; close $fh; push @files,[$File::Find::dir,$_,$header]; }
      poj

        The mapping of names in Headers.txt and the FASTA files can work.

        Chimpanzee_AMY2B_CDS.fasta MP.C_AMY2B Human_AMY2B_CDS.fasta FP.H_AMY2B
        Following solution worked for my problem.

        create a folder called test (in the same folder where fasta files are located) and run the command:

        $ mkdir test

        execute:

         for i in $(seq 1 $(ls *.fasta |wc -l)); do sed -n "$i"p headers.txt| sed 's/^/>/'> test/$(ls *.fasta| sed -n "$i"p); cat $(ls *.fasta| sed -n "$i"p)| sed '1d' >>test/$(ls *.fasta| sed -n "$i"p); done

        Cheers.. :)