Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Renaming fasta headers - string within a string issue

    Hi Everyone,

    I am in the midst of renaming some fasta headers to include the chromosomes they have been mapped to (from a tab delimited txt file). I don't have any problems setting up the hash for the scaffold and chromosome locations...the problem is that I have some short strings contained in longer strings (scaffold1 and scaffold10 and scaffold100). Usually I would add "$" to the end of my search term (/scaffold1$/) and thereby indicate the end of the search string, but I'm not sure how to make use of this when the search term is a variable ($hash{$scaff/$/}). Advice?

    Below is my script so far...and TIA!

    Code:
    #!/bin/bash/perl
    #mod-header2include-chrom.pl
    #This script is intended to read in a fasta file and a tab-delimited file and use the information from the tab-delimited file to modify the header.
    #In this case, we are appending to the header (e.g. "scaffold671") the chromosome to which it has been mapped and the number of genes on this scaffold.
    
    use strict;
    use warnings;
    
    open (DATA, "<genome-assoc-chromosomes.txt") or die "Could not open genome chromosome mapping data: $!\n";
    open (FASTA, "<scafSeq.FG.fill") or die "Could not open Fasta file: $!\n";
    
    my %hash;
    
    while (<DATA>)
    {
    chomp;
    if ($_ =~ "scafold"){ #skip header - scafold is spelled incorrectly on purpose;
    next;
    }
    else {
    my ($key, $chrom, $len, $gene) = split /\t/;
    $hash{$key} = $chrom;
    }
    }
    
    while (<FASTA>){
    
    my $line = $_;
    chomp ($line);
    if ( defined $hash{$line} ) {
    print "$line-$hash{$line}";
    }
    else { print $line; }
    
    }

  • #2
    Hi,
    Kindly upload a sample of both files (scafSeq.FG.fill and genome-assoc-chromosomes.txt). Without the fasta file, I am wondering how the following:
    while (<FASTA>){
    my $line = $_;
    chomp ($line);
    if ( defined $hash{$line} ) {


    reads in the header line with ">" from "<scafSeq.FG.fill"

    does the variable $key in "$hash{$key} = $chrom;" contain ">"?

    Comment

    Latest Articles

    Collapse

    • seqadmin
      Current Approaches to Protein Sequencing
      by seqadmin


      Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
      04-04-2024, 04:25 PM
    • seqadmin
      Strategies for Sequencing Challenging Samples
      by seqadmin


      Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
      03-22-2024, 06:39 AM

    ad_right_rmr

    Collapse

    News

    Collapse

    Topics Statistics Last Post
    Started by seqadmin, 04-11-2024, 12:08 PM
    0 responses
    17 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-10-2024, 10:19 PM
    0 responses
    22 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-10-2024, 09:21 AM
    0 responses
    16 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-04-2024, 09:00 AM
    0 responses
    46 views
    0 likes
    Last Post seqadmin  
    Working...
    X