3
|
1 #!/usr/bin/perl
|
|
2
|
|
3 #---
|
|
4 # Initialize parameters
|
|
5 #---
|
|
6 $sampleStart = $ARGV[0];
|
|
7 $sampleEnd = $ARGV[1];
|
|
8 if(( $ARGV[0] eq '' ) || ($ARGV[1] eq '')) { die "Usage: fastaSample sampleStart sampleEnd\n"; }
|
|
9
|
|
10 $sampleStart--;
|
|
11 $sampleEnd--;
|
|
12 $sampleLen = $sampleEnd - $sampleStart + 1;
|
|
13
|
|
14 #---
|
|
15 # Read fasta file
|
|
16 #---
|
|
17 for($lineNum=0 ; $l = <STDIN> ; $lineNum++ ) {
|
|
18 if( $l =~/^>/ ) {
|
|
19 # Sample if not empty
|
|
20 if( $seq ne "" ) {
|
|
21 $s = substr( $seq, $sampleStart, $sampleLen);
|
|
22 print "$s\n";
|
|
23 }
|
|
24 # New sequence
|
|
25 $seq = "";
|
|
26 } else {
|
|
27 chomp($l);
|
|
28 $seq .= $l;
|
|
29 }
|
|
30 }
|
|
31
|
|
32 # Sample if not empty
|
|
33 if( $seq ne "" ) {
|
|
34 $s = substr( $seq, $sampleStart, $sampleLen);
|
|
35 print "$s\n";
|
|
36 }
|
|
37
|
|
38 $len = length($seq);
|
|
39 print STDERR "Lines: $lineNum\n";
|
|
40 print STDERR "Sequence size: $len\n";
|
|
41 print STDERR "Sample size: $sampleLen\n";
|