Entering edit mode
2.4 years ago
marcela.uliano
▴
90
Hi all, I apologize in advance. I feel this is simple but I'm stuck for a few hours.
Giving a list of gene names(list_of_genes) and a tab delimited file such as id"\t"gene_names (args.i bellow),
how do I create a folder with gene name and save selected id within each new folder. So I guess its basically creating a folder g and then save the two instances of df5 data frame within this new g.
I'm at:
list_of_genes =['lactato desi', 'NADH lac']
for g in list_of_genes:
m=['id', 'all']
ids_tabbed=pd.read_csv(args.i, sep="\t", names=m)
df5 = ids_tabbed[ids_tabbed['all'].str.contains(g, na=False)]
os.mkdir('{}'.format(str(g.replace(' ', '_'))))
df5.to_csv(f"{g.replace(' ', '_')}.csv", index=False, header=None, sep="\t")
df5[['id']].to_csv(f"ID.{g.replace(' ', '_')}.id.csv", index=False, header=None)
Im able to create the folders: lactato_desi NADH_lac and the files. But I don't know how to save each bunch files to its specific folder =(
Real thanks for your help!
All working. Thanks a lot =)
A small educational note: if an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one answer if they all work. If an answer was not really helpful or did not work, provide detailed feedback so others know not to use that answer.
Noted. Thank Ram