-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixFasta.pl
executable file
·45 lines (40 loc) · 1007 Bytes
/
fixFasta.pl
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
#!/usr/bin/perl -w
#
# fixFasta.pl
#
# Fix fasta files so that each sequence is on one line
#
# September 12, 2013
#
# RUN THIS SCRIPT IN THE DIRECTORY WITH THE FILES!!!!!
# By Liz Cooper
use strict;
# Get the input files from the current directory
my @files = glob("*filtered.cap.singlets");
# For each file, fix the reads and output to a new file
foreach my $file (@files) {
my @name = split(/\./, $file);
my $prefix = $name[0];
$prefix =~ s/filtered/fixed/;
my $output = $prefix . "." . "fasta";
open (OUT, ">$output") || die "\nUnable to open the file $output!\n";
open (IN, $file) || die "\nUnable to open the file $file!\n";
my $sequence = '';
# Start reading through the input file
while (<IN>) {
chomp $_;
if ($_ =~ /^>/) {
unless ((length($sequence)) == 0) {
print OUT $sequence, "\n";
}
print OUT $_, "\n";
$sequence = '';
} else {
$sequence .= $_;
}
}
print OUT $sequence, "\n";
close(IN);
close(OUT);
}
exit;