text: user9659: 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'
  
  
  user6628: 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.
  
original_text: 9659: <p>I  am trying to look for miRNA targets using a file called <code>Conservedfamily.txt</code> 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 <a href="https://www.biostars.org/p/9481491/" rel="nofollow noreferrer">posted the question in biostars</a> but go no reply from them for 4 days. Hence I am posting the question in Stack exchange. The python code is attached below.</p>
  <pre class="lang-py prettyprint-override"><code>#!/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()
  </code></pre>
  <pre><code>python miR99target.py 'Conserved_Family_Info.txt' 'miR-210targetlist.txt' 'miR-210targetid.txt'
  </code></pre>
   6628: <p>I'd suggest loading in all of the miRNA tags as a <code>set()</code>. Then, you can just check the set membership each time.</p>
  <pre class="lang-py prettyprint-override"><code>#!/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()
  </code></pre>
  <p>One additional comment:
  I'd suggest using the <a href="https://docs.python.org/3/library/csv.html" rel="nofollow noreferrer">python module for csv</a> reading/writing, even for quick and dirty scripts as well as using <a href="https://stackoverflow.com/a/36559849/7092484">context managers</a> for reading/writing files.</p>
  