【发布时间】:2012-04-02 23:36:33
【问题描述】:
到目前为止,我已经设法对 Perl 有了更多的了解,这让我松了一口气,我要感谢你们。我目前仍在研究另一个方面,我需要读取 .fasta 文件并找到所有 G 和 C 核苷酸,然后创建一个制表符分隔的文件。
这些是我过去几天的帖子,按时间顺序排列:
- How do I average column values from a tab-separated data... (已解决)
- Why do I see no computed results in my output file? (已解决)
- Using a .fasta file to compute relative content of sequences
- Reading .fasta sequences to extract nucleotide data, and then... (在此之前发布)
最后一个查询仍在处理中,但我已经取得了一些进展。
一些背景,.fasta 文件的内容如下:
>label
sequence
>label
sequence
>label
sequence
我不确定如何打开 .fasta 文件,所以我不确定哪些标签适用于哪个,但我知道基因应该标记为 gag、pol 或 env。我是否需要打开 .fasta 文件才能知道我在做什么,或者我可以通过上述格式“盲目”地做吗?
反正我现在的代码如下:
#!/usr/bin/perl -w
# This script reads several sequences and computes the relative content of G+C of each sequence.
use strict;
my $infile = "Lab1_seq.fasta"; # This is the file path
open INFILE, $infile or die "Can't open $infile: $!"; # This opens file, but if file isn't there it mentions this will not open
my $outfile = "Lab1_SeqOutput.txt"; # This is the file's output
open OUTFILE, ">$outfile" or die "Cannot open $outfile: $!"; # This opens the output file, otherwise it mentions this will not open
my $sequence = (); # This sequence variable stores the sequences from the .fasta file
my $GC = 0; # This variable checks for G + C content
my $line; # This reads the input file one-line-at-a-time
while ($line = <INFILE>) {
chomp $line; # This removes "\n" at the end of each line (this is invisible)
if($line =~ /^\s*$/) { # This finds lines with whitespaces from the beginning to the ending of the sequence. Removes blank line.
next;
} elsif($line =~ qr(^\s*\#/)) { # This finds lines with spaces before the hash character. Removes .fasta comment
next;
} elsif($line =~ /^>/) { # This finds lines with the '>' symbol at beginning of label. Removes .fasta label
next;
} else {
$sequence = $line;
}
$sequence =~ s/\s//g; # Whitespace characters are removed
print OUTFILE $sequence;
}
代码现在将整个序列打印到文本文件中,没有空格。唯一的问题是,我不知道序列从哪里开始或结束,所以我不确定哪些序列适用于每个基因。虽然停止/开始密码子应该给我一个指示。考虑到这一点,我将如何修改/添加到代码中以计算序列中 G+C 的数量,然后将它们打印到一个制表符分隔的文件中,其中包含与它们各自的 G/C 内容相关的基因名称?
我期待听到有人可以提供一些指导,与上面发布的代码类似,关于如何找到 G/C,然后将各个计数制成表格。
【问题讨论】:
标签: perl tabs bioinformatics fasta