Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7574341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:24:46+00:00 2026-05-30T16:24:46+00:00

I am working on some genome data and I have 2 files -> File1

  • 0

I am working on some genome data and I have 2 files ->

File1

A1 1   10
A1  15  20
A2  2   11
A2  13  16

File2

>A1
CTATTATTTATCGCACCTACGTTCAATATTACAGGCGAACATACCTACTA
AAGTGTGTTAATTAATTAATGCTTGTAGGACATAATAATAACAATTGAAT
>A2
GTCTGCACAGCCGCTTTCCACACAGACATCATAACAAAAAATTTCCACCA
AACCCCCCCCTCCCCCCGCTTCTGGCCACAGCACTTAAACACATCTCTGC
CAAACCCCAAAAACAAAGAACCCTAACACCAGCCTAACCAGATTTCAAAT

In file 1, 2nd and 3rd column represents the indexes in File2. So I want that, if character in column1 of file1 matches with character followed by symbol (>) in file2 , then from next line of that file2 give back the substring according to indexes in col2 and col3 of file1. (sorry, I know its complicated) Here is the desire output ->

Output

>A1#1:10
CTATTATTTA
>A1#15:20
ACCTA
>A2#2:11
TCTGCACAGC
>A2#13:16
GCTT

I know if I have only 1 string I can take out sub-string very easily ->

@ARGV or die "No input file specified";
open $first, '<',$ARGV[0] or die "Unable to open input file: $!";
$string="GATCACAGGTCTATCACCCTATTAACCACTCACGGGAGCTCTCCATGCAT";
while (<$first>) 
{
@cols = split /\s+/;
$co=$cols[1]-1;
$length=$cols[2]-$co;
$fragment =  substr $string, $co, $length;
print ">",$cols[0],"#",$cols[1],":",$cols[2],"\n",$fragment,"\n";
}

but here my problem is when should I input my second file and how should I match the character in col1 (of file1) with character in file2 (followed by > symbol) and then how to get substring?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:24:48+00:00Added an answer on May 30, 2026 at 4:24 pm

    I wasnt sure if they were all one continuous line or separate lines.
    I set it up as continuous for now.

    Basically, read the 2nd file as master.
    Then you can process as many index files as you need.

    You can use hash of arrays to help with the indexing.
    push @{$index{$key}}, [$start,$stop];

    use strict;
    my $master_file = "dna_master.txt";
    if ($#ARGV) {
        print "Usage: $0 [filename(s)]\n";
        exit 1;
    }
    
    my %Data = read_master($master_file);
    
    foreach my $index_file (@ARGV) {
        my %Index = read_index($index_file);
        foreach my $key (sort keys %Index) {
            foreach my $i (@{$Index{$key}}) {
                my ($start,$stop) = @$i;
                print ">$key#$start:$stop\n";
                my $pos = $start - 1;
                my $count = $stop - $start + 1;
                print substr($Data{$key},$pos,$count)."\n";
            }
        }
    }
    
    sub read_file {
        my $file = shift;
        my @lines;
        open(FILE, $file) or die "Error: cannot open $file\n$!";
        while(<FILE>){
            chomp; #remove newline
            s/(^\s+|\s+$)//g; # strip lead/trail whitespace
            next if /^$/;  # skip blanks
            push @lines, $_;
        }
        close FILE;
        return @lines;
    }
    
    sub read_index {
        my $file = shift;
        my @lines = read_file($file);
        my %index;
        foreach (@lines) {
            my ($key,$start,$stop) = split /\s+/;
            push @{$index{$key}}, [$start,$stop]; 
        }
        return %index;
    }
    
    sub read_master {
        my $file = shift;
        my %master;
        my $key;
        my @lines = read_file($file);
        foreach (@lines) {
            if ( m{^>(\w+)} ) { $key = $1 }
            else { $master{$key} .= $_ }
        }
        return %master;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on some legacy C++ code that uses variable length structures
i have attached TinyScrollBar(from [here] ) plugin with my project. It was working some
Working with some basic java apps on CentOS 5 linux and I have my
Working on some import process where i need to first upload the file at
I have some working JavaScript that I want to convert to pure jQuery. Please
Been working on some code streamlining and have realised that it would be really
I'm having some difficulty working with buttons and images. I have 2 buttons, one
Working on some dynamic pages and specifically we have profile pages for users. However
I have some working code that I have been using on a test O365
Working on some tweaks for a build script, I noticed that the output from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.