Skip to content

Instantly share code, notes, and snippets.

@ShujiaHuang
Created May 14, 2016 12:47
Show Gist options
  • Save ShujiaHuang/c96a2390ceca78bf6ed38d6b7e483f60 to your computer and use it in GitHub Desktop.
Save ShujiaHuang/c96a2390ceca78bf6ed38d6b7e483f60 to your computer and use it in GitHub Desktop.
Fasta 读写
### 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