This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Get The Total Counts Number From A Collapsed File

Hi,

After adapter trimming, I collapsed my total reads to the following fasta format:

>1-5832000 
AGGGCCCTTT

>2-124000
GGCCCTTTT

But now I want to get to total number of counts, not just the number of the unique reads. For example, for the above reads, I want to get the total number of (5832000+124000), not 2.

Could anybody tell me how to do it? Thanks.

Ran

read counts

1 answer

Assuming tab in between as above:

cut -f 1 inputfile.txt | awk -F"-"  { SUM += $2} END { print SUM }'

EDIT: If it is a fasta file

 >1-5832000 
 AGGGCCCTTT
 >2-124000 
 GGCCCTTTT

Try this:

awk -F"-" '/>/{ SUM += $2} END { print SUM }' input.fasta

Hi Rm, i copied the fasta file here but it didn't show correctly. Actually it's a fasta file. So >1-5832000 should be on a single line. where 1 is the seq name and 5832000 is the frequency of this sequence. Could you show me how to calculate the total number in this format? Thanks a lot!

I have edited my answer

Thank you! I don't know what it mean, but it works!

hehe, like magic ;-)

Log in to answer this question.