Batch run in R
0
0
Entering edit mode
4.0 years ago

I want to run one tool called ClassyfireR from which I will get compounds classification details as result. In their site, the following code is given:

> library(classyfireR)
> inchi_keys <- c('BRMWTNUJHUMWMS-LURJTMIESA-N', 'MDHYEMXUFSJLGV-UHFFFAOYSA-N')
> classification_result <- get_classification(inchi_keys[1])
its result is given in object form such as:
> classification_result

── ClassyFire Object ────────────────────────────────────────────────────────────────────────── classyfireR v0.3.0
Object Size: 18.2 Kb 

Info: 
● InChIKey=BRMWTNUJHUMWMS-LURJTMIESA-N

● [H][C@](N)(CC1=CN(C)C=N1)C(O)=O

● Classification Version: 2.1

kingdom : Organic compounds
└─superclass : Organic acids and derivatives
  └─class : Carboxylic acids and derivatives
    └─subclass : Amino acids, peptides, and analogues
      └─level 5 : Amino acids and derivatives
        └─level 6 : Alpha amino acids and derivatives
          └─level 7 : Histidine and derivatives

I want to run the above three line code for 11 crore inchi keys and store the result in one file or different file. Please suggest me how to modify the code according to inchi keys(nearly in crores)? Thanks in advance

R • 1.3k views
ADD COMMENT
1
Entering edit mode
ADD REPLY
0
Entering edit mode

Sorry but i didnt find anything related to my query. Can you please suggest me any idea how to do this?

ADD REPLY
0
Entering edit mode

The section vectorization has exactly what you need. Please read it more carefully.

ADD REPLY
0
Entering edit mode

I have gone through that. it worked but not completely. can you please help me?

ADD REPLY
0
Entering edit mode

it worked but not completely

Please explain - what part of it failed?

ADD REPLY
0
Entering edit mode
library(readr)
test <- read_csv("test.csv")
file <- c(test)
for (i in file) {
    classification_result <- get_classification(i[1])}

I wrote this code. In this, I took all the inputs in loop but at the last, it is not giving output in bulk. That i[1] I have to change it to 2,3,4,etc every time. Can you please tell me how to apply loop in last line to get output of all inputs?

ADD REPLY
0
Entering edit mode

file <- c(test) is a meaningless statement. Plus, don't override keywords like file. You're still using a loop, not a vectorized method so you've not studied the segment on vectorization. Please do that and let us know if you have difficulties in that.

ADD REPLY
0
Entering edit mode

but sir i understood this way only, it would be helpful if you tell me the exact code how to write it

ADD REPLY
0
Entering edit mode

Sorry but we are not a code writing service. You're welcome to use loops or vectorization - it's your code but from the above snippet, I can't understand what you're doing and your loop doesn't seem to be looping over what it needs to loop over.

Try lapply(inchi_keys, get_classification) and sapply(inchi_keys, get_classification) where inchi_keys is the 2 member vector from your top level post. Once you see how that works, work on building the inchi_keys array to contain all the keys you need and using the appropriate function to get your results.

ADD REPLY
0
Entering edit mode

yeah thats what I was asking for. I also know that this is not code writing service platform but we beginners expect some kind of knowledge or idea from you. Thank you so much. I will try with this method

ADD REPLY
0
Entering edit mode

Thank you so much, it works finally. Only one line code I added and its done

ADD REPLY

Login before adding your answer.

Traffic: 2507 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6