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 9232969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:26:24+00:00 2026-06-18T06:26:24+00:00

I am trying to modify a file which is set up like this: chr

  • 0

I am trying to modify a file which is set up like this:

chr start   ref alt 
chr1    18884   C   CAAAA
chr1    135419  TATACA  T
chr1    332045  T   TTG
chr1    453838  T   TAC
chr1    567652  T   TG
chr1    602541  TTTA    T
chr1    614937  C   CTCTCTG
chr1    654889  C   CA
chr1    736800  AC  A

I want to modify it such that:
if column “ref” is a string >1 (i.e line 2) then I generate 2 new columns where:

first new column = start coordinate-1
second new column = start coordinate+(length of string in ref)+1

therefore, for line 2 output would look like:

chr1 135419 TATACA T 135418 135426

or:
if length of string in “ref” = 1 and column “alt”=string of length>1 (i.e. line 1) then

first new column = start coordinate
second new column = start coordinate+2

so, output for line 1 would be:

chr1 18884 C CAAAA 18884 18886

I have tried to this in awk but without success
My perl is non-existent but would this be the best way? Or maybe in R?

  • 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-06-18T06:26:25+00:00Added an answer on June 18, 2026 at 6:26 am

    Perl solution. Note that your specification does not mention what to do if both strings are length 1.

    #!/usr/bin/perl
    use warnings;
    use strict;
    use feature qw(say);
    
    #use Data::Dumper;
    <DATA>; # Skip the header;
    while (<DATA>) {
        my ($chr, $start, $ref, $alt) = split;
        my @cols;
        if (1 < length $ref) {
              @cols = ( $start - 1, $start + 1 + length $ref);
        } elsif (1 < length $alt) {
            @cols = ($start, $start + 2);
        } else {
            warn "Don't know what to do at $.\n";
        }
        say join "\t", $chr, $start, $ref, $alt, @cols;
    }
    
    
    __DATA__
    chr start   ref alt
    chr1    18884   C   CAAAA
    chr1    135419  TATACA  T
    chr1    332045  T   TTG
    chr1    453838  T   TAC
    chr1    567652  T   TG
    chr1    602541  TTTA    T
    chr1    614937  C   CTCTCTG
    chr1    654889  C   CA
    chr1    736800  AC  A
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to update (add/modify files) an existing JAR file, and this code (using
I'm trying to modify a file in a zip-file using java.util.net As direct modification
i am trying to modify one js file validation rule but unable to do
I'm trying to modify the access timestamp and modify timestamp of a remote file
I am trying to modify the android lvl library and as part of this
I'm trying to store a file which encode an id of a class, read
I was trying to parse an xml file. My problem is same as this:
We have been trying to modify the Customer.php file ( import/export ) to get
I am trying to use C# to read excel file which has intermixed datatype.
I have a javascript file from a wordpress plugin that I'm trying to modify.

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.