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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:43:20+00:00 2026-06-11T15:43:20+00:00

I am fairly new to programming and trying to resolve this problem. I have

  • 0

I am fairly new to programming and trying to resolve this problem. I have the file like this.

CHROM    POS     REF     ALT    10_sample.bam   11_sample.bam   12_sample.bam   13_sample.bam   14_sample.bam   15_sample.bam   16_sample.bam 
tg93    77  T   C   T   T   T   T           T
tg93    79  C   -   C       C   C   -   -   
tg93    79  C   G   C   C   C   C   G       C
tg93    80  G   A   G   G   G   G   A   A   G
tg93    81  A   C   A   A   A   A   C   C   C
tg93    86  C   A   C   C   A   A   A   A   C
tg93    105 A   G   A   A   A   A   A   G   A
tg93    108 A   G   A   A   A   A   G   A   A
tg93    114 T   C   T   T   T   T   T   C   T
tg93    131 A   C   A   A   A   A   A   A   A
tg93    136 G   C   C   G   C   C   G   G   G
tg93    150 CTCTC   -       CTCTC       -   CTCTC       CTCTC

In this file, in the heading

CHROM – name
POS – position
REF – reference
ALT – alternate
10 – 16_sample.bam – samplesd
I

Now i wanted to see how many times the letter in REF and ALT column occured. If either of them is repeated less than two times, i need to delete that row.

For example
In the first row, i have ‘T’ in REF and ‘C’ in ALT . I see in 7 samples, there are 5 T’s and 2 blanks and no C. So i need to delete this row.

In Second row, REF is ‘C’ and Alt is ‘-‘. Now in seven samples we have 3 C’s, 2 ‘-‘s and 2 blanks. So we keep this row as C and – have repeated more than 2 times.
Always we ignore the blanks while counting

The final file after filtering is

#CHROM   POS     REF     ALT    10_sample.bam   11_sample.bam   12_sample.bam   13_sample.bam   14_sample.bam   15_sample.bam   16_sample.bam 
tg93    79  C   -   C       C   C   -   -   
tg93    80  G   A   G   G   G   G   A   A   G
tg93    81  A   C   A   A   A   A   C   C   C
tg93    86  C   A   C   C   A   A   A   A   C
tg93    136 G   C   C   G   C   C   G   G   G

I am able to read the columns in to arrays and display them in the code but i am not sure how to start the loops to read the base and count their occurrences and remain the column. Can anyone tell me how i should be proceeding with this? Or it will be helpful if you have any example code i can modify up on.

  • 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-11T15:43:21+00:00Added an answer on June 11, 2026 at 3:43 pm
    #!/usr/bin/env perl
    use strict;
    use warnings;
    
    print scalar(<>);                   # Read and output the header.
    
    while (<>) {                        # Read a line.
       chomp;                           # Remove the newline from the line.
       my ($chrom, $pos, $ref, $alt, @samples) =
          split /\t/;                   # Parse the remainder of the line.
    
       my %counts;                      # Count the occurrences of sample values.
       ++$counts{$_} for @samples;      # e.g. Might end up with $counts{"G"} = 3.
    
       print "$_\n"                     # Print line if we want to keep it.
          if ($counts{$ref} || 0) >= 2  # ("|| 0" avoids a spurious warning.)
          && ($counts{$alt} || 0) >= 2;
    }
    

    Output:

    CHROM    POS     REF     ALT    10_sample.bam   11_sample.bam   12_sample.bam   13_sample.bam   14_sample.bam   15_sample.bam   16_sample.bam 
    tg93    79  C   -   C       C   C   -   -   
    tg93    80  G   A   G   G   G   G   A   A   G
    tg93    81  A   C   A   A   A   A   C   C   C
    tg93    86  C   A   C   C   A   A   A   A   C
    tg93    136 G   C   C   G   C   C   G   G   G
    

    You included 108 in your desired output, but it only has one instance of ALT in the seven samples.

    Usage:

    perl script.pl file.in >file.out
    

    Or in-place:

    perl -i script.pl file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am fairly new to DirectX 10 programming, and I have been trying to
I'm fairly new to C programming but trying my best to understand it. I
I'm fairly new to iPhone programming and am trying to implement a double-component PickerView.
I am fairly new to programming and to python and wxpython. I have looked
I'm fairly new to programming and new to java, but I'd like to jump
I am fairly new to Objective C and iOS programming but am constantly trying
I'm fairly new to programming and from learning I have seen different ways of
I'm fairly new to Python and programming in general. I have done a few
I am fairly new to database programming and am trying to get a basic
I'm fairly new to programming and have been focussing a great deal on Java

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.