I have a data frame with 1000 rows and 21 columns which the first column is miRNA gene names and other columns show each nucleotide in each position:

What I want is to make a loop over the first column and if my character pattern gets matched in the column for example "Ami-Mir-489" (don't consider p1 and p2) then for each position (pos_1, pos_2, ..., pos_20) calculate the frequency of each nucleotide separately.

enter image description here

  • Welcome to the site. Please avoid including screenshots of sample input as much as possible; it makes it more difficult for contributors to help you find the problem as they would need to copy-type the sample text. Instead, copy-and-paste the sample text into your question. – AdminBee Jan 21 '20 at 15:58
  • Quite simple with a 2-D awk array. Would help to know: (a) Can there be multiple data frames in a file. (b) Are ATCG the only possibilities. (c) Are all the rows for a particular Ami-Mir-xxx code consecutive. (d) Do you really want the output 500+ chars wide. (e) What are the column separators, for both input and output. – Paul_Pedant Jan 21 '20 at 16:38
  • Does it have to be in R? If so, I'm out. – Paul_Pedant Jan 21 '20 at 18:30
  • @Paul_Pedant it is a defined data frame in r but gene names are not always consecutive. Is there any solution to prevent 500+ chars wide? If you assume an excel file I want those 4 percentages to be inside a single cell of the excel file. – morteza aslanzadeh Jan 21 '20 at 23:19
  • Each position has 4 %ages so is around 24 chars wide, and with 20 pos_x columns, the gene name and the separators, that's 500 in a plain text format. I have no knowledge of R and don't know how to interface to it. Obviously if it behaves like Excel you can hide columns, set formats, multiline cells and scroll sideways to make it manageable, but that's probably too much for me to learn to do this properly. – Paul_Pedant Jan 22 '20 at 0:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.