Created
May 14, 2016 12:47
-
-
Save ShujiaHuang/7106659a1781acd9010d1984e4ff0d42 to your computer and use it in GitHub Desktop.
Fasta 读写
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Read Fa sequence ### | |
sub ReadFaSeq { | |
my ( $file, $fa ) = @_; | |
my ( $refId, $seq ); | |
open I, $file or die "Cannot open file : $file\n"; | |
$/ = ">"; <I>; $/ = "\n"; | |
while ( <I> ) { | |
chomp; | |
$refId = ( split /\s+/ )[0]; | |
$/ = ">"; chomp( $seq = <I> ); $/ = "\n"; | |
$seq =~ s/\s+//g; | |
$$fa{$refId} = $seq; | |
} | |
close I; | |
} | |
### Output Fa Sequence #### | |
sub OutputFa { | |
my ( $id, $lineLength, $seq ) = @_; | |
my $i= 0; | |
print "$id\n"; | |
for (; $i < length( $$seq ); $i += $lineLength ) { | |
print substr($$seq, $i, $lineLength ); | |
print "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment