Example #1
0
def writeExtensions(genome, extensions):
    """
  genome: The genome as a string.
  extensions: A dictionary mapping genes(Iteration objects) to alternative locations where that gene could start.
  
  This function will write the translation of each possible extension to the file, "extensions.fas".
  """
    output = open("extensions.fas", "w")
    q = 0
    for gene, extensionList in extensions.items():
        for extension in extensionList:
            q += 1
            if gene.location[0] < gene.location[1]:
                ext = extension + 1
                proteins = utils.translate(genome[extension:gene.location[1]])
            else:
                ext = extension
                proteins = utils.translate(
                    utils.reverseComplement(genome[gene.location[1] -
                                                   1:extension]))
            output.write(">" + gene.query + "~" + str(q) + ":" +
                         "-".join(map(str, [ext, gene.location[1]])) + "\n")
            for i in xrange(0, len(proteins), 50):
                output.write(proteins[i:min(i + 50, len(proteins))] + "\n")

    output.close()
Example #2
0
def writePotentialGenes(genome, locations):
  """
  genome:    The genome as a string.
  locations: A list of 2-tuples representing the locations of genes in string coordinates(first nucleotide is at zero and the ending index is exclusive).
  
  Writes all the genes in genome listed locations to "intergenic.fas".  The written
  headers will contain fasta coordinates(first nucleotide is at one and the ending index is inclusive).
  """
  output = open("intergenics.fas", "w")
  q = 0
  for location in locations:
    q += 1
    if location[0] < location[1]:
      output.write(">intergenic~" + str(q) + ":" + str(location[0]+1) + "-" + str(location[1]) + "\n")
      proteins = utils.translate(genome[location[0]:location[1]])
    else:
      output.write(">intergenic~" + str(q) + ":" + str(location[0]) + "-" + str(location[1]+1) + "\n")
      proteins = utils.translate(utils.reverseComplement(genome[location[1]:location[0]]))
    for i in xrange(0, len(proteins), 50):
      output.write(proteins[i:min(i+50, len(proteins))] + "\n")
  output.close()
Example #3
0
def writeExtensions(genome, extensions):
  """
  genome: The genome as a string.
  extensions: A dictionary mapping genes(Iteration objects) to alternative locations where that gene could start.
  
  This function will write the translation of each possible extension to the file, "extensions.fas".
  """
  output = open("extensions.fas", "w")
  q = 0
  for gene, extensionList in extensions.items():
    for extension in extensionList:
      q += 1
      if gene.location[0] < gene.location[1]:
        ext = extension+1
        proteins = utils.translate(genome[extension:gene.location[1]])
      else:
        ext = extension
        proteins = utils.translate(utils.reverseComplement(genome[gene.location[1]-1:extension]))
      output.write(">" + gene.query + "~" + str(q) + ":" +
                   "-".join(map(str, [ext, gene.location[1]])) + "\n")
      for i in xrange(0, len(proteins), 50):
        output.write(proteins[i:min(i+50, len(proteins))] + "\n")
      
  output.close()
Example #4
0
def writePotentialGenes(genome, locations):
    """
  genome:    The genome as a string.
  locations: A list of 2-tuples representing the locations of genes in string coordinates(first nucleotide is at zero and the ending index is exclusive).
  
  Writes all the genes in genome listed locations to "intergenic.fas".  The written
  headers will contain fasta coordinates(first nucleotide is at one and the ending index is inclusive).
  """
    output = open("intergenics.fas", "w")
    q = 0
    for location in locations:
        q += 1
        if location[0] < location[1]:
            output.write(">intergenic~" + str(q) + ":" + str(location[0] + 1) +
                         "-" + str(location[1]) + "\n")
            proteins = utils.translate(genome[location[0]:location[1]])
        else:
            output.write(">intergenic~" + str(q) + ":" + str(location[0]) +
                         "-" + str(location[1] + 1) + "\n")
            proteins = utils.translate(
                utils.reverseComplement(genome[location[1]:location[0]]))
        for i in xrange(0, len(proteins), 50):
            output.write(proteins[i:min(i + 50, len(proteins))] + "\n")
    output.close()