【发布时间】:2016-01-08 01:13:08
【问题描述】:
这是本网站上my very first question 的扩展。
现在我有以下代码:
#!/usr/bin/perl
use strict;
use warnings;
#Print Directory
print "Please provide the directory containing the FASTQ files from your Illumina MiSeq run \n";
my $FASTQ = <STDIN>;
chomp ($FASTQ);
print "Please provide the minimum overlap between the two reads in bp";
my $min = <STDIN>;
chomp ($min);
print "Please provide the maximum overlap between the two reads in bp";
my $max = <STDIN>;
chomp ($max);
print "Now provide the output directory for your merged fastq reads";
my $output = <STDIN>;
chomp ($output);
#Open Directory
my $dir = $FASTQ;
opendir(DIR, $dir) or die "Cannot open $dir: $!";
my @reads = grep { /.fastq/ } readdir DIR;
closedir DIR;
sub parse_fastq_filename {
# Strip the suffix
my $filename = shift;
# Parse Sample-ID_Adapter-Sequence_L001_R1_001
my($sample_id, $adapter_sequence, $L001, $format, $001) = split /_/, $filename;
return {
filename => $filename,
sample_id => $sample_id,
adapter_sequence => $adapter_sequence,
$L001 => $L001,
format => $format,
001 => $001
};
}
# The pairs of files will be stored within the following hash.
my %pairs;
# List just the *.fastq files
for my $filename (@reads) {
# Parse the filename into a hash reference
my $fastq = parse_fastq_filename($filename);
# Put each parsed fastq filename into its pair
$pairs{ $fastq->{sample_id} }{ $fastq->{format} } = $fastq;
}
for my $sample (values %pairs) {
# Go through each pair in the sample
for my $fastq (values %$sample) {
print "$fastq->{filename} has format $fastq->{format}\n";
}
}
for my $forward (values %pairs) {
for my $fastq (values %$forward) {
}
}
#print the keys within the hash
foreach (keys %pairs){
print "$_ => $pairs{$_}\n";
}
#place the hash into an array
my @unique = keys %pairs;
print @unique;
#change directory to the user-inputted directory and merge reads
chdir $dir;
`/usr/local/flash/flash @array[0] @array[1] -m $min -M $max -d $output`;
我成功地将正向和反向 fastq 文件按照 Unix 命令末尾的要求相互配对。现在我被困在如何相互调用对的各个组件。
我考虑过通过键入其键作为用户输入来访问哈希,但这些数字是在脚本中随机生成的,我不想强迫用户在运行 Unix 脚本之前输入这些值。
另外,我检查过的所有示例都已经在哈希中提供了固定数量的键。根据用户想要合并的文件数量,散列中的键数量也会有所不同。
我知道我想创建一个循环,以便命令可以多次运行;程序FLASH一次只能接受一个正向和反向fastq文件。因此,正向和反向 fastq 读取必须循环,以便处理每个读取。
在将它们配对成哈希后,如何取出要使用的特定文件?
【问题讨论】:
-
每个问题都应该独立存在——您真的不应该依赖前一个问题的内容来为您填写详细信息。这个问题真的很难理解,但是我认为你想提取每个样本id对应两种格式的两个文件的名称。那正确吗?格式是否总是
R1和R2? -
“现在我被困在如何相互调用配对的各个组件上。”您能否通过一个示例来说明此要求,以显示您到底想做什么? “我考虑过通过键入其键作为用户输入来访问散列”。我认为这也需要一些澄清。听起来您可以为此使用“keys %pairs”。
-
@Borodin 每对都有一个正向和反向读取,分别由 R1 和 R2 组件区分。所以每个文件都被格式化为 sample-id_adapter-sequence_L001_R1/R2_001.fastq/ Ramana 现在,我已经有了脚本,它可以相互解析正向和反向读取。但是它们被困在散列中的单个键中。因此,如果我在哈希中有一个样本 ID 为“11215”的键,那么该键将同时包含 R1 和 R2 文件。
标签: perl hash bioinformatics