<commit_before>package org.opencb.cellbase.build.transform

import org.opencb.biodata.models.variant.clinical.Cosmic
import org.opencb.cellbase.build.serializers.CellBaseSerializer
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll

import java.nio.file.Paths

/**
 * Created by lcruz on 23/10/14.
 */
class CosmicParserTest extends Specification {

    @Shared
    def cosmicParser
    @Shared
    List<Cosmic> serializedVariants

    def setupSpec() {
        // custom test serializer that adds the serialized variants to a list
        def serializer = Mock(CellBaseSerializer)
        serializedVariants = new ArrayList<Cosmic>()
        serializer.serialize(_) >> { Cosmic arg -> serializedVariants.add(arg) }
        def cosmicFile = Paths.get(VariantEffectParserTest.class.getResource("/cosmicTest.csv").toURI())

        cosmicParser = new CosmicParser(serializer, cosmicFile)
    }

    def "Parse"() {
        when:
        cosmicParser.parse()
        then: "serialize 4 variants"
        serializedVariants.size() == 7
    }

    @Unroll
    def "parsed variant #chr:#start-#end #ref #alt cosmic values"() {
        expect:
        serializedVariants[variantNumber].chromosome.equals(chr)
        serializedVariants[variantNumber].start.equals(start)
        serializedVariants[variantNumber].end.equals(end)
        serializedVariants[variantNumber].reference.equals(ref)
        serializedVariants[variantNumber].alternate.equals(alt)

        where:
        variantNumber || chr  | start     | end       | ref      | alt
        0             || "12" | 25398285  | 25398285  | "G"      | "T"
        1             || "1"  | 215793922 | 215793922 | "A"      | "-"
        2             || "4"  | 152069187 | 152069188 | "-"      | "A"
        3             || "17" | 7578478   | 7578478   | "C"      | "T"
        4             || "5"  | 35874605  | 35874607  | "CTC"    | "AAAAAG"
        5             || "19" | 13054627  | 13054628  | "-"      | "TTGTC"
        6             || "9"  | 5070038   | 5070043   | "GAAGAT" | "-"
    }
}<commit_msg>Improved cosmic test to control some fields and check if input database version has change its fields<commit_after>package org.opencb.cellbase.build.transform

import org.opencb.biodata.models.variant.clinical.Cosmic
import org.opencb.cellbase.build.serializers.CellBaseSerializer
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll

import java.nio.file.Paths

/**
 * Created by lcruz on 23/10/14.
 */
class CosmicParserTest extends Specification {

    @Shared
    def cosmicParser
    @Shared
    List<Cosmic> serializedVariants

    def setupSpec() {
        // custom test serializer that adds the serialized variants to a list
        def serializer = Mock(CellBaseSerializer)
        serializedVariants = new ArrayList<Cosmic>()
        serializer.serialize(_) >> { Cosmic arg -> serializedVariants.add(arg) }
        def cosmicFile = Paths.get(VariantEffectParserTest.class.getResource("/cosmicTest.csv").toURI())

        cosmicParser = new CosmicParser(serializer, cosmicFile)
    }

    def "Parse"() {
        when:
        cosmicParser.parse()
        then: "serialize 4 variants"
        serializedVariants.size() == 7
    }

    @Unroll
    def "parsed variant #chr:#start-#end #ref #alt cosmic values"() {
        expect:
        serializedVariants[variantNumber].chromosome.equals(chr)
        serializedVariants[variantNumber].start.equals(start)
        serializedVariants[variantNumber].end.equals(end)
        serializedVariants[variantNumber].reference.equals(ref)
        serializedVariants[variantNumber].alternate.equals(alt)

        where:
        variantNumber || chr  | start     | end       | ref      | alt
        0             || "12" | 25398285  | 25398285  | "G"      | "T"
        1             || "1"  | 215793922 | 215793922 | "A"      | "-"
        2             || "4"  | 152069187 | 152069188 | "-"      | "A"
        3             || "17" | 7578478   | 7578478   | "C"      | "T"
        4             || "5"  | 35874605  | 35874607  | "CTC"    | "AAAAAG"
        5             || "19" | 13054627  | 13054628  | "-"      | "TTGTC"
        6             || "9"  | 5070038   | 5070043   | "GAAGAT" | "-"
    }

    @Unroll
    def "parsed fields variant #chr:#start-#end #ref #alt #fathmm #pubmed #idStudy #age cosmic values"() {
        given:
        cosmicParser.parse()

        expect:
        serializedVariants[variantNumber].chromosome.equals(chr)
        serializedVariants[variantNumber].start.equals(start)
        serializedVariants[variantNumber].end.equals(end)
        serializedVariants[variantNumber].reference.equals(ref)
        serializedVariants[variantNumber].alternate.equals(alt)
        serializedVariants[variantNumber].fathmmPrediction.equals(fathmm)
        serializedVariants[variantNumber].pubmedPMID.equals(pubmed)
        serializedVariants[variantNumber].idStudy.equals(idStudy)
        serializedVariants[variantNumber].age == age

        where:
        variantNumber || chr  | start     | end       | ref      | alt      | fathmm   | pubmed     | idStudy | age
        0             || "12" | 25398285  | 25398285  | "G"      | "T"      | "CANCER" | "23205087" | null    | null
        1             || "1"  | 215793922 | 215793922 | "A"      | "-"      | ""       | "24293293" | 529     | 53.0
        2             || "4"  | 152069187 | 152069188 | "-"      | "A"      | ""       | "22980975" | 431     | 80.0
        3             || "17" | 7578478   | 7578478   | "C"      | "T"      | "CANCER" | "10780666" | null    | 24.0
        4             || "5"  | 35874605  | 35874607  | "CTC"    | "AAAAAG" | ""       | "21536738" | null    | null
        5             || "19" | 13054627  | 13054628  | "-"      | "TTGTC"  | ""       | "24895336" | null    | null
        6             || "9"  | 5070038   | 5070043   | "GAAGAT" | "-"      | ""       | "17984312" | null    | 80.0
    }
}
{'fraction_non_alphanumeric': 0.12111593718676913, 'fraction_numerical': 0.07968593384563982, 'mean_word_length': 2.0734086242299794, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '1224279', 'n_tokens_mistral': 2215, 'n_tokens_neox': 1867, 'n_words': 373}