PhD Student

PhD Student

1

Hello,
Im 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


edit


Fastq


Perl

• 64 views

updated 11 minutes ago by

12k

written 2 hours ago by

0

you mean something like this:

#!/usr/bin/perl

use strict; 
use warnings;

open DIR, "/path/to/dir/" or die "cannot read directoryn";
while (my $file = readdir DIR) {
    if ($file =~ /Rund+_(BCd+--BCd+).fastq/) {
        my $barcode = $1;
        my $new_file = $file;
        $new_file =~ s/.fastq/_edit.fastq/;
        warn "ediiting $file with barcode $barcode in $new_filen";
        open (my $in, "<", $file) or die "cannot read $filen");
        open (my $out, ">", $new_file) or die "cannot write $new_filen";
        while (<$in>) {
            s/^@/@Barcode$barcode_/;
            print $out $_;
        }
        close $in;
        close $out;
    }
}
closedir DIR;

11 minutes ago by


JC

12k


Login
before adding your answer.

Traffic: 2438 users visited in the last hour

Read more here: Source link