<commit_before>package org.phenoscape.owl.mod.xenbase

import java.io.File
import scala.collection.JavaConversions._
import scala.collection.Map
import scala.collection.TraversableOnce.flattenTraversableOnce
import scala.collection.mutable
import scala.io.Source
import org.apache.commons.lang3.StringUtils
import org.phenoscape.scowl.OWL._
import org.phenoscape.owl.OWLTask
import org.phenoscape.owl.Vocab
import org.phenoscape.owl.Vocab._
import org.phenoscape.owl.util.OBOUtil
import org.semanticweb.owlapi.model.IRI
import org.semanticweb.owlapi.model.OWLAxiom
import org.semanticweb.owlapi.model.OWLNamedIndividual
import org.semanticweb.owlapi.model.OWLOntology
import org.semanticweb.owlapi.apibinding.OWLManager
import org.phenoscape.owl.util.OntologyUtil

object XenbaseExpressionToOWL extends OWLTask {

  val laevis = Individual(Vocab.XENOPUS_LAEVIS)
  val tropicalis = Individual(Vocab.XENOPUS_TROPICALIS)
  val manager = OWLManager.createOWLOntologyManager()
  val rdfsLabel = factory.getRDFSLabel()

  def convert(genepageMappingsFile: Source, laevisExpressionFile: Source, tropicalisExpressionFile: Source): Set[OWLAxiom] = {
    val mappings = indexGenepageMappings(genepageMappingsFile)
    convert(laevisExpressionFile, mappings, laevis) ++ convert(tropicalisExpressionFile, mappings, tropicalis)
  }

  def indexGenepageMappings(mappings: Source): Map[String, String] = {
    val index = mutable.Map[String, String]()
    for (mapping <- mappings.getLines()) {
      val items = mapping.split("\t")
      val genepageID = StringUtils.stripToNull(items(0))
      for (geneID <- items(1).split(",")) {
        index(StringUtils.stripToNull(geneID)) = genepageID
      }
    }
    return index
  }

  def convert(expressionData: Source, genepageMappings: Map[String, String], species: OWLNamedIndividual): Set[OWLAxiom] = {
    expressionData.getLines.flatMap(translate(_, genepageMappings, species)).toSet[OWLAxiom] +
      (laevis Annotation (rdfsLabel, factory.getOWLLiteral("Xenopus laevis"))) +
      (tropicalis Annotation (rdfsLabel, factory.getOWLLiteral("Xenopus tropicalis")))<commit_msg>Fixed index out of bounds in Xenopus gene expression conversion.<commit_after>package org.phenoscape.owl.mod.xenbase

import java.io.File
import scala.collection.JavaConversions._
import scala.collection.Map
import scala.collection.TraversableOnce.flattenTraversableOnce
import scala.collection.mutable
import scala.io.Source
import org.apache.commons.lang3.StringUtils
import org.phenoscape.scowl.OWL._
import org.phenoscape.owl.OWLTask
import org.phenoscape.owl.Vocab
import org.phenoscape.owl.Vocab._
import org.phenoscape.owl.util.OBOUtil
import org.semanticweb.owlapi.model.IRI
import org.semanticweb.owlapi.model.OWLAxiom
import org.semanticweb.owlapi.model.OWLNamedIndividual
import org.semanticweb.owlapi.model.OWLOntology
import org.semanticweb.owlapi.apibinding.OWLManager
import org.phenoscape.owl.util.OntologyUtil

object XenbaseExpressionToOWL extends OWLTask {

  val laevis = Individual(Vocab.XENOPUS_LAEVIS)
  val tropicalis = Individual(Vocab.XENOPUS_TROPICALIS)
  val manager = OWLManager.createOWLOntologyManager()
  val rdfsLabel = factory.getRDFSLabel()

  def convert(genepageMappingsFile: Source, laevisExpressionFile: Source, tropicalisExpressionFile: Source): Set[OWLAxiom] = {
    val mappings = indexGenepageMappings(genepageMappingsFile)
    convert(laevisExpressionFile, mappings, laevis) ++ convert(tropicalisExpressionFile, mappings, tropicalis)
  }

  def indexGenepageMappings(mappings: Source): Map[String, String] = {
    val index = mutable.Map[String, String]()
    for (mapping <- mappings.getLines()) {
      val items = mapping.split("\t", -1)
      val genepageID = StringUtils.stripToNull(items(0))
      for {
        geneIDs <- Option(StringUtils.stripToNull(items(1)))
        geneID <- geneIDs.split(",")
      } {
        index(StringUtils.stripToNull(geneID)) = genepageID
      }
    }
    return index
  }

  def convert(expressionData: Source, genepageMappings: Map[String, String], species: OWLNamedIndividual): Set[OWLAxiom] = {
    expressionData.getLines.flatMap(translate(_, genepageMappings, species)).toSet[OWLAxiom] +
      (laevis Annotation (rdfsLabel, factory.getOWLLiteral("Xenopus laevis"))) +
      (tropicalis Annotation (rdfsLabel, factory.getOWLLiteral("Xenopus tropicalis")))
{'fraction_non_alphanumeric': 0.1018582243633861, 'fraction_numerical': 0.001605872906629961, 'mean_word_length': 5.355685131195335, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5760437', 'n_tokens_mistral': 1528, 'n_tokens_neox': 1439, 'n_words': 247}