@ Override public List < Variant > create ( VariantStudyMetadata metadata , String line ) throws IllegalArgumentException , NotAVariantException { String [ ] fields = line . split ( "\t" ) ; if ( fields . length < 8 ) { throw new IllegalArgumentException ( "Not enough fields provided (min 8)" ) ; } // if(fields[4].equals(".")) { // throw new NotAVariantException("Alternative allele is a '.'. This is not an actual variant but a reference position."); // } String chromosome = fields [ 0 ] ; int position = Integer . parseInt ( fields [ 1 ] ) ; String id = fields [ 2 ] . equals ( "." ) ? null : fields [ 2 ] ; List < String > ids = id == null ? Collections . emptyList ( ) : Arrays . asList ( id . split ( ";" ) ) ; String reference = fields [ 3 ] . equals ( "." ) ? "" : fields [ 3 ] ; String alternate = fields [ 4 ] ; // String alternate = fields[4].equals(".") ? "" : fields[4]; String [ ] alternateAlleles = alternate . split ( "," ) ; String mainAlternate = alternateAlleles [ 0 ] ; float quality = fields [ 5 ] . equals ( "." ) ? - 1 : Float . parseFloat ( fields [ 5 ] ) ; String filter = fields [ 6 ] . equals ( "." ) ? "" : fields [ 6 ] ; String info = fields [ 7 ] . equals ( "." ) ? "" : fields [ 7 ] ; String format = ( fields . length <= 8 || fields [ 8 ] . equals ( "." ) ) ? "" : fields [ 8 ] ; int end = position + reference . length ( ) - 1 ; Variant variant = new Variant ( chromosome , position , end , reference , mainAlternate ) ; List < AlternateCoordinate > secondaryAlternatesMap = Arrays . stream ( alternateAlleles , 1 , alternateAlleles . length ) . map ( a -> new AlternateCoordinate ( chromosome , null , null , null , a , null ) ) . collect ( Collectors . toList ( ) ) ; StudyEntry entry = new StudyEntry ( metadata . getId ( ) , secondaryAlternatesMap , Arrays . asList ( format . split ( ":" ) ) ) ; VariantFileMetadata fileMetadata = new VariantFileMetadata ( metadata . getFiles ( ) . get ( 0 ) ) ; entry . setFileId ( fileMetadata . getId ( ) ) ; variant . addStudyEntry ( entry ) ; try { parseSplitSampleData ( entry , fileMetadata , fields , reference , alternateAlleles ) ; // Fill the rest of fields (after samples because INFO depends on them) setOtherFields ( variant , entry , fileMetadata , ids , quality , filter , info , format , alternateAlleles , line ) ; } catch ( NonStandardCompliantSampleField ex ) { Logger . getLogger ( VariantFactory . class . getName ( ) ) . log ( Level . SEVERE , String . format ( "Variant %s:%d:%s>%s will not be saved\n%s" , chromosome , position , reference , alternate , ex . getMessage ( ) ) ) ; } return Collections . singletonList ( variant ) ; }
Creates a list of Variant objects using the fields in a record of a VCF file . A new Variant object is created per allele so several of them can be created from a single line .