File: splitDelimitedFasta.pl

package info (click to toggle)
rtax 0.984-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 224 kB
  • sloc: perl: 1,123; sh: 203; makefile: 2
file content (46 lines) | stat: -rwxr-xr-x 806 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env perl

use strict;
use warnings;

# make sure delimiter is properly escaped, e.g. for "+" we need "\+".
my $delimiter = $ARGV[0];
my $infile = $ARGV[1];

my $infilename = `basename $infile`;
chomp $infilename;

open(IN, $infile) or die "Can't read $infile\n";
open(A,">$infilename.a") or die "Can't write $infilename.a\n";
open(B,">$infilename.b") or die "Can't write $infilename.b\n";

my $fastaHeader = "";
my $outfile = *A;
	
while(<IN>)
	{
	chomp;
	if(/^>/)
		{
		$outfile = *A;
		$fastaHeader = $_;
		print A "$fastaHeader\n";
		print B "$fastaHeader\n";
		}
	else
		{
		if ( /(.*)$delimiter(.*)/)
		    {
		        print A "$1\n";
		        print B "$2\n";
		        $outfile = *B;
	        }
		else
		    {
		        print $outfile "$_\n";
	        }
		}
	}
close IN;
close A;
close B;