Thank you for the suggestion!
• 0 views
•
link
Hello,
I'm using a tool that produces for every barcode's name a fastq file where every fastq file name contains the barcode number. I need to add the barcode number to all headers depending on their suitable barcodes. I used this command bellow but I need to apply this for all fastq and integrate it in my perl script:
perl -pe '$i = $i ? 0 : 1; s/^@/\@BarcodeBC001--BC001_/ if $i' Run00213_BC001--BC001.fastq > Run00213_BC001--BC001_edit.fastq
With this command I could change the headers in all fastq files but i have to apply it one by one.
I need help if someone has an idea I would appreciate that.
Thank you in advance!
you mean something like this:
#!/usr/bin/perl
use strict;
use warnings;
open DIR, "/path/to/dir/" or die "cannot read directory\n";
while (my $file = readdir DIR) {
if ($file =~ /Run\d+_(BC\d+--BC\d+).fastq/) {
my $barcode = $1;
my $new_file = $file;
$new_file =~ s/\.fastq/_edit.fastq/;
warn "ediiting $file with barcode $barcode in $new_file\n";
open (my $in, "<", $file) or die "cannot read $file\n");
open (my $out, ">", $new_file) or die "cannot write $new_file\n";
while (<$in>) {
s/^@/\@Barcode$barcode\_/;
print $out $_;
}
close $in;
close $out;
}
}
closedir DIR;
Thank you for the suggestion!
Log in to answer this question.