0
$\begingroup$

I am trying to look for miRNA targets using a file called Conservedfamily.txt from the Zebrafish target scan fish website. I have written a python program to extract each of the miRNAs which works fine. However, for a big list of microRNAs, I must provide a name every time in line 22 and get one individual output file. I am thinking is there any option to parallelize the process so that somehow, I can provide a list of all microRNAs and obtain all my targets at the same time. The python code is attached below. I have posted the question in biostars but go no reply from them for 4 days. Hence I am posting the question in Stack exchange. The python code is attached below.

#!/usr/bin/python

#Import relevant modules

import sys

conservedfamily = open(sys.argv[1], 'r')
targetgenelist = open(sys.argv[2], 'w')
targetgeneid = open(sys.argv[3], 'w')

geneid = []

targetgenelist.write('miR family' + '\t' + 'Gene ID' + '\t' + 'Gene Symbol' + '\t' + 'Transcript ID' + '\t' + 'Species ID' + '\t' + 'UTR start' + '\t' + 'UTR end' + '\t' + 'MSA start' + '\t' + 'MSA end' + '\t' + 'Seed match' + '\n')

for line in conservedfamily:
  splitline = line.strip().split('\t')

  if splitline[0] == 'miR-210':
    targetgenelist.write(line)
    if not splitline[1] in geneid:
      geneid.append(splitline[1])
      targetgeneid.write(splitline[1] + '\n')

conservedfamily.close()
targetgenelist.close()
targetgeneid.close()
python miR99target.py 'Conserved_Family_Info.txt' 'miR-210targetlist.txt' 'miR-210targetid.txt'
$\endgroup$
0
0
$\begingroup$

I'd suggest loading in all of the miRNA tags as a set(). Then, you can just check the set membership each time.

#!/usr/bin/python

#Import relevant modules

import sys


conservedfamily = open(sys.argv[1], 'r')
targetgenelist = open(sys.argv[2], 'w')
targetgeneid = open(sys.argv[3], 'w')


# Create a set of all miRNA tags. Each tag should be on its own line.
with open(sys.argv[4], 'r') as miRNAlist:
    miRNA_set = {line.strip() for line in miRNAlist}

geneid = []

targetgenelist.write('miR family' + '\t' + 'Gene ID' + '\t' + 'Gene Symbol' + '\t' + 'Transcript ID' + '\t' + 'Species ID' + '\t' + 'UTR start' + '\t' + 'UTR end' + '\t' + 'MSA start' + '\t' + 'MSA end' + '\t' + 'Seed match' + '\n')

for line in conservedfamily:
  splitline = line.strip().split('\t')

  # Check if current tag is in the desired set
  if splitline[0] in miRNA_set:
    targetgenelist.write(line)
    if not splitline[1] in geneid:
      geneid.append(splitline[1])
      targetgeneid.write(splitline[1] + '\n')

conservedfamily.close()
targetgenelist.close()
targetgeneid.close()

One additional comment: I'd suggest using the python module for csv reading/writing, even for quick and dirty scripts as well as using context managers for reading/writing files.

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.