@@ -71,61 +71,70 @@ public void init() {
7171
7272 @ Override
7373 protected boolean canUseExtension (VariantFileMetadata fileMetadata ) {
74- // canCalculateVaf is calculated in the init() method after checking the VCF header fields
75- return SUPPORTED_SVTYPE_CALLERS .containsKey (caller ) || SUPPORTED_SVLEN_CALLERS .containsKey (caller );
74+ // First, check if the caller is registered because it does not use standard names
75+ if (SUPPORTED_SVTYPE_CALLERS .containsKey (caller ) || SUPPORTED_SVLEN_CALLERS .containsKey (caller )) {
76+ return true ;
77+ }
78+
79+ // Second, if the VCF header contains standard SV info fields, in this case we always add EXT fields
80+ for (VariantFileHeaderComplexLine complexLine : fileMetadata .getHeader ().getComplexLines ()) {
81+ if (complexLine .getKey ().equals ("INFO" )) {
82+ if (complexLine .getId ().equals ("SVTYPE" ) || complexLine .getId ().equals ("SVLEN" )) {
83+ return true ;
84+ }
85+ }
86+ }
87+
88+ return false ;
7689 }
7790
7891 @ Override
7992 protected void normalizeHeader (VariantFileMetadata fileMetadata ) {
80- if (SUPPORTED_SVTYPE_CALLERS .containsKey (caller )) {
81- // Add EXT_SVTYPE
82- VariantFileHeaderComplexLine newSampleMetadataLine = new VariantFileHeaderComplexLine ( "INFO" ,
83- EXT_SVTYPE ,
84- "Variant SVTYPE obtained from " + SUPPORTED_SVTYPE_CALLERS .get (caller )
85- + ", several variant callers supported. NOTE: this is a OpenCB extension field." ,
86- "1" ,
87- "String" ,
88- Collections .emptyMap ());
89- fileMetadata .getHeader ().getComplexLines ().add (newSampleMetadataLine );
90- }
91-
92- if (SUPPORTED_SVLEN_CALLERS .containsKey (caller )) {
93- // Add EXT_SVLEN
94- VariantFileHeaderComplexLine newSampleMetadataLine = new VariantFileHeaderComplexLine ( "INFO" ,
95- EXT_SVLEN ,
96- "Variant SVLEN obtained from " + SUPPORTED_SVLEN_CALLERS .get (caller )
97- + ", several variant callers supported. NOTE: this is a OpenCB extension field." ,
98- "1" ,
99- "Integer" ,
100- Collections .emptyMap ());
101- fileMetadata .getHeader ().getComplexLines ().add (newSampleMetadataLine );
102- }
93+ // Add EXT_SVTYPE
94+ VariantFileHeaderComplexLine extSvtypeFileMetadataLine = new VariantFileHeaderComplexLine ( "INFO" ,
95+ EXT_SVTYPE ,
96+ "Variant SVTYPE obtained from " + SUPPORTED_SVTYPE_CALLERS .getOrDefault (caller , "SVTYPE" )
97+ + ", several variant callers supported. NOTE: this is a OpenCB extension field." ,
98+ "1" ,
99+ "String" ,
100+ Collections .emptyMap ());
101+ fileMetadata .getHeader ().getComplexLines ().add (extSvtypeFileMetadataLine );
102+
103+ // Add EXT_SVLEN
104+ VariantFileHeaderComplexLine extSvlenFileMetadataLine = new VariantFileHeaderComplexLine ( "INFO" ,
105+ EXT_SVLEN ,
106+ "Variant SVLEN obtained from " + SUPPORTED_SVLEN_CALLERS .getOrDefault (caller , "SVLEN" )
107+ + ", several variant callers supported. NOTE: this is a OpenCB extension field." ,
108+ "1" ,
109+ "Integer" ,
110+ Collections .emptyMap ());
111+ fileMetadata .getHeader ().getComplexLines ().add (extSvlenFileMetadataLine );
103112 }
104113
105114 @ Override
106115 protected void normalizeFile (Variant variant , StudyEntry study , FileEntry file ) {
107- // Check if we can get SVTYPE from this caller
108- if (SUPPORTED_SVTYPE_CALLERS .containsKey (caller )) {
109- VariantType svtype = parseSvtype (file );
110- // Check returned svtype, some variants could miss the svtype
111- if (svtype != null ) {
112- study .addFileData (file .getFileId (), EXT_SVTYPE , svtype .name ());
113- }
116+ // GET SVTYPE and check value, some variants could miss the SVTYPE
117+ VariantType svtype = parseSvtype (file );
118+ if (svtype != null ) {
119+ study .addFileData (file .getFileId (), EXT_SVTYPE , svtype .name ());
114120 }
115121
116- // Check if we can get SVLEN from this caller
117- if (SUPPORTED_SVLEN_CALLERS .containsKey (caller )) {
118- String svlen = file .getData ().get (SUPPORTED_SVLEN_CALLERS .get (caller ));
119- // Check returned svlen, some variants could miss the svlen
120- if (StringUtils .isNotEmpty (svlen )) {
122+ // Get SVLEN and check value, some variants could miss the SVLEN
123+ String svlen = file .getData ().get (SUPPORTED_SVLEN_CALLERS .getOrDefault (caller , "SVLEN" ));
124+ if (StringUtils .isNotEmpty (svlen )) {
125+ try {
126+ // Make sure SVLEN is a positive number
127+ int i = Math .abs (Integer .parseInt (svlen ));
128+ study .addFileData (file .getFileId (), EXT_SVLEN , String .valueOf (i ));
129+ } catch (NumberFormatException e ) {
121130 study .addFileData (file .getFileId (), EXT_SVLEN , svlen );
122131 }
123132 }
124133 }
125134
126135 private VariantType parseSvtype (FileEntry file ) {
127136 VariantType SVTYPE = null ;
128- String fileSvType = file .getData ().get (SUPPORTED_SVTYPE_CALLERS .get (caller ));
137+ String fileSvType = file .getData ().get (SUPPORTED_SVTYPE_CALLERS .getOrDefault (caller , "SVTYPE" ));
129138
130139 if (StringUtils .isNotEmpty (fileSvType )) {
131140 switch (fileSvType .toUpperCase ()) {
0 commit comments