到目前为止,我已经设法对 Perl 有了更多的了解,这是一种解脱,我要感谢你们。我目前仍在研究另一个方面,我需要读取 .fasta 文件并找到所有 G 和 C 核苷酸,然后创建一个制表符分隔的文件。
这些是我过去几天的帖子,按时间顺序排列:
- 如何从制表符分隔的数据中平均列值... (已解决)
- 为什么我在输出文件中看不到计算结果? (解决了)
- 使用 .fasta 文件计算序列的相对内容
- 读取 .fasta 序列以提取核苷酸数据,然后... (在此之前发布)
最后一个查询仍在处理中,但我已经取得了一些进展。
在某些背景下,.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,然后将各自的计数制成表格。