Edit the Fastq headers
1
0
Entering edit mode
5 weeks ago
KSmarty • 0

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!

headers Perl Fastq • 360 views
ADD COMMENT
0
Entering edit mode
5 weeks ago
JC 12k

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;
ADD COMMENT
0
Entering edit mode

Thank you for the suggestion!

ADD REPLY

Login before adding your answer.

Traffic: 2334 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6