<commit_before>/*
 *  Groovy NGS Utils - Some simple utilites for processing Next Generation Sequencing data.
 *
 *  Copyright (C) 2013 <NAME>, ssadedin<at>gmail.com
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

import java.util.List;


/**
 * An individual in a family pedigree
 * 
 * @author <EMAIL>
 */
class Subject {
    
    String id
    
    Set<String> phenoTypes
}

/**
 * Models a relationship between two individuals in a pedigree
 * 
 * @author <EMAIL>
 */
class Relationship {
    
    boolean transmits
    
    double transmissionFactor
    
    String type
    
    String from
    
    String to
}

/**
 * Represents a set of relationships between individuals in a family
 * 
 * @author <EMAIL>
 */
class Pedigree {
    
    /**
     * Unique identifier for the family
     */
    String id
    
    /**
     * List of subject ids belonging to the family
     */
    List<String> samples
    
    List<Subject> individuals
    
    List<Integer> phenoTypes
    
    String toString() {
        "$id $samples"
    }
    
    @Lazy
    List<String> affected = { samples.grep {phenoTypes[samples.indexOf(it)] > 0 } }()
   
}<commit_msg>support for parsing pedigrees from PED files<commit_after>/*
 *  Groovy NGS Utils - Some simple utilites for processing Next Generation Sequencing data.
 *
 *  Copyright (C) 2013 <NAME>, ssadedin<at>gmail.com
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

import java.util.List;


/**
 * An individual in a family pedigree
 * 
 * @author <EMAIL>
 */
class Subject {
    
    String id
    
    Sex sex
    
    Set<String> phenoTypes
}

/**
 * Models a relationship between two individuals in a pedigree
 * 
 * @author <EMAIL>
 */
class Relationship {
    
    boolean transmits
    
    double transmissionFactor
    
    String type
    
    String from
    
    String to
}

/**
 * Represents a set of relationships between individuals in a family
 * 
 * @author <EMAIL>
 */
class Pedigree {
    
    /**
     * Unique identifier for the family
     */
    String id
    
    /**
     * List of subject ids belonging to the family
     */
    List<String> samples = []
    
    List<Subject> individuals = []
    
    List<Integer> phenoTypes = []
    
    String toString() {
        "$id $samples"
    }
    
    static Map<String,Pedigree> parse(String pedFileName) {
        
        Map<String,Pedigree> families = [:]
        
        List<Subject> subjects = new TSV(pedFileName,columnNames:['familyId','id', 'paternalId', 'maternalId', 'sex', 'phenotype']).collect { line ->
//            println "FamilyId = $line.familyId id = $line.id"
            if(!families.containsKey(line.familyId))
                families[line.familyId] = new Pedigree(id:line.familyId)
            Pedigree p = families[line.familyId]
            def sex = line.sex ?: "other"
            Subject s = new Subject(id: line.id, sex: Sex.decode(sex), phenoTypes:[line.phenotype])
            p.individuals.add(s)
            p.samples.add(s.id)
            p.phenoTypes.add(line.phenotype)
        }
        
        return families
    }
    
    @Lazy
    List<String> affected = { samples.grep {phenoTypes[samples.indexOf(it)] > 0 } }()
    
    @Lazy
    List<String> unaffected = { samples.grep {phenoTypes[samples.indexOf(it)] == 0 } }()
}
{'fraction_non_alphanumeric': 0.08917197452229299, 'fraction_numerical': 0.007855626326963907, 'mean_word_length': 2.5104321907600595, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '645328', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1341, 'n_words': 494}